' Kod zmienia nazw komputera. Jeli w domenie istnieje konto
' komputera, NIE modyfikuje go.
' ------ KONFIGURACJA SKRYPTU ------
strComputer = "<AktualnaNazwaSerwera>"
strNewName = "<NowaNazwaSerwera>"
' ------ KONIEC KONFIGURACJI ---------
const HKLM   = &H80000002
strKeyPath   = "System\CurrentControlSet\Control\ComputerName\ComputerName"
set objReg = GetObject("winmgmts:\\" & strComputer & _
                       "\root\default:StdRegProv")
intRC = objReg.SetStringValue(HKLM, strKeyPath, "ComputerName", strNewName)
if intRC <> 0 then
   WScript.Echo "Bd ustawienia wartoci wpisu ComputerName: " & intRC
else
   WScript.Echo "Dla wpisu ComputerName ustawiono warto " & strNewName
end if

strKeyPath   = "System\CurrentControlSet\Services\Tcpip\Parameters"
intRC = objReg.SetStringValue(HKLM, strKeyPath, "NV Hostname", strNewName)
if intRC <> 0 then
   WScript.Echo " Bd ustawienia wartoci wpisu NV Hostname: " & intRC
else
   WScript.Echo " Dla wpisu NV Hostname ustawiono warto " & strNewName
end if

WScript.Echo "Ponowne uruchamianie systemu..."
set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
for each objOS in objWMI.InstancesOf("Win32_OperatingSystem")
   objOS.Reboot()
next
