获取“远程服务器机器不存在或不可用"在 Outlook VBScript 中 [英] Getting "Remote server machine does not exist or not available" in Outlook VBScript
问题描述
我在 Outlook VBScript 上写过,它从 Outlook 下载附件.但是现在我遇到了一个错误
I have written on Outlook VBScript which downloads the attachment from Outlook. But now I am encountering an error
远程服务器机器不存在或不可用
Remote Server machine does not exist or is unavailable
我多次收到此错误,有时此代码运行时没有任何错误.我能够跟踪确切的故障点.线是
I get this error a few time and also sometimes this code runs without any error. I was able to track the exact point of failure. The line is
Set olns = olApp.GetNameSpace("MAPI")
我几乎尝试了所有方法,但我无法找到解决方案.
I have almost tried everything yet I am not able to to find the solution.
Set Arg = WScript.Arguments
Dim item1
Dim objsubject
Dim intcount
Dim i
Dim savename
Dim vTextFile
Dim filename
Dim extension
Dim t
Dim Itimestamp
Dim savefolder
Dim vSenderEmailAddress
Dim vFlagTextFileCreate
vFlagTextFileCreate = True
savefolder = "C:\Users\SANxSAxAABOTDEV\Documents\Automation Anywhere Files\Automation Anywhere\My Tasks\ThrdOutlookTest"
vTextFile = savefolder & "\File Report.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If Err.Number <> 0 Then 'Could not get instance of Outlook, so create a new one
Err.Clear
Set olApp = CreateObject("Outlook.Application")
End If
On Error Goto 0
Set olns = olApp.GetNameSpace("MAPI")
olns.Logon "Outlook", , False, True
Set objFolder = olns.GetDefaultFolder(6)
'objFolder.InAppFolderSyncObject = True
'syc.Start
For Each item1 In objFolder.Items
If item1.Unread = True Then
objsubject = item1.Subject
If InStr(UCase(objsubject) ,"RPA BOT") Then
intCount = item1.Attachments.Count
If intcount > 0 Then
For i = 1 To intcount
If InStr(item1.Attachments(i).filename, ".xls") Then
t = Now()
'Adding timestamp to the file to make it unique
Itimestamp = Right("0" & Hour(t), 2) & _
Right("0" & Minute(t), 2) & _
Right("0" & Second(t), 2)
fileName = Left(item1.Attachments(i).filename, InStr(item1.Attachments(i).filename, ".xl") - 1)
extension = Right(item1.Attachments(i).filename, Len(item1.Attachments(i).filename) - InStr(item1.Attachments(i).filename, ".xl"))
savename = saveFolder & "\" & fileName & "_" & Itimestamp & "." & extension
item1.Attachments(i).SaveAsFile savename
WScript.Sleep 1000
If item1.SenderEmailType = "SMTP" Then
vSenderEmailAddress = item1.SenderEmailAddress
ElseIf item1.SenderEmailType = "EX" Then
vSenderEmailAddress = item1.Sender.GetExchangeUser.PrimarySmtpAddress
End If 'If item1.SenderEmailType
'Create InfoFile If does not exist
If vFlagTextFileCreate = True Then
vFlagTextFileCreate = False
fso.CreateTextFile vTextFile
End If
Set ts = fso.OpenTextFile(vTextFile, 8, True, 0)
ts.WriteLine fileName & "_" & Itimestamp & "." & extension & "|" & item1.Subject & "|" & vSenderEmailAddress & vbLf
ts.Close
End If 'If InStr(item1.Attachments(i).filename
Next
'Turning the unread mail to read
item1.Unread = False
End If 'If intcount > 0 Then
End If 'If Instr(objsubject ,
End If 'If item1.Unread=True
Next
olns.Logoff
Set olns = Nothing
Set olApp = Nothing
WScript.Quit
我做了一些研究,发现这个问题可能是因为在运行脚本之前已经打开了 Outlook 会话.所以我在 Set fso = CreateObject("Scripting.FileSystemObject")
之前添加了一个补丁来杀死所有的 outlook.exe
会话.我有一段时间没有收到任何错误.我不知道这是否正确.我很高兴知道您对此的反馈.
I did some research and came to know that this issue may be caused due to the fact that the outlook session is already opened before running the script. So I added a patch before Set fso = CreateObject("Scripting.FileSystemObject")
to kill all the outlook.exe
session. I did not get any error for a while. I don't know if this is correct. I would be happy to know your feedback on this.
推荐答案
在我为 Outlook.Application 创建对象之前终止 Outlook.exe 会话解决了我的错误.我在 Set fso = CreateObject("Scripting.FileSystemObject") 之前添加了一个补丁来终止 Outlook.exe 会话.下面是补丁
Killing the outlook.exe session before I create the object for Outlook.Application solved my error. I added a patch before Set fso = CreateObject("Scripting.FileSystemObject") to kill outlook.exe sessions. Below is the patch
strComputer = "."
Set Arg = WScript.Arguments
Process = "outlook.exe"
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name like '" & Process & "%'")
For Each p in colProcess
On Error Resume Next
p.Terminate
On Error GoTo 0
Next
SET objWMIService = Nothing
SET colProcess = Nothing
这篇关于获取“远程服务器机器不存在或不可用"在 Outlook VBScript 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!