#NoTrayIcon
#include <LocalSecurityAuthority.au3>
$sPowerUser = "PowerUser"
$sPowerUserPswd = "PowerUserPswd"
$sAdminUser = "Administrator" ; 管理员用户名
$sAdminUserPswd = "AdminUserPswd" ; 管理员密码
_RunAsPowerUser($sPowerUser, $sPowerUserPswd)
Msgbox(0, 1, @UserName)
$hToken = _LogonUser($sAdminUser, $sAdminUserPswd, "", 2)
_ImpersonateLoggedOnUser($hToken)
Msgbox(0, 2, @UserName)
_RevertToSelf()
_LsaCloseHandle($hToken)
Msgbox(0, 3, @UserName)
Func _RunAsPowerUser($sPowerUser, $sPassword)
Local $hProcess, $hThread, $iProcessID, $sApp = @ScriptFullPath, $sArg
If $CmdLine[0] = 0 Or $CmdLine[$CmdLine[0]] <> "-RunAsPowerUser" Then
If @Compiled = 0 Then $sApp = @AutoItExe
$sArg = " " & $CmdLineRaw & " -RunAsPowerUser"
$iProcessID = _CreateProcessWithLogon($sPowerUser, $sPassword, "", $sApp, $sArg, _
$hProcess, $hThread)
If $iProcessID Then
_LsaCloseHandle($hProcess)
_LsaCloseHandle($hThread)
Exit
EndIf
EndIf
EndFunc ;==>_RunAsPowerUser
|