使用不同用户运行 VBscript 时出错

发布于 2024-11-06 02:19:03 字数 1184 浏览 0 评论 0原文

我正在编写一个脚本,该脚本将在本地管理员帐户下作为计划任务运行。脚本的核心如下:

'Calculate date time
dtm = Now
ymd = (Year(dtm)*10000) + (Month(dtm)*100) + Day(dtm)
hms = (Hour(dtm)*10000) + (Minute(dtm)*100) + Second(dtm)
dString = ymd & "_"  & hms
Set Wso = CreateObject("WScript.Shell")
'Write random string to text file for reference by incremental script
Const ForWriting = 2
Set objFile = Fso.OpenTextFile("e:\backups\dString.txt", ForWriting, True)
objFile.WriteLine(dString)
objFile.Close
'Append random string to make full backup name unique'
'Execute full backup creation'
'PROBLEM: Below line will only execute under my domain account
Wso.Run("trueimagecmd /create /filename:""e:\backups\autoBackup_" & dString &"_.tib"" /compression:5 /incremental /partition:""C""")

上面的代码片段将在我的域帐户下正常运行,但会在上面指示的行上出错,并显示以下内容:

The system cannot find the file specified
Code: 80070002
Source (null)

当我在我的帐户下运行它时,不会发生此错误。我不太熟悉运行“Wscript.Shell”实例所需的权限。任何见解都值得赞赏。

更新:

trueImagecmd 是 Acronis 恢复软件的命令行版本。我使用此脚本作为自动化部署过程的一种方式。该命令很好,当在本地管理员帐户下运行时,我可以自己运行该脚本,但是,该脚本执行到指定的位置时,运行命令抛出错误。

更新 2:

看起来包含完整路径解决了问题。感谢大家的建议。

I'm working on a script that will run as a scheduled task under a local admin account. The heart of the script is as follows:

'Calculate date time
dtm = Now
ymd = (Year(dtm)*10000) + (Month(dtm)*100) + Day(dtm)
hms = (Hour(dtm)*10000) + (Minute(dtm)*100) + Second(dtm)
dString = ymd & "_"  & hms
Set Wso = CreateObject("WScript.Shell")
'Write random string to text file for reference by incremental script
Const ForWriting = 2
Set objFile = Fso.OpenTextFile("e:\backups\dString.txt", ForWriting, True)
objFile.WriteLine(dString)
objFile.Close
'Append random string to make full backup name unique'
'Execute full backup creation'
'PROBLEM: Below line will only execute under my domain account
Wso.Run("trueimagecmd /create /filename:""e:\backups\autoBackup_" & dString &"_.tib"" /compression:5 /incremental /partition:""C""")

The above snippet will run fine under my domain account, but will error on the line indicated above with the following:

The system cannot find the file specified
Code: 80070002
Source (null)

This error will not occur when I run it under my account. I'm not familiar enough with the permissions required to run an instance of "Wscript.Shell". Any insight is appreciated.

UPDATE:

trueImagecmd is a command line version of Acronis recovery software. I'm using this script as a way of automating the process for deployment. The command is fine and I can run this script as myself, when running under the local admin account, however, the script executes up to the point indicated, the run command is throwing the error.

UPDATE 2:

Looks like including the full path fixed the problem. Thanks all for your suggestions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不顾 2024-11-13 02:19:03

您是否尝试过使用可执行文件的完整路径调用 trueimagecmd ?
例如 C:\progra~1\trueimage\trueimagecmd.exe

Have you tried calling trueimagecmd with the full path to the executable?
For instance C:\progra~1\trueimage\trueimagecmd.exe

·深蓝 2024-11-13 02:19:03

确保另一台机器上有驱动器 E,从那里产生错误。尝试使用 c:\backups\autoBackup_" & dString &".tib" 而不是 e:\backups\autoBackup ”& dString &"_.tib"

Make sure you have drive E in the other machine from where it generates error. Try using c:\backups\autoBackup_" & dString &".tib" instead of e:\backups\autoBackup" & dString &"_.tib"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文