如果我以前尝试过有关此问题的过多解决方案,则不会发布。
我已经开发了一个软件,该软件使用.vbs文件(exporter.vbs)从安装在客户端计算机上的另一软件(Reporter.exe)执行.exe 。
手动运行exporter.vbs(右键单击并打开)完全可以正常运行。当通过任务计划程序以我自己的Windows用户身份在我自己的计算机上运行时,它可以完美运行,完全符合预期。
在客户端Windows Server 2008/2012机器上手动运行时,它完全可以正常工作,完全符合预期。当通过任务计划的任何用户(不包括管理员组)中运行,任务调度器返回报告作为为0x0,然而reporter.exe并未如预期生成的文件。
当通过任务计划程序以用户Administrators身份运行在客户端Windows Server 2008/2012机器上运行时,它可以运行,但是在一夜之间(当我们的任务设置为运行时)不能运行。
计划任务设置-常规
计划任务设置-操作
在上述方案中,随着脚本其他部分正在运行(脚本的其他部分清空目标XML文件),exporter.vbs似乎在脚本的此阶段跳闸。
Function Export(filepath, report)
dim fso
set fso_tidy = CreateObject("Scripting.FileSystemObject")
if fso_tidy.FileExists(filepath)=true then
set fso_tidy = nothing
set oShell = CreateObject("WScript.Shell")
oShell.Run """"&simsdir&"\CommandReporter.exe"" /QUIET /user="""&simsu&""" /password="""&simsp&""" /REPORT:"""&report&" v"&rptv&""" /OUTPUT:"""&filepath&"""", 0, true
set oShell = nothing
set fso_tidy = CreateObject("Scripting.FileSystemObject")
set objFile = fso_tidy.GetFile(filepath)
if objFile.size > 64 then
size = round(objFile.size / 1024, 1)
WriteToLog "DATA", "(OK) "&report&" EXPORTED (size: "&size&"kb)"
else
WriteToLog "DATA", "(FAILED) "&report&" EXPORTED (size: "&size&"kb)"
end if
set objFile = nothing
end if
set fso_tidy = nothing
end Function
This function is called 5 times, one time for each report we need to export data from the Software.
Is there something I am missing in terms of how vbs need to be run from Task Scheduler if they manipulate files etc
You have the task set to run in the context of the Local System account. The System account is not a full-blown interactive user, so not everything will run in that context. You must keep the following considerations in mind when using it for tasks:
COMPUTERNAME$
),因此,如果filepath
位于网络共享上,则本地计算机帐户必须对此(或“所有人”组)具有特定的权限。尝试以真正的本地或域帐户(而不是系统帐户)运行任务。当然,您需要将密码嵌入到任务中才能正常工作。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句