Anthrax
Posts: 19
Joined: Tue Jul 31, 2007 1:51 pm

Return Codes in VBScript

Hi,

in my custom action i have to return a return code if something in the script fails.
I want to return 0 if all is ok and return 1 if sth. faisl.
But i don't know how to accomplish this, because wscript.quit(1) or wsript.quit 1 won't work.
Can somebody help me with returning return codes from a custom action?

kind regards

Anthrax
canhuth
Posts: 241
Joined: Thu Jun 19, 2008 9:03 am

Re: Return Codes in VBScript

Hello Anthrax,

maybe this is useful:

"Return Values of JScript and VBScript Custom Actions":

http://msdn.microsoft.com/en-us/library ... S.85).aspx

(URL hopefully fixed now. Odd that the link detection screwed it up. :/)



With best regards

Clemens Anhuth
Last edited by canhuth on Tue Jul 29, 2008 10:44 am, edited 1 time in total.
Anthrax
Posts: 19
Joined: Tue Jul 31, 2007 1:51 pm

Re: Return Codes in VBScript

That is exactly what i need.
Thank you very much.

Anthrax
jidjan
Posts: 7
Joined: Thu Jul 24, 2008 7:54 pm

Re: Return Codes in VBScript

Anthrax wrote:That is exactly what i need.
Thank you very much.

Anthrax
Hi Anthrax,

The link on Clemens reply, did it work for you? I am having similar problem with the wscript.quit, do you have a sample vbscript?


Thanks,
Jidjan
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Return Codes in VBScript

Hi,

Please note that the link doesn't work if you click on it, you need to copy it into a web browser. Or you can click here. Note that the MSDN article to which the link points contains a sample script.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
jidjan
Posts: 7
Joined: Thu Jul 24, 2008 7:54 pm

Re: Return Codes in VBScript

Hi Cosmin,

I think I am misqouted, what I mean is, on the sample script from the link how did he apply Anthrax apply it on the script as an alternative to the wscript.quit. Any help is really appreciated.

Thanks,
Jeffrey
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Return Codes in VBScript

Hi,

Please note that this is explained in the article to which the link points:

"To return a value other than success from a script custom action, you must use a function target for the custom action. ... The following script example shows you how to return success or failure from a VBScript custom action."

Code: Select all

Function MyVBScriptCA()

	If Session.Property("CustomErrorStatus") <> "0" Then
		'return error
		MyVBScriptCA = 3
		Exit Function
	End If

	' return success
	MyVBScriptCA = 1
	Exit Function

End Function
Basically, you need to write a function in your custom action. This function will execute the code you want and it will be set to an integer value which means something:
0 -- Action not executed
1 -- Action completed successfully.
2 -- Premature termination by user.
3 -- Unrecoverable error. Returned if there is an error during parsing or execution of the Jscript or VBScript.
4 -- Suspended sequence to be resumed later.
5 -- Skip remaining actions. Not an error.

For the above example, the function MyVBScriptCA is set to 3 in case of an error and to 1 in case of success.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
jidjan
Posts: 7
Joined: Thu Jul 24, 2008 7:54 pm

Re: Return Codes in VBScript

Hi Cosmin,

I am not really a scripting guy and this is what I am trying to do. My test.vbs runs a batch file and that batch files creates a log file. On the log file there is a line "Return value = XX". Now, after my test.vbs runs batch files, I took the XX from the log file. How am I going to use the function from the link so that if my XX is not 0 it will abort? Do I have to do this?


Function MyVBScriptCA()

run the batch file
read/get XX from the log file and save it as StrData

.........what is next?

If Session.Property("CustomErrorStatus") <> "0" Then
'return error
MyVBScriptCA = 3
Exit Function
End If

' return success
MyVBScriptCA = 1
Exit Function

End Function


Thanks,
Jeffrey
jidjan
Posts: 7
Joined: Thu Jul 24, 2008 7:54 pm

Re: Return Codes in VBScript

Hi,

I think I figured it out.

Thanks,
Jeffrey
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Return Codes in VBScript

Hi Jeffrey,
run the batch file
read/get XX from the log file and save it as StrData
.........what is next?
The return code of the BAT file can be evaluated inside your custom action. After it is evaluated, you can set the return code of the actual custom action. For example:

Code: Select all

if StrData <> 0 then
   MyVBScriptCA = 3
   Exit Function
end if

MyVBScriptCA = 1
Exit Function
where MyVBScriptCA is the main function of your custom action (the one which is called by the installation).
Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
jidjan
Posts: 7
Joined: Thu Jul 24, 2008 7:54 pm

Re: Return Codes in VBScript

Hi Cosmin,

Actually I have three conditions and what I did is simlar to what you did. With this my msi seems to work now. Thank you Anthrax for posting this, clemens for showing us the link, and to you cosmin.


Regards,
Jeffrey

Return to “Common Problems”