Friday, October 23, 2009

Sample WMI scripts

So, I figured I would deviate from the regular linux techie stuff and put up one of the WMI vbscripts that I have been playing with the last few days.

RunningServices.vbs: At work, we use a backup solution that requires VSC (Volume Shadow Copy) running on the client machine in order to backup opened files. When setting up the clients on the individual machines, we usually check to make sure VSC is set to automatic; but sometimes we forget. With 300+ machines, going to each remote client, or connecting to each remote client via services.msc would be WAY too time consuming. So, alas, I whipped up a vbscript that uses WMI to connect to each machine. Keep in mind, I am NOT a vbscript person, I had to rely on my rusty memory from the last few years of dabbling in vbscripting.

'RunningServices.vbs
'VB Script to check on the status of VSC running on remote machines
'Need to replace the "." next to Array with a remote computer name
'syntax is: "computer1","computer2","etcetcetc"


On Error Resume Next
Dim oShell
Set oShell = CreateObject("Wscript.Shell")

forceUseCScript

Sub forceUseCScript()
If Not WScript.FullName = WScript.Path & "\cscript.exe" Then
oShell.Popup "Launched using wscript. Relaunching...",3,"WSCRIPT"
oShell.Run "cmd.exe /k " & WScript.Path & "\cscript.exe //NOLOGO " & Chr(34) & WScript.scriptFullName & Chr(34),1,False
WScript.Quit 0
End If
End Sub


arrComputers = Array(".")
For Each strComputer In arrComputers
WScript.Echo
WScript.Echo "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"
WScript.Echo "Computer: " & strComputer
WScript.Echo "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_Service WHERE DisplayName = 'Volume Shadow Copy'",,48)
For Each objItem in colItems
Wscript.Echo "Service: " & objItem.DisplayName
Wscript.Echo "StartMode: " & objItem.StartMode
Wscript.Echo "State: " & objItem.State
Next
Next



Executing this will display the output on a terminal window. So there you have it! Now I'm currently experimenting with getting MS Access 2007 Professional to work in Wine! If I can get it to work, I will have to post the results :-)

No comments:

Post a Comment