在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”即可。