当任务计划程序运行VBScript和批处理文件失败 [英] VBScript and batch file fails when run by Task Scheduler

查看:789
本文介绍了当任务计划程序运行VBScript和批处理文件失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有检查,看看是否微软Word运行隐患,使它可见一个VBScript,然后再次隐藏它。

I have a VBScript that checks to see if MS Word is running hidden, makes it visible, then hides it again.

下面是脚本code当我双击在资源管理器文件正常工作:

here is the script code that works fine when I double click the file in Explorer:

dim oWord
Dim wshShell, btn
Set wshShell = WScript.CreateObject("WScript.Shell")

set oWord = getobject(, "Word.Application")

if isobject(oWord) then 
    on error goto 0
    wshShell.Popup "Word is running, making visible", 7, "ALPS Push print", &H0 + &H40
    oWord.visible=true
    wshShell.Popup "MS Word is now visible" & vbcrlf & vbcrlf & "Waiting 30 seconds then hiding it", 30, "ALPS Push print", &H0 + &H30
    oWord.visible=false
else    
    wshShell.Popup "Word is not running" & vbcrlf & vbcrlf & "Quitting", 7, "ALPS Push print", &H0 + &H40
end if

它的工作原理发现当我运行它,但是当它在任务计划程序运行失败,所以我创建一个批处理文件来启动它。

It works find when I run it, but when it runs under Task Scheduler it fails so I created a batch file to launch it

wscript C:\dev\checkALPS.vbs

现在,当我尝试从任务计划程序运行它,它仍然失败,下面的错误消息

Now when I try to run it from the Task Scheduler, it still fails with the below error message

---------------------------
Windows Script Host
---------------------------
Script: C:\dev\checkALPS.bat
Line:   7
Char:   1
Error:  ActiveX component can't create object: 'getobject'
Code:   800A01AD
Source:     Microsoft VBScript runtime error

我能做些什么来得到这个工作?

What can I do to get this working?

推荐答案

我曾经有过这样类似的问题,我利用cscript.exe应用程序启动VBScript作为一个控制台应用程序,而不是一个Windows应用程序绕过它。有一种可能性,即有关于在域或计算机不允许视窗应用程序通过W脚本执行的限制。作为替代方案,尝试通过的Cscript.exe,而不是激活相同的脚本。

I have had this similar issue, I bypassed it by utilizing cscript.exe application to activate the vbscript as a console application rather than a windows application. There is a possibility that there is a limitation on the domain or computer which does not allow windows applications to be executed via wscript. As an alternative, try activating the same script via "Cscript.exe" instead.

所以,code将是:

cscript C:\dev\checkALPS.vbs

和的get对象的方法不脱WScript的可执行文件的启动。所以你需要通过W脚本来激活它。

And the get object method is not activated off of the wscript executable. So you would need to activate it via wscript.

dim oWord
Dim wshShell, btn
Set wshShell = WScript.CreateObject("WScript.Shell")

set oWord = Wscript.GetObject(, "Word.Application")

if isobject(oWord) then 
    on error goto 0
    wshShell.Popup "Word is running, making visible", 7, "ALPS Push print", &H0 + &H40
    oWord.visible=true
    wshShell.Popup "MS Word is now visible" & vbcrlf & vbcrlf & "Waiting 30 seconds then hiding it", 30, "ALPS Push print", &H0 + &H30
    oWord.visible=false
else    
    wshShell.Popup "Word is not running" & vbcrlf & vbcrlf & "Quitting", 7, "ALPS Push print", &H0 + &H40
end if

给一个秋千,让我知道它是如何工作。

Give that a swing and let me know how it works.

这篇关于当任务计划程序运行VBScript和批处理文件失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆