Windows Scripting BLOG

Due to limited time working on this project this place is not intended to people who are new to scripting but much more for people who are already familiar with the VBS/WMI syntax.

Mittwoch, 2. April 2008

Learn Windows Scripting Act 4 - Class material

Class material for ACT 4

References

Split Method
http://msdn2.microsoft.com/en-us/library/0764e5w5(VS.85).aspx

Open Text File
http://support.microsoft.com/kb/300982

Complete Script

On Error Resume Next

IN_FILE = "test.txt"
Const PRO_READ = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(IN_FILE, PRO_READ)
strComputers = objFile.ReadAll
objFile.Close
arrComputers = Split(strComputers, vbCrLf)

For Each strComputer In arrComputers



Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Service where DisplayName = ""MSSQLSERVER""")


For Each objItem in colItems



ret = objitem.StopService() & " on Computer " &
strComputer


Wscript.Echo ret


next



Next

* Loop routine wrapped around the core script
* Core script wrapped into the Loop routine