[已关闭]求救以管理员权限运行函数
本帖最后由 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可以做到吗?求那位高手给个帮助 Why no engineer ? 这个是...修改计算机名? http://www.autoitx.com/forum.php?mod=viewthread&tid=13871
参考我的
solved
Run("runas /noprofile /user:jnj\kzhang6 ""netsh firewall set opmode disable""")
WinWait("C:\WINDOWS\system32\runas.exe")
Send("88888888")
Send("{Enter}") 本帖最后由 wgboy 于 2010-3-31 09:17 编辑
我要的这个是rename()函数里面的内容都要用管理员权限运行,我就用这一个角本去实现?4楼说的只能运行 一些程序
实在没办法只能把这个编译成EXE文件,,然后再一个脚本,用runas调用,不过这样就会产生两个脚本。。我希望是一个脚本就能完成。。那位高手出来帮忙下。谢谢!
页:
[1]