#1 03 Dec 2020 17:09

New Member
Registered: 03 Dec 2020
Posts: 1

Error trapping for "The application failed to initialize properly"

I have a relatively simple script set up to read the registry to find the executable for a specified program, concatenate this with up to three parameters, and then execute it via a shell command.  Most times it runs smoothly, but occasionally it gives me a "The application failed to initialize properly" error, code 0xc0000142.  When I am running these scripts in sequence, clicking "OK" on this (the only option available) exits the script and goes on to the next one - oftentimes the exact same script but with the next set of parameters, and usually without any further errors.

I would like to error trap on this and have the script retry instead of failing.  This script is usually used for Excel or Access, but it is only Access that causes these fails, if that is of any help.


dim objShell, WshShell, ProgToFind, FileToCall, Param1, Param2
Set objShell = CreateObject("WScript.Shell")
Set Arg = WScript.Arguments

Set WshShell = WScript.CreateObject("WScript.Shell")

On Error Resume Next

'FileToCall = "S:\blather\GeneralLedger.mdb"
'Parameters = "/x macPrintRebates"

FileToCall = Arg(0)
Param1 = Arg(1)
Param2 = Arg(2)

'WScript.Echo WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" & ProgToFind & "\")
	AppPath = WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" & ProgToFind & "\")
	If Len(AppPath) = 0 Then
		WScript.Echo "App Not Found"
		End If
	CommandStr = Chr(34) & AppPath & Chr(34) & " " & Chr(34) & FileToCall & Chr(34) & " " & Param1 & " " & Param2
	'WScript.Echo CommandStr
	objShell.run CommandStr

'Wait until ProgToFind finishes running before ending script

Dim i
Dim strComputer
strComputer = "."

Do Until colProcessList.count = 0

	Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
	Set colProcessList = objWMIService.ExecQuery ("Select Name from Win32_Process WHERE Name='" & ProgToFind & "'")



'WScript.echo ProgToFind & " finished running"

Set objWMIService = Nothing
Set colProcessList = Nothing


#2 03 Dec 2020 18:57

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 1,103

Re: Error trapping for "The application failed to initialize properly"

Some examples of error handling are here:

I bet the cause is clicktoRun/install, so you may find that just opening and closing Access before doing anything else will be enough to avoid the error.


Board footer

Powered by FluxBB