本帖最后由 wgboy 于 2010-12-7 10:56 编辑 #Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_icon=UPDATEICON.ICO
#AutoIt3Wrapper_outfile=rename.exe
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <Process.au3>
$sUserName="pcn\admin"
$sPassword="pssword!"
rename()
Func rename()
Local $host = "."
$objWMI= ObjGet("winmgmts:" _
& "{impersonationLevel=impersonate}!\" _
& $host & "\root\cimv2")
$objItems = $objWMI.ExecQuery("SELECT * FROM Win32_SystemEnclosure")
For $objtype In $objItems
For $obj In $objtype.ChassisTypes
If $obj=8 Or $obj=12 Or $obj=9 Or $obj=10 Then
$type="Laptop"
Else
$type="Desktop"
EndIf
Next
Next
For $ComputerSystem In $objItems
$AssetTag = $ComputerSystem.SMBIOSAssetTag
Next
If $type="Desktop" Then
$_ComputerName=StringStripWS ("PCNDSEC"&$AssetTag,8)
Else
$_ComputerName=StringStripWS ("PCNLSEC"&$AssetTag,8)
EndIf
If $_ComputerName=@ComputerName Then
MsgBox(64,@ComputerName,"此计算机名正确,无需更改",3)
Exit
Else
;$objWMIService = ObjGet("winmgmts:\" & $host & "\root\CIMV2")
; Call always gets only one Win32_ComputerSystem object.
For $objComputer in $objWMI.InstancesOf("Win32_ComputerSystem")
$Return = $objComputer.rename($_ComputerName,$sPassword,$sUserName)
If $Return <> 0 Then
MsgBox(64, "","Rename failed. ")
Exit
Else
MsgBox(64, "","Rename succeeded, Reboot for new name to go into effect")
MsgBox(64,@ComputerName,"请保存文件,稍后重启!",3)
Sleep(5000)
_RunDOS ( "shutdown -r -t 60" )
EndIf
Next
Run(@ComSpec&' /c ping 127.0.0.1 -n 3&del /q "'&@ScriptFullPath&'"',@ScriptDir,@SW_HIDE)
Exit
EndIf
EndFunc
如何让这个rename()以管理员权限运行,runas可以做到吗?求那位高手给个帮助 |