轉自 http://phorum.study-area.org/index.php?topic=49247.0
' 作業系統支援
' Windows Server 2003 : Yes
' Windows XP : Yes
' Windows 2000 : No
' Windows NT 4.0 : No
' Windows 98 : No
Const HKEY_LOCAL_MACHINE = &H80000002
' 目標電腦名稱
strComputer = "oldname"
' 新電腦名稱
strNewName = "newname"
' 電腦描述
strDescription = "某某某的電腦"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputers = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objComputer in colComputers
err = objComputer.Rename(strNewName)
If Err <> 0 Then
Wscript.Echo "無法修改電腦名稱, 錯誤碼: " & Err
End If
Next
Set objRegistry = GetObject _
("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "System\CurrentControlSet\Services\lanmanserver\parameters"
strValueName = "srvcomment"
objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strDescription
Set objWMIService2 = GetObject _
("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process")
Error = objWMIService2.Create("C:\windows\system32\shutdown.exe -t 30 -r -c ""電腦名稱已更新為 '" & strnewname & "', 30 秒鍾後將自動重新開機"" ", null , null, intProcessID)
If Error <> 0 Then
Wscript.Echo "無法執行 shutdown.exe, 錯誤碼: " & _
Error & "."
End If
沒有留言:
張貼留言