微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何从提升的AHK脚本启动未提升的exe?

如何解决如何从提升的AHK脚本启动未提升的exe?

我试图通过按键盘上的“播放/暂停”按钮来启动Spotify(如果未运行)。

我有这个。

Media_Play_Pause::
Process,Exist,spotify.exe
if ErrorLevel
{
    Send {Media_Play_Pause}
}
else
{
    Run,Spotify
}
return

这可行,但是由于我的ahk以管理员身份运行,因此Spotify也以管理员身份运行。 为什么这样不好?因为提升的Spotify不在任务栏预览中显示媒体控制按钮,而是在任务栏上与固定的Spotify图标分开创建一个新图标。

有什么方法可以以普通用户而非管理员身份运行Spotify?

解决方法

让Shell为您运行程序。
Here's一个实现,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
,

您正在寻找RunAs

例如:

RunAs,UserName,UserPassword
Run,Spotify

应该以指定的用户身份运行Spotify,您可以将其指定为自己的用户个人资料[您需要使用正确的凭据替换UserName和UserPassword才能使它正常工作>

如果不确定用户名是什么,可以在命令提示符下使用net user命令列出所有用户名。

以下是更改后的代码:

Media_Play_Pause::
Process,spotify.exe
if ErrorLevel
{
    Send {Media_Play_Pause}
}
else
{
    RunAs,UserPassword ;Change these to be the correct values!
    Run,Spotify
}
return

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。