2010年8月23日 星期一

UAC下,利用autohotkey去執行runas

AdminAccount=
AdminPWD=
ConfigFile=D:\GameStarter.ini
MyCode=%1%

SetWorkingDir %A_ScriptDir%
Loop, %0% ; No need for the intermediary variable 'param':
params .= A_Space . """" . %A_Index% . """"

if( A_USERNAME <> AdminAccount ){
RunAs, %AdminAccount%,%AdminPWD%
Run, %A_ScriptFullPath% %params%
ExitApp
}

Loop
{
FileReadLine, line, %ConfigFile%, %A_Index%
if ErrorLevel
break
StringSplit, word_array, line, `,, . ; Omits periods.
if ( word_array0 == 3 ){
Game_Code=%word_array1%
if ( Game_Code == MyCode ){
GameTitle=%word_array2%
CMD=%word_array3%
}
}

}


if ( CMD <> "" ){
MsgBox, 64, 遊戲啟動器, %GameTitle%, 3
if ( not A_IsAdmin ) {
if ( A_IsCompiled ){
BUF=
Loop, parse, CMD, `\
{
if ( BUF <> "" ){
MYWORKINGDIR =%MYWORKINGDIR%%BUF%\
}
BUF=%A_LoopField%
}
DllCall("shell32\ShellExecuteA", uint, 0, str, "RunAs", str,CMD
, str, str , str, MYWORKINGDIR, int, 1)
}else{
DllCall("shell32\ShellExecuteA", uint, 0, str, "RunAs", str, A_AhkPath
, str, """" . A_ScriptFullPath . """" . SubStr(params,2), str, A_WorkingDir, int, 1)
}
ExitApp
}

} else {
MsgBox, 16, 遊戲啟動器錯誤, 該遊戲並未經過認證通過, 3
}

沒有留言: