Jump to content

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


Recommended Posts

Posted (edited)

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.

 

 

'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

Edited by russdev
Posted (edited)

Link from Koryo worked great next issue..

 

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

 

'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.

Edited by russdev
Posted

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.

Posted

@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

Posted (edited)

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.

 

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

Edited by koryo
  • Thanks 1
Posted
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.

 

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

 

Link from Koryo worked great next issue..

 

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

 

'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")

  • Thanks 1
Posted

Mac_Shinobi is correct. Without the backup and security privileges you will receive an error.

 

http://theadminblog.blogspot.com/2009/07/wmi-windows-event-logs-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.
  • Thanks 1
Posted
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 ?

  • Thanks 1
Posted

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 :)

Posted (edited)

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

Edited by koryo
Posted
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 :)

 

Can't you get the script to enumerate all machines on the domain and populate a listbox in a hta type interface ??

 

Then they can pick one or multiple computers to run it against

Posted
Can't you get the script to enumerate all machines on the domain and populate a listbox in a hta type interface ??

 

Then they can pick one or multiple computers to run it against

 

you make it sound so easy.... :p

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...