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


Donnerstag, 20. März 2008

$Scripting Video Tutorials become reality!$

Hi,
yeah...finally I'm almost ready to put out the first video of my "How to script" series.
We've found an appropriate screen capturing software, created a Youtube Channel and will start recording the first video tomorrow. This is going to discuss a script which I've written during my tenure at the ECB, changing proxy settings in InternetExplorer for the currently logged on user only.

This will touch some nice techniques which you definitely want to know about when dealing with windows scripting. Also I'm going to give you some ideas on how to strategically approach a scripting task, dividing the workload into logical segments and working with the WMI Namespace reference Microsoft is providing to us.

So, maybe this will be available sometime next week (I hope so), most likely it will :P

Cheers

Jay