I have a 32-bit VB6 application that uses Outlook Redemption to send out e-mails. This program has worked fine up to Outlook 2016, but some of my customers are losing the ability to e-mail through my program when they either upgrade to 2019 or get auto-updated on their Office 365 subscription.
A simplified version of my code:
Private Sub cmdSendMessage_Click()
Dim objSession As RDOSession
Dim objOutbox As RDOFolder
Dim objMessage As RDOMail
Dim objRecipient As RDORecipient
Dim strBody As String
100 On Error GoTo ErrorHandler
101 Set objSession = New RDOSession
102 objSession.Logon , , False, False
103 Set objOutbox = objSession.GetDefaultFolder(olFolderOutbox)
104 Set objMessage = objOutbox.Items.Add
105 Set objRecipient = objMessage.Recipients.Add(txtAddressTo.Text)
106 objRecipient.Resolve
107 strBody = "This is a test message--sent using Outlook Redemption." & vbNewLine & vbNewLine & _
"Sent: " & Now & vbNewLine & _
"Sent from Computer: " & GetThisComputerName
109 With objMessage
110 .Subject = "Test Message - Outlook Redemption"
111 .Body = strBody
112 .Send
113 End With 'objMessage
114 objSession.Logoff
115 MsgBox "Message sent.", vbOKOnly + vbInformation
ExitRoutine:
201 Set objRecipient = Nothing
202 Set objMessage = Nothing
203 Set objOutbox = Nothing
204 Set objSession = Nothing
210 Exit Sub
ErrorHandler:
MsgBox "Error " & Err.Number & vbNewLine & vbNewLine & Err.Description & vbNewLine & vbNewLine & _
"Line " & Erl, vbOKOnly + vbCritical, "Error in Execution"
Resume ExitRoutine
End Sub
I tried the program with the code above on a customer's machine running Outlook 2019 MSO (16.0.12527.20260) 32-bit with Windows 10, 1909 (18363.535) 64-bit and 32-bit Outlook Redemption 5.18. The program immediately crashes without an error message when I click the button to send this e-mail.
Does Outlook Redemption work at all with VB6 and the newer versions of Outlook? If so, what do I need to change in my application to make it work?
Two errors appeared in the Application Event Log:
Faulting application name: RedemptionMail.exe, version: 1.0.0.0, time stamp: 0x5b995b5e
Faulting module name: RPCRT4.dll, version: 10.0.18362.476, time stamp: 0x7acb686b
Exception code: 0xc0000005
Fault offset: 0x000461c6
Faulting process id: 0x1660
Faulting application start time: 0x01d60931c9abef20
Faulting application path: \\???\RedemptionMail.exe
Faulting module path: C:\WINDOWS\System32\RPCRT4.dll
Report Id: 916c7e74-a3dd-440c-8759-23806d654b9d
Faulting package full name:
Faulting package-relative application ID:
and
Fault bucket 1285058706613227027, type 1
Event Name: APPCRASH
Response: Not available
Cab Id: 0
Problem signature:
P1: RedemptionMail.exe
P2: 1.0.0.0
P3: 5b995b5e
P4: RPCRT4.dll
P5: 10.0.18362.476
P6: 7acb686b
P7: c0000005
P8: 000461c6
P9:
P10:
Attached files:
\\?\C:\ProgramData\Microsoft\Windows\WER\Temp\WERDE85.tmp.mdmp
\\?\C:\ProgramData\Microsoft\Windows\WER\Temp\WERDEE4.tmp.WERInternalMetadata.xml
\\?\C:\ProgramData\Microsoft\Windows\WER\Temp\WERDEF4.tmp.xml
\\?\C:\ProgramData\Microsoft\Windows\WER\Temp\WERDF04.tmp.csv
\\?\C:\ProgramData\Microsoft\Windows\WER\Temp\WERDF24.tmp.txt
These files may be available here:
\\?\C:\ProgramData\Microsoft\Windows\WER\ReportArchive\AppCrash_RedemptionMail.e_684bbff35d28781a9319f7f96316e4566e7d38f_ae0321e2_6f232be0-f6dd-46d3-bdbf-4f81e08f6760
Analysis symbol:
Rechecking for solution: 0
Report Id: 916c7e74-a3dd-440c-8759-23806d654b9d
Report Status: 268435456
Hashed bucket: ca938f3d4eba0c8bd1d57215cb344e13
Cab Guid: 0
Related
I have a PDFCreator script I compiled in PrimalScript so that I could execute it via svrany and the problem I am running into is the fact that when I run the service the print jobs from the script are never seen by the queue. If I run the vbscript or the compiled exe from my session it works fine.
Here is the code in my vbs file that runs against pdfcreator version 2.1.1.820
Dim strExt, intStatus, strDestFileName, strInputFileName, strReason
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")
Set PDFCreatorQueue = CreateObject("PDFCreatorBeta.JobQueue")
strInputFileName = "C:\Temp\Test.txt"
strDestFileName = "C:\Temp\Test.pdf"
PDFProcess
' ** Sub Routine to render file as PDF
Sub PDFProcess
Dim objFolder, job, intStatPDFCreator, intPageCount
intPageCount = 1
WScript.Echo "PDF Destination Name: " & strDestFile
WScript.Echo "Initializing PDFCreator queue..."
intStatPDFCreator = PDFCreatorQueue.Initialize()
WScript.Echo "PDFCreator Object Status: " & intStatPDFCreator
If intStatPDFCreator = 0 Then
If Not objFSO.FileExists(strInputFileName) Then
WScript.Echo "PDFCreator: Can't find the file: " & strInputFileName
Else
WScript.Echo "Printing Page: " & strInputFileName
objShell.ShellExecute strInputFileName, "", "", "print"
WScript.Sleep 1000
WScript.Echo "Currently there are " & PDFCreatorQueue.Count & " job(s) in the queue"
End If
WScript.Echo "Waiting for the job to arrive at the queue..."
if Not(PDFCreatorQueue.WaitForJobs(intPageCount, 10)) Then
strReason = "The print job did not reach the queue within " & 10 & " seconds"
WScript.Echo strReason
intStatus = 0
Else
WScript.Echo "Currently there are " & PDFCreatorQueue.Count & " job(s) in the queue"
WScript.Echo "Getting job instance and merging"
PDFCreatorQueue.MergeAllJobs
while(PDFCreatorQueue.Count > 0)
Set job = PDFCreatorQueue.NextJob
WScript.Echo "Staging PDF File: " & strDestFileName
job.ConvertTo(strDestFileName)
WScript.sleep 5000
If Not(job.IsFinished Or job.IsSuccessful) Then
strReason = "Could not convert the file: " & strDestFileName
WScript.Echo strReason
intStatus = 0
Else
WScript.Echo "Job finished successfully"
End If
Wend
End If
WScript.Echo "Releasing the object"
PDFCreatorQueue.ReleaseCom()
Else
strReason = "Failed to create PDFCreator COM instance."
WScript.Echo strReason
intStatus = 0
End If
End Sub
The service I have running under my domain credentials and have modified the registry to allow it to run interactively
SERVICE_NAME: tgprintprocessor
TYPE : 110 WIN32_OWN_PROCESS (interactive)
STATE : 4 RUNNING
(STOPPABLE, PAUSABLE, ACCEPTS_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
PID : 3752
FLAGS :
I have set interactive Services Detection to a running state.
reviewing the PDFCreator trace log I don't see any errors of any kind.
If I open PDFCreator printer and view the print queue, I do see the job hit the queue and exit, and can even pause the printer so the job stops in the printer queue but the com object queue is oblivious to its existence.
I also tried running PDFCreator.exe additionally as a service incase it needed to have an instance of the exe running in the background as I noticed the application itself does not fire up in task manager post print job submission like I typically see when executing the script manually.
What is my question, I guess I don't know where else to look and if there is maybe something I am missing that I can add to the above test script to attempt trapping the problem.
Resolution to this issue and behavior above is to change the driver isolation mode from the default NONE, to SHARED. I did this under Print Management Snapin. Took a while to figure it out....
If you are using WScript it will stop at the first wscript.echo. Make sure you are running with CScript.
I use this vbscript code, to download web page:
Dim oXML
Set oXML = CreateObject("msxm12.XMLHTTP")
oXML.Open "GET", "mysite.com", False
oXML.Send
If there is no such web site, I get an error 80004005, Unspecified error at line "oXML.Open ..."
How can I handle this error in vbscript? I want to catch this error and show msgbox with my error, i.e. web page is not available.
There are at least three possible points of failure in your script.
CreateObject may fail; e.g. if you use msxml12 (digit 1) instead of msxml2 (letter l). Such blunders should be fixed during development.
.Open may fail; e.g. if you use "mysite.com" instead of a syntactically correct URL. If you get the URL at runtime, a 'look before you jump' check is advisable, an OERN can be used to catch bad URLs not found by your validation.
.Send may fail; e.g. if the site is down or abandoned. This is a clear case for an OERN.
The most important rule wrt OERN: Keep it local and short (Only one risky line between OERN and OEG0).
Demo code:
Option Explicit
Dim sUrl
For Each sUrl In Split("http://stackoverflow.com http://pipapo.org mysite.com")
Dim oXML, aErr
' Set oXML = CreateObject("msxm12.XMLHTTP")
Set oXML = CreateObject("msxml2.XMLHTTP.6.0")
On Error Resume Next
oXML.Open "GET", sUrl, False
aErr = Array(Err.Number, Err.Description)
On Error GoTo 0
If 0 = aErr(0) Then
On Error Resume Next
oXML.Send
aErr = Array(Err.Number, Err.Description)
On Error GoTo 0
Select Case True
Case 0 <> aErr(0)
WScript.Echo "send failed:", aErr(0), aErr(1)
Case 200 = oXML.status
WScript.Echo sUrl, oXML.status, oXML.statusText
Case Else
WScript.Echo "further work needed:"
WScript.Echo sUrl, oXML.status, oXML.statusText
End Select
Else
WScript.Echo "open failed:", aErr(0), aErr(1)
End If
Next
output:
cscript 24863986.vbs
http://stackoverflow.com 200 OK
send failed: -2146697211 The system cannot locate the resource specified.
open failed: -2147012890 System error: -2147012890.
But your problem is it's msxml2.http (El 2) not msxm12.http (1 2). Yopur error is because you dd not create the object sucessfully or test the object isn't empty.
The URL has to be 100% correct. Unlike a browser there is no code to fix urls.
The purpose of my program is to get error details.
How I get a correct URL is to type my url in a browser, navigate, and the correct URL is often in the address bar. The other way is to use Properties of a link etc to get the URL.
Also Microsoft.XMLHTTP maps to Microsoft.XMLHTTP.1.0. HKEY_CLASSES_ROOT\Msxml2.XMLHTTP maps to Msxml2.XMLHTTP.3.0. Try a later one
Try this way using xmlhttp. Edit the url's etc. If it seems to work comment out the if / end if to dump info even if seeming to work. It's vbscript but vbscript works in vb6.
On Error Resume Next
Set File = WScript.CreateObject("Microsoft.XMLHTTP")
File.Open "GET", "http://www.microsoft.com/en-au/default.aspx", False
'This is IE 8 headers
File.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 1.1.4322; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C; .NET4.0E; BCD2000; BCD2000)"
File.Send
If err.number <> 0 then
line =""
Line = Line & vbcrlf & ""
Line = Line & vbcrlf & "Error getting file"
Line = Line & vbcrlf & "=================="
Line = Line & vbcrlf & ""
Line = Line & vbcrlf & "Error " & err.number & "(0x" & hex(err.number) & ") " & err.description
Line = Line & vbcrlf & "Source " & err.source
Line = Line & vbcrlf & ""
Line = Line & vbcrlf & "HTTP Error " & File.Status & " " & File.StatusText
Line = Line & vbcrlf & File.getAllResponseHeaders
wscript.echo Line
Err.clear
wscript.quit
End If
On Error Goto 0
Set BS = CreateObject("ADODB.Stream")
BS.type = 1
BS.open
BS.Write File.ResponseBody
BS.SaveToFile "c:\users\test.txt", 2
Also see if these other objects work.
C:\Users>reg query hkcr /f xmlhttp
HKEY_CLASSES_ROOT\Microsoft.XMLHTTP
HKEY_CLASSES_ROOT\Microsoft.XMLHTTP.1.0
HKEY_CLASSES_ROOT\Msxml2.ServerXMLHTTP
HKEY_CLASSES_ROOT\Msxml2.ServerXMLHTTP.3.0
HKEY_CLASSES_ROOT\Msxml2.ServerXMLHTTP.4.0
HKEY_CLASSES_ROOT\Msxml2.ServerXMLHTTP.5.0
HKEY_CLASSES_ROOT\Msxml2.ServerXMLHTTP.6.0
HKEY_CLASSES_ROOT\Msxml2.XMLHTTP
HKEY_CLASSES_ROOT\Msxml2.XMLHTTP.3.0
HKEY_CLASSES_ROOT\Msxml2.XMLHTTP.4.0
HKEY_CLASSES_ROOT\Msxml2.XMLHTTP.5.0
HKEY_CLASSES_ROOT\Msxml2.XMLHTTP.6.0
End of search: 12 match(es) found.
Also be aware there is a limit on how many times you can call any particular XMLHTTP object before a lockout occurs. If that happens, and it does when debugging code, just change to a different xmlhttp object
We have an ancient VB6 component that needs Google Analytics tracking. I am using the Internet Transfer Control to POST data via HTTP. I cannot see my tracking data in the Google Analytics reports. This leads me to believe that I cam calling POST incorrectly.
I have already added Google Analytics tracking to a desktop .Net Application and can see that data so I know it works.
I have a VB6 form with a button on it. The button-click event executes:
Dim var1 As String
var1 = "v=1&tid=UA-00000000-1&cid=123&t=appview&cd=VBScreen"
Inet1.Execute "http://www.google-analytics.com/collect", "POST", var1
This doesn't return an error but no data can be seen in the Google Analytics reporting pages. What am I going wrong?
I do not need to use the Internet Transfer Control if there is some other simple way to do this.
After Execute() is called, Inet1_StateChanged is fired and the state is icResponseCompleted. Inet1.ResponseInfo == "" and Inet1.StillExecuting == False.
Try this way using xmlhttp. Edit the url's etc. If it seems to work comment out the if / end if to dump info even if seeming to work. It's vbscript but vbscript works in vb6.
On Error Resume Next
Set File = WScript.CreateObject("Microsoft.XMLHTTP")
File.Open "GET", "http://www.microsoft.com/en-au/default.aspx", False
'This is IE 8 headers
File.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 1.1.4322; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C; .NET4.0E; BCD2000; BCD2000)"
File.Send
If err.number <> 0 then
line =""
Line = Line & vbcrlf & ""
Line = Line & vbcrlf & "Error getting file"
Line = Line & vbcrlf & "=================="
Line = Line & vbcrlf & ""
Line = Line & vbcrlf & "Error " & err.number & "(0x" & hex(err.number) & ") " & err.description
Line = Line & vbcrlf & "Source " & err.source
Line = Line & vbcrlf & ""
Line = Line & vbcrlf & "HTTP Error " & File.Status & " " & File.StatusText
Line = Line & vbcrlf & File.getAllResponseHeaders
wscript.echo Line
Err.clear
wscript.quit
End If
On Error Goto 0
Set BS = CreateObject("ADODB.Stream")
BS.type = 1
BS.open
BS.Write File.ResponseBody
BS.SaveToFile "c:\users\test.txt", 2
I don't recall why the original code did not work, but I was able to get it working with the following code:
Dim xmlhttp As WinHttp.WinHttpRequest
Set xmlhttp = New WinHttp.WinHttpRequest
Dim var1 As String
var1 = "v=1&tid=UA-00000000-0&cid=123&an=MyAN&av=1.0&t=event&ec=ecData&ea=eaData&el=elData"
xmlhttp.Open "POST", "http://www.google-analytics.com/collect", False
xmlhttp.send var1
I'm a relatively inexperienced coder and I've been running into an issue with getting the physical disk serial number remotely via a VBScript.
Currently I'm using the default script in Scriptomatic V2, by the Scripting Guys. I'm running it from a 2003 Server and trying to get info from Win2000 and WinXP SP2/SP3 systems. I've seen from a couple tutorials that the WMI class recommended is Win32_PhysicalMedia.
Including the useful bits:
On Error Resume Next
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
arrComputers = Array("STN_XP","STN_2000")
For Each strComputer In arrComputers
WScript.Echo
WScript.Echo "=========================================="
WScript.Echo "Computer: " & strComputer
WScript.Echo "=========================================="
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PhysicalMedia", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
'(Removed a couple from the code, just showing the useful ones)
WScript.Echo "Model: " & objItem.Model
WScript.Echo "Name: " & objItem.Name
WScript.Echo "SerialNumber: " & objItem.SerialNumber
WScript.Echo "Tag: " & objItem.Tag
WScript.Echo
Next
Next
Now the output I get is below: Note this is the exact output from running the script with all calls; no data is returned beyond the objItem.Tag value:
==========================================
Computer: STN_XP
==========================================
Capacity:
Caption:
CleanerMedia:
CreationClassName:
Description:
HotSwappable:
Manufacturer:
MediaDescription:
MediaType:
Model:
Name:
OtherIdentifyingInfo:
PartNumber:
PoweredOn:
Removable:
Replaceable:
SerialNumber:
SKU:
Status:
Tag: \\.\PHYSICALDRIVE0
Version:
WriteProtectOn:
==========================================
Computer: STN_2000
==========================================
All computers are connected to a domain, I'm logged in to the primary admin account. Using some of the other WMI libraries, I get data, and on one specific computer so far I've received a serial number (and tag, but nothing else). I've read up on this being an issue for Vista, where you are required to run in admin mode. This shouldn't be an issue here, due to the OSes in use. Anyone know what might be wrong?
As a follow-up question, does anyone know how to get the Serial Number from a 2000 station?
Thanks in advance for any help you can give me.
Comment out the On Error Resume Next with a single quote, and post the error message that is likely being returned.
I'm trying to handle Winsock_Connect event (Actually I need it in Excel macro) using the following code:
Dim Winsock1 As Winsock 'Object type definition
Sub Init()
Set Winsock1 = CreateObject("MSWinsock.Winsock") 'Object initialization
Winsock1.RemoteHost = "MyHost"
Winsock1.RemotePort = "22"
Winsock1.Connect
Do While (Winsock1.State <> sckConnected)
Sleep 200
Loop
End Sub
'Callback handler
Private Sub Winsock1_Connect()
MsgBox "Winsock1::Connect"
End Sub
But it never goes to Winsock1_Connect subroutine although Winsock1.State is "Connected".
I want to use standard MS library because I don't have administrative rights on my PC and I'm not able to register some custom libraries.
Can anybody tell me, where I'm wrong?
Are you stuck using MSWinsock?
Here is a site/tutorial using a custom winsock object.
Also... You need to declare Winsock1 WithEvents within a "Class" module:
Private WithEvents Winsock1 As Winsock
And finally, make sure you reference the winsock ocx control.
Tools -> References -> Browse -> %SYSEM%\MSWINSCK.OCX
Documentation about Winsock Control:
http://msdn.microsoft.com/en-us/library/aa228119%28v=vs.60%29.aspx
Example here:
http://support.microsoft.com/kb/163999/en-us
My short example with event handling in VBscript:
Dim sock
Set sock = WScript.CreateObject("MSWinsock.Winsock","sock_")
sock.RemoteHost = "www.yandex.com"
sock.RemotePort = "80"
sock.Connect
Dim received
received = 0
Sub sock_Connect()
WScript.Echo "[sock] Connection Successful!"
sock.SendData "GET / HTTP/1.1"& vbCrLf & "Host: " & sock.RemoteHost & vbCrLf & vbCrLf
End Sub
Sub sock_Close()
WScript.Echo "[sock] Connection closed!"
End Sub
Sub sock_DataArrival(Byval b)
Dim data
sock.GetData data, vbString
received = received + b
WScript.Echo "---------------------------------------"
WScript.Echo " Bytes received: " & b & " ( Total: " & received & " )"
WScript.Echo "---------------------------------------"
WScript.Echo data
End Sub
'Wait for server close connection
Do While sock.State <> 8
rem WScript.Echo sock.State
WScript.Sleep 1000
Loop
Output will be:
cscript /nologo sockhttp.vbs
[sock] Connection Successful!
-------------------------------
Bytes received: 1376 ( Total: 1376 )
-------------------------------
HTTP/1.1 200 Ok
Date: Mon, 08 Dec 2014 15:41:36 GMT
Content-Type: text/html; charset=UTF-8
Cache-Control: no-cache,no-store,max-age=0,must-revalidate
Expires: Mon, 08 Dec 2014 15:41:36 GMT
...