+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
Scripts Thread, Windows Scripting - checking if zipped up. Now problem connecting to xp. in Coding and Web Development; As Shaun will tell you I am no developer been updating a batch file to windows scripting and got some ...
  1. #1

    russdev's Avatar
    Join Date
    Jun 2005
    Location
    Leicestershire
    Posts
    6,918
    Thank Post
    708
    Thanked 550 Times in 365 Posts
    Blog Entries
    3
    Rep Power
    204

    Windows Scripting - checking if zipped up. Now problem connecting to xp.

    As Shaun will tell you I am no developer been updating a batch file to windows scripting and got some code below.

    I want to replace wait command with something that will check to see if has completed any ideas.


    Code:
    'Zip Up Log Folder.
    
    strFolderToZip = strWorkingLogDir
    strzipFile = strCurPath & "\" & strRMLOGDIR & ".zip" 
    
    
    Set Ag=Wscript.Arguments
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.OpenTextFile(strzipFile, 8, vbtrue)
    BlankZip = "PK" & Chr(5) & Chr(6)
    For x = 0 to 17
    BlankZip = BlankZip & Chr(0)
    Next
    ts.Write BlankZip
            set objFolder = nothing
            set objShell = nothing
    Set fso = nothing
    Set ts = nothing
    
    Set objShell = CreateObject("Shell.Application")
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set DestFldr=objShell.NameSpace(strzipFile)
    Set SrcFldr=objShell.NameSpace(strFolderToZip)
    DestFldr.CopyHere (strFolderToZip) 
     
    
    WScript.Sleep 30000 ' increase this if the folder is large
    Russ
    Last edited by russdev; 7th December 2010 at 03:37 PM.

  2. #2
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    41
    Thought it would wait for copy to complete anyway before it moves onto the next line.. im probably wrong.

  3. Thanks to apeo from:

    russdev (7th December 2010)

  4. #3

    russdev's Avatar
    Join Date
    Jun 2005
    Location
    Leicestershire
    Posts
    6,918
    Thank Post
    708
    Thanked 550 Times in 365 Posts
    Blog Entries
    3
    Rep Power
    204
    Sadly it does not wait.

    Russ

  5. #4

    Join Date
    May 2010
    Location
    England
    Posts
    104
    Thank Post
    20
    Thanked 16 Times in 13 Posts
    Rep Power
    11
    Hi Russ

    I am not completely familiar with Batch programming and only dabble in it a bit, but post 8 on the following link looks quite usefull for your case?

    How to create ZIP Files from Command-Line via VBScript? - Windows Server Help

  6. Thanks to koryo from:

    russdev (7th December 2010)

  7. #5
    browolf's Avatar
    Join Date
    Jun 2005
    Location
    Mars
    Posts
    1,524
    Thank Post
    106
    Thanked 88 Times in 74 Posts
    Blog Entries
    46
    Rep Power
    40
    check the timestamp on the file, if its more than say 5mins old, it'll have finished.

  8. Thanks to browolf from:

    russdev (7th December 2010)

  9. #6

    russdev's Avatar
    Join Date
    Jun 2005
    Location
    Leicestershire
    Posts
    6,918
    Thank Post
    708
    Thanked 550 Times in 365 Posts
    Blog Entries
    3
    Rep Power
    204
    Link from Koryo worked great next issue..

    Next Issue part of script pulls the event viewer logs off..

    Code:
    'Get Application Logs
        Set objWMIService = GetObject("winmgmts:" _
            & "{impersonationLevel=impersonate,(Backup)}!\\" & _
                strComputerName & "\root\cimv2")
        Set colLogFiles = objWMIService.ExecQuery _
            ("Select * from Win32_NTEventLogFile " _
                & "Where LogFileName='Application'")
        For Each objLogfile in colLogFiles
            errBackupLog = objLogFile.BackupEventLog( _
                "c:\" & strComputerName & "-application.evt")
            WScript.Echo ("File saved as c:\" & strComputerName & "-application.evt")
        Next
    Works fine against Vista machines but not XP machines (errors with permission denied error). As can tell getting to limits of my knowledge when it comes to windows scripting.
    Last edited by russdev; 7th December 2010 at 03:39 PM.

  10. #7

    Join Date
    May 2010
    Location
    England
    Posts
    104
    Thank Post
    20
    Thanked 16 Times in 13 Posts
    Rep Power
    11
    Personally i would re-design this script in powershell, its a lot more powerfull, for instance you could do all that event viewer stuff through one line of code.

    I will look into a batch file solution for this, hold this space.

  11. #8

    russdev's Avatar
    Join Date
    Jun 2005
    Location
    Leicestershire
    Posts
    6,918
    Thank Post
    708
    Thanked 550 Times in 365 Posts
    Blog Entries
    3
    Rep Power
    204
    @Koroyo

    Not batch file but windows scripting (it was a batch file). As for powershell that the next stage but need to sit down and learn powershell. Needed to move away from batch file in meantime.

    Russ

  12. #9

    Join Date
    May 2010
    Location
    England
    Posts
    104
    Thank Post
    20
    Thanked 16 Times in 13 Posts
    Rep Power
    11
    Hi Russ, i presume your now on about a .vbs script yes?

    If so, i have found an extremely similar one online that apparently works on XP. Maybe a comparison against this would help you?

    PLEASE NOTE - this script is to clear event logs, as well as back them up.

    Code:
    dtmThisDay = Day(Date)
    dtmThisMonth = Month(Date)
    dtmThisYear = Year(Date)
    strBackupName = dtmThisYear & "_" & dtmThisMonth & "_" & dtmThisDay
    
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate, (Backup, Security)}!\\" _
            & strComputer & "\root\cimv2")
    
    Set colLogFiles = objWMIService.ExecQuery _
        ("Select * from Win32_NTEventLogFile")
    
    For Each objLogfile in colLogFiles
        If objLogFile.FileSize <> 100000 Then
           strBackupLog = objLogFile.BackupEventLog _
               ("D:\Eventlogs\" & strBackupName & objLogFile.LogFileName & ".evt")
           objLogFile.ClearEventLog()
        End If
    Next
    Source : Windows XP Event Log export/copy : event, log, export, xp, windows
    Last edited by koryo; 7th December 2010 at 04:51 PM.

  13. Thanks to koryo from:

    russdev (7th December 2010)

  14. #10

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,703
    Thank Post
    3,235
    Thanked 1,043 Times in 965 Posts
    Rep Power
    363
    Quote Originally Posted by koryo View Post
    Hi Russ, i presume your now on about a .vbs script yes?

    If so, i have found an extremely similar one online that apparently works on XP. Maybe a comparison against this would help you?

    PLEASE NOTE - this script is to clear event logs, as well as back them up.

    Code:
    dtmThisDay = Day(Date)
    dtmThisMonth = Month(Date)
    dtmThisYear = Year(Date)
    strBackupName = dtmThisYear & "_" & dtmThisMonth & "_" & dtmThisDay
    
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate, (Backup, Security)}!\\" _
            & strComputer & "\root\cimv2")
    
    Set colLogFiles = objWMIService.ExecQuery _
        ("Select * from Win32_NTEventLogFile")
    
    For Each objLogfile in colLogFiles
        If objLogFile.FileSize <> 100000 Then
           strBackupLog = objLogFile.BackupEventLog _
               ("D:\Eventlogs\" & strBackupName & objLogFile.LogFileName & ".evt")
           objLogFile.ClearEventLog()
        End If
    Next
    Source : Windows XP Event Log export/copy : event, log, export, xp, windows
    strComputer is specified

    Quote Originally Posted by russdev View Post
    Link from Koryo worked great next issue..

    Next Issue part of script pulls the event viewer logs off..

    Code:
    'Get Application Logs
        Set objWMIService = GetObject("winmgmts:" _
            & "{impersonationLevel=impersonate,(Backup)}!\\" & _
                strComputerName & "\root\cimv2")
        Set colLogFiles = objWMIService.ExecQuery _
            ("Select * from Win32_NTEventLogFile " _
                & "Where LogFileName='Application'")
        For Each objLogfile in colLogFiles
            errBackupLog = objLogFile.BackupEventLog( _
                "c:\" & strComputerName & "-application.evt")
            WScript.Echo ("File saved as c:\" & strComputerName & "-application.evt")
        Next
    Works fine against Vista machines but not XP machines (errors with permission denied error). As can tell getting to limits of my knowledge when it comes to windows scripting.
    In your script you have not specified strComputerName

    strComputerName ="."

    Also the below code is slightly different as it has the security option as well
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate, (Backup, Security)}!\\" _
    & strComputer & "\root\cimv2")

  15. Thanks to mac_shinobi from:

    russdev (7th December 2010)

  16. #11

    russdev's Avatar
    Join Date
    Jun 2005
    Location
    Leicestershire
    Posts
    6,918
    Thank Post
    708
    Thanked 550 Times in 365 Posts
    Blog Entries
    3
    Rep Power
    204
    strcomputername is sorted out at the start of script (just not shown that) my code above was just event viewer part of much larger script. Will try with security option and see what happens.

    Russ

    p.s

    If want to see the script then look at getlogs.vbs - rmloggetter - Project Hosting on Google Code.

    p.p.s

    Would not use on live environment yet and lots of tidying up to do on the code.

  17. #12


    Join Date
    Feb 2007
    Location
    51.405546, -0.510212
    Posts
    8,748
    Thank Post
    221
    Thanked 2,626 Times in 1,936 Posts
    Rep Power
    778
    Mac_Shinobi is correct. Without the backup and security privileges you will receive an error.

    http://theadminblog.blogspot.com/200...-and-user.html

    What is interesting to note here is that WMI is not consistent in reporting missing privileges: in the first case there was no error at all, in the second example Win32_Process.Terminate returned the error code that signaled the missing privilege and continued, and in the third script Win32_NTEventLogFile.BackupEventLog caused the script to crash this is not very helpful when debugging WMI scripts. Here is some more information that just adds to the confusion: to back up the Security log file you need both Security and Backup privileges. If you use just the Security privilege you will get the "Access denied" error, but if you use just the Backup privilege, Win32_NTEventLogFile.BackupeventLog will return 5, an error code not listed in the documentation. To make it work, use both privileges.

  18. Thanks to Arthur from:

    russdev (7th December 2010)

  19. #13

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,703
    Thank Post
    3,235
    Thanked 1,043 Times in 965 Posts
    Rep Power
    363
    Quote Originally Posted by Arthur View Post
    Mac_Shinobi is correct. Without the backup and security privileges you will receive an error.

    SysAdmins Blog: WMI, Windows Event Logs and User Privileges
    I was about to reply and ask what account type he is logged in when running said script as I know when running vbscripts using wmi against a remote computer you need to use elevated rights with wmi to allow you to run the code as an admin ( whether domain admin or local admin, generally it is domain admin ) rights.

    Connecting to WMI on a Remote Computer (Windows)

    Just in the google code it is using an inputbox to enter in the computer name which will rely on human input ( so possible errors occuring with the human factor, as apposed to using a method such as the network object to ascertain the computer name on which the script is running on )

    What is it exactly that you are trying to achieve though ?

  20. Thanks to mac_shinobi from:

    russdev (7th December 2010)

  21. #14

    russdev's Avatar
    Join Date
    Jun 2005
    Location
    Leicestershire
    Posts
    6,918
    Thank Post
    708
    Thanked 550 Times in 365 Posts
    Blog Entries
    3
    Rep Power
    204
    The script does what it says on tin really. It gets all the RM log files and zips them up.

    If not used CC4 and RM support then you might think this script is pointless. But after getting the log files for RM support 100th time I got annoyed and decided to write batch file (v1.0, 1.1 & 1.2) to save some time. V1.3 was never released and it was then I decided a move away from batch file was needed.

    The script means as soon as RM support say can you send me these log files you run the script against machine then send the zip file and they have all the log files they need.

    As for user input well it is needed as machine you run script against is different each time as one time I want log files for one machine. Then might need another machine next time etc. Also chances are not at station your running script on hence why it gets everything remotely.

    I do need to sort out error handling on the input through

  22. #15

    Join Date
    May 2010
    Location
    England
    Posts
    104
    Thank Post
    20
    Thanked 16 Times in 13 Posts
    Rep Power
    11
    Hi Russ

    Any chance you can PM me the script or re-upload it to google? I was kind of hoping to port it to powershell for a little challenge, if your ok with that, but it appears to have dissapeared

    *EDIT*

    Meh. links down, but the code repository is still there, went 1 URL up. I'm going to have a quick play with powershell. If you'd rather i didn't then please do tell me, not trying to take away from your fire or anything, but as im learning powershell it seems the ideal thing to play with.

    Thanks
    Last edited by koryo; 9th December 2010 at 07:05 PM.

SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 3
    Last Post: 21st March 2012, 12:10 PM
  2. Scripting Wireless - Windows XP/Vista
    By barryfl in forum Wireless Networks
    Replies: 18
    Last Post: 22nd June 2011, 09:57 AM
  3. Windows 7 Printer Scripting HELP!!
    By Scottyboy99 in forum Windows 7
    Replies: 13
    Last Post: 6th November 2009, 01:44 PM
  4. checking my other pc
    By mikeymike in forum General Chat
    Replies: 5
    Last Post: 4th August 2008, 01:30 AM
  5. PC Checking
    By Gatt in forum How do you do....it?
    Replies: 16
    Last Post: 23rd February 2007, 12:13 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •