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.

Samstag, 22. März 2008

Learn Windows Scripting Act 1 - Class material

Class material used in 'Learn Windows Scripting Act 1'

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

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

Code Snippets used:

Connect to WMI

strComputer="."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)For Each objItem in colItems

next


Connect to Windows Registry

HKEY_USERS = &H80000003

Set objReg = GetObject _ ("winmgmts:{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\default:StdRegProv")

comppath = "" & sidentry & "" & strKeyPath & ""
retVal = objReg.SetStringValue(HKEY_USERS, comppath, strEntryName, dwValue)

Complete Script

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each objItem in colItems
nm = objItem.UserName
next
Result = InStrRev(nm, "\")
tre = len(nm)
tre1 = tre - Result
Res = right(nm,tre1)

Set colOS = objWMIService.ExecQuery("Select * from WIN32_UserAccount where Name="""& Res & """")

for each obj in colOS
X1 = obj.SID
Next

strKeyPath ="\Software\Microsoft\Windows\CurrentVersion\Internet Settings"

HKEY_USERS = &H80000003

Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
comppath = "" & X1 & "" & strKeyPath & ""
strEntryName = "AutoConfigURL"
dwValue = "http://proxy/pac/proxy.pac"

retval = objReg.SetStringValue(HKEY_USERS, comppath, strEntryName, dwValue)

Wscript.echo retval


Keine Kommentare: