在Server 2003上通过计划任务运行vbs文件
我一直致力于修改现有的 vbscript。奇怪的是,当我手动运行脚本时,它工作正常。但是,一旦我尝试将其作为计划任务运行,它就会报告为已完成,但实际上并没有执行任何操作。经过多次故障排除后,我想我找到了原始的 CreateObject。这是代码:
On Error Resume Next
'create an instance of IE
Dim oIE, objFSO, linenum
linenum = 0
Set oIE = CreateObject("InternetExplorer.Application")
'If err.number <> 0 Then linenum = 6
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForAppending = 8
Set objTextFile = objFSO.OpenTextFile ("C:\test.txt", ForAppending, True)
'objTextFile.WriteLine(now() & " Internet object created.")
'Execute our URL
'oIE.navigate("<intranet site>")
'objTextFile.WriteLine(now() & " Starting import")
'wait for the window to be closed (exit IE)
'Do Until Err : oIE.visible = True : wsh.sleep 1000 : Loop
'objTextFile.WriteLine(now() & " Import complete.")
if Err.Number <> 0 then
' An exception occurred
objTextFile.WriteLine("Exception:" & vbCrLf & " linenum: " & linenum & vbCrLf & " Error number: " & Err.Number & vbCrLf & " Error source: " & Err.source & vbCrLf & " Error description: " & Err.Description & vbCrLf)
End If
'clean up
'oIE.Quit
'oIE.Visible = False
'Set oIE = Nothing
我已经注释掉了大部分内容,以缩小范围,并且从我添加的日志记录中,它吐出了当前错误:
Exception:
linenum: 0
Error number: -2147467259
Error source:
Error description:
是的,源代码和描述行是空白的。 谷歌搜索错误似乎没有带来任何有用的信息。所以我不确定发生了什么事。权限已被检查多次,并且它始终以管理员身份运行,即与我登录的用户相同的用户。有趣的是,这个脚本在 Windows 2000 上运行得很好。我唯一能想到的可能是我正在使用的远程桌面连接在某种程度上干扰了它。
有人有任何想法或事情我可以尝试解决这个问题吗?
I've been working on modifying an existing vbscript. The wierd part is that when I run the script manually, it works fine. But as soon as I try to run it as a scheduled task, it reports as complete, but doesn't actually do anything. After much troubleshooting, I think I tracked it down to the original CreateObject. Here's the code:
On Error Resume Next
'create an instance of IE
Dim oIE, objFSO, linenum
linenum = 0
Set oIE = CreateObject("InternetExplorer.Application")
'If err.number <> 0 Then linenum = 6
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForAppending = 8
Set objTextFile = objFSO.OpenTextFile ("C:\test.txt", ForAppending, True)
'objTextFile.WriteLine(now() & " Internet object created.")
'Execute our URL
'oIE.navigate("<intranet site>")
'objTextFile.WriteLine(now() & " Starting import")
'wait for the window to be closed (exit IE)
'Do Until Err : oIE.visible = True : wsh.sleep 1000 : Loop
'objTextFile.WriteLine(now() & " Import complete.")
if Err.Number <> 0 then
' An exception occurred
objTextFile.WriteLine("Exception:" & vbCrLf & " linenum: " & linenum & vbCrLf & " Error number: " & Err.Number & vbCrLf & " Error source: " & Err.source & vbCrLf & " Error description: " & Err.Description & vbCrLf)
End If
'clean up
'oIE.Quit
'oIE.Visible = False
'Set oIE = Nothing
I've commented most of it out, to narrow it down, and from the logging I added, it spits out the current error:
Exception:
linenum: 0
Error number: -2147467259
Error source:
Error description:
Yes, the source and description lines are blank.
Googling the error doesn't seem to bring up anything useful. So I'm not sure what's going on. Permissions have been checked multiple times, and it's always run as Administrator, the same user as I'm logged in as. The funny part is, this script works fine with Windows 2000. About the only thing I can think of is perhaps the Remote Desktop connection I'm using is somehow interfering with it.
Anyone have any ideas or things I might be able to try to resolve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
作为参考,当您在谷歌搜索十进制错误编号时遇到问题时,请尝试将其转换为十六进制。 -2147467259 与 80004005 相同,如果您搜索它,您会发现这是一个相当常见的错误,通常意味着您被拒绝访问某些内容,因此即使您确定它没有您的权限已经检查过,可能值得执行以下检查:
计划任务是否在您手动执行脚本时使用的同一帐户下运行?否则,请尝试对脚本执行 RunAs,以与任务相同的用户帐户运行,如果有效,请尝试将任务安排为您的帐户。
这样您就会知道它是(任务还是手动)还是(用户 1 与用户 2)。这可能会让追踪问题变得更容易一些。
For reference, when you've got problems googling a decimal error number, try converting it to hexadecimal. -2147467259 is the same as 80004005 and if you search for that you'll find that it's quite a common error and usually means that you're denied access to something so even if you're sure that it's not permissions for the things you've checked, it might be worth doing the following checks:
Does the scheduled task run under the same account as you used when you executed the script manually? Otherwise, try doing a RunAs on the script to run as the same user account as the task, if that works, try scheduling the task as your account.
That way you'll know if it's (task vs manual) or if it's (user1 vs user2). Which might make it a little easier to track down the issue.