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.

Donnerstag, 17. Mai 2007

Graphical script for Renaming Hostname + Reboot

On Error Resume Next

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputers = objWMIService.ExecQuery _ ("Select * from Win32_ComputerSystem")
call Load
Sub Load
For Each objComputer in colComputersstrNewName = inputbox("Current ComputerName is: " & objcomputer.name & "" & vbNewLine & "Enter New ComputerName","Rename Computer","FUNA0xxx5SCxxxx")
next
if strNewName = "" thenWScript.quit(0)
end if
Dim Lenght
lenght = len(strNewName)
if lenght = 15 then
For Each objComputer in colComputers
errReturn = ObjComputer.Rename(strNewName)
next
if errReturn <> 0 or errReturn = ""
thenWscript.Echo "Renaming Computer failed with following error: " & err.Number &amp; "" & vbnewline & ""WScript.quit(0)
else
WScript.Echo "Computer has been renamed successfully. Please remove Disk and hit OK to reboot"
call Rbt
end if
else
WScript.Echo "ComputerName must be 15 characters long.Please try again!"call load
end if
end sub


Sub RbtSet
colComputers2 = objWMIService.ExecQuery _ ("Select * from Win32_OperatingSystem")For Each objComputer2 in colComputers2
objComputer2.Security_.privileges.AddAsString "SeShutdownPrivilege", true
errRet = objComputer2.Reboot()
next
end Sub
'created by Julian Ruf

Keine Kommentare: