我将其编译成可执行文件,但是要打开它,我必须右键单击并按“以管理员身份运行”。我希望每次运行时都能请求管理员权限,但如何做到呢?
我无法这样做:
因为当我将它复制到第二台计算机上时会失效。
我无法这样做:
因为当我将它复制到第二台计算机上时会失效。
尝试将以下内容添加到自动执行部分(脚本顶部):
; If the script is not elevated, relaunch as administrator and kill current instance:
full_command_line := DllCall("GetCommandLine", "str")
if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
try ; leads to having the script re-launching itself as administrator
{
if A_IsCompiled
Run *RunAs "%A_ScriptFullPath%" /restart
else
Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
}
ExitApp
}
并重新编译脚本。
#SingleInstance Force
if not A_IsAdmin
Run *RunAs "%A_ScriptFullPath%"
#SingleInstance Force
if !A_IsAdmin
Run, % "*RunAs " (A_IsCompiled ? "" : A_AhkPath " ") Chr(34) A_ScriptFullPath Chr(34)
Chr(34)
返回字符 "
在AHK V2中
#SingleInstance Force
full_command_line := DllCall("GetCommandLine", "str")
if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
try
{
if A_IsCompiled
Run '*RunAs "' A_ScriptFullPath '" /restart'
else
Run '*RunAs "' A_AhkPath '" /restart "' A_ScriptFullPath '"'
}
ExitApp
}
#SingleInstance Force
尝试终止已经在运行的脚本,但失败了(因为正在运行的脚本是以管理员身份运行的,但新的调用不是)。 - snath03