以管理员身份运行脚本文件
我有这个 .vbs 脚本,我试图在 Windows 7 上运行。 它必须以完全权限运行,并且必须自动执行。 需要明确的是,当用户双击该文件时,会出现提示“允许以管理员身份运行该文件”,然后以完全权限运行。
为此,我创建了一个调用脚本文件的批处理文件 (run.bat),
cscript "V02.vbs"
pause
然后为该批处理文件创建了一个快捷方式,我可以选择以管理员身份运行该快捷方式。
我现在遇到的问题是,当我以管理员身份运行批处理文件时,文件夹更改为 c\windows\system32。脚本、批处理文件和快捷方式都位于同一文件夹中。有没有办法获取文件夹位置?
I have this .vbs script that I am trying to run on windows 7.
It has to run with full permissions and it has to do it automatically.
To be clear When the user double clicks on the file it will get the prompt that asks "to allow to run the file as an administrator", and then run with full permissions.
To do this I created a batch file (run.bat) that calls the script file
cscript "V02.vbs"
pause
then I created a shortcut for the batch file which I can choose to run as admin.
The problem I encounter now is that when I run the batch file as admin the folder changes to c\windows\system32. The script, batch file and shortcut are all in the same folder. is there a way to get the folder location?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可能误解了...
最简单的解决方案是使用 - 将该路径“硬编码”到补丁文件中
cd \路径\到\我的\脚本
cscript myscript.vbs
暂停
I may have misunderstood...
The easiest solution would be to "hardcode" that path into the patch file with a -
cd \path\to\my\script
cscript myscript.vbs
pause
使用“带有批处理参数的修饰符”。从链接的文档中:
由于
%0
是您的脚本,因此%~dp0
就是您想要的:请注意,%~dp0 包含尾部反斜杠,因此上面的 v02.vbs 文件名变得相当困难阅读。
Use "modifiers with batch parameters". From the linked documentation:
Since
%0
is your script,%~dp0
is what you want:Note that %~dp0 includes the trailing backslash, so your v02.vbs file name above becomes quite hard to read.