VBScript通过hta执行程序

在hta文件里用vbscript执行程序,原来的写法是:

Set shl = CreateObject("Wscript.Shell")
shl.CurrentDirectory = foo
Call shl.Run("""" & bar & """")

在windows 7下运行正常,但是在windows 11下,如果这个程序是在Program Files或者Program Files (x86)下,则必须以管理员身份运行,上面的代码就失效了。

查了资料,改写成

Set oShell = CreateObject("Shell.Application")
oShell.ShellExecute """" & bar & """", , foo, "runas", 1

运行正常。如果不需要以管理员身份运行,去掉“runas”即可。

posted @ 2023-06-28 02:26  平静寄居者  阅读(68)  评论(0编辑  收藏  举报