如何从提升的 AHK 脚本启动未提升的 exe?
How to launch unelevated exe from elevated AHK script?
我正在尝试启动 Spotify,如果它不是 运行ning,请按键盘上的 Play/Pause 按钮。
我有这个。
Media_Play_Pause::
Process, Exist, spotify.exe
if ErrorLevel
{
Send {Media_Play_Pause}
}
else
{
Run, Spotify
}
return
这有效,但由于我的 ahk 是 运行 作为管理员,Spotify 也是 运行 作为管理员。
为什么这样不好?因为提升的 Spotify 不会在任务栏预览中显示媒体控制按钮,它会在任务栏上创建一个与固定的 Spotify 图标分开的新图标。
有什么方法可以 运行 Spotify 作为普通用户而不是管理员?
您正在寻找RunAs
例如:
RunAs, UserName, UserPassword
Run, Spotify
Spotify 是否应该作为您指定的用户,您可以将其指定为您自己的用户配置文件[您需要将 UserName 和 UserPassword 替换为正确的凭据才能正常工作]
如果您不确定自己的用户名是什么,可以在命令提示符下使用 net user
命令列出所有用户名。
以下是您的代码经过此更改后的样子:
Media_Play_Pause::
Process, Exist, spotify.exe
if ErrorLevel
{
Send {Media_Play_Pause}
}
else
{
RunAs, UserName, UserPassword ;Change these to be the correct values!
Run, Spotify
}
return
获取 Shell 到 运行 适合您的程序。
Here's one implementation, and here's另一个。
没有意见哪个更好,两个都适合我。
脚本中任一函数的用法为:
Media_Play_Pause::
Process, Exist, spotify.exe
if (ErrorLevel)
SendInput, {Media_Play_Pause}
else
ShellRun("Spotify") ; I don't have Spofify, so I didn't try using this short name for it. If it doesn't work, try to specify the full path of the exe
return
; copy paste the function here
我正在尝试启动 Spotify,如果它不是 运行ning,请按键盘上的 Play/Pause 按钮。
我有这个。
Media_Play_Pause::
Process, Exist, spotify.exe
if ErrorLevel
{
Send {Media_Play_Pause}
}
else
{
Run, Spotify
}
return
这有效,但由于我的 ahk 是 运行 作为管理员,Spotify 也是 运行 作为管理员。 为什么这样不好?因为提升的 Spotify 不会在任务栏预览中显示媒体控制按钮,它会在任务栏上创建一个与固定的 Spotify 图标分开的新图标。
有什么方法可以 运行 Spotify 作为普通用户而不是管理员?
您正在寻找RunAs
例如:
RunAs, UserName, UserPassword
Run, Spotify
Spotify 是否应该作为您指定的用户,您可以将其指定为您自己的用户配置文件[您需要将 UserName 和 UserPassword 替换为正确的凭据才能正常工作]
如果您不确定自己的用户名是什么,可以在命令提示符下使用 net user
命令列出所有用户名。
以下是您的代码经过此更改后的样子:
Media_Play_Pause::
Process, Exist, spotify.exe
if ErrorLevel
{
Send {Media_Play_Pause}
}
else
{
RunAs, UserName, UserPassword ;Change these to be the correct values!
Run, Spotify
}
return
获取 Shell 到 运行 适合您的程序。
Here's one implementation, and here's另一个。
没有意见哪个更好,两个都适合我。
脚本中任一函数的用法为:
Media_Play_Pause::
Process, Exist, spotify.exe
if (ErrorLevel)
SendInput, {Media_Play_Pause}
else
ShellRun("Spotify") ; I don't have Spofify, so I didn't try using this short name for it. If it doesn't work, try to specify the full path of the exe
return
; copy paste the function here