Home > Archive > Visual Basic Syntax > July 2005 > How can VB6 Exe exit with a Return Code
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How can VB6 Exe exit with a Return Code
|
|
| Todd M 2005-07-27, 10:02 pm |
| I want to run a VB6 Exe using Windows Scripting Host. I need to determine if
the VB6 Exe ran successfully or failed with an error. I'm using the
following VB Script to run the Exe:
Dim liReturnCode
Dim loShell
'Run Executable
Set loShell = WScript.CreateObject("WScript.Shell")
liReturnCode = loShell.Run("myVB6Prog.exe, 1 , True)
I want the VB6 Exe to Return 0 for success and a non-zero number for failure.
I tried using Err.Raise to raise an error that I did not catch. That didn't
work.
Can anyone tell me how to do this?
Thanks
Todd M
| |
| alpine 2005-07-28, 4:03 am |
| On Wed, 27 Jul 2005 18:44:01 -0700, Todd M
<ToddM@discussions.microsoft.com> wrote:
>I want to run a VB6 Exe using Windows Scripting Host. I need to determine if
>the VB6 Exe ran successfully or failed with an error. I'm using the
>following VB Script to run the Exe:
>
>Dim liReturnCode
>Dim loShell
>
>
>'Run Executable
>Set loShell = WScript.CreateObject("WScript.Shell")
>liReturnCode = loShell.Run("myVB6Prog.exe, 1 , True)
>
>I want the VB6 Exe to Return 0 for success and a non-zero number for failure.
>
>I tried using Err.Raise to raise an error that I did not catch. That didn't
>work.
>
>Can anyone tell me how to do this?
>
>Thanks
>
>Todd M
Search the Google archives for "ExitProcess vb -.net". Note the
caveats in many of the posts.
http://groups.google.com/advanced_group_search
HTH,
Bryan
________________________________________
____________________
New Vision Software "When the going gets weird,"
Bryan Stafford "the weird turn pro."
alpine_don'tsendspam@mvps.org Hunter S. Thompson -
Microsoft MVP-Visual Basic Fear and Loathing in LasVegas
| |
| Todd M 2005-07-28, 5:04 pm |
| After searching on ExitProcess I found the following MSDN Knowledge Base
Article:
http://support.microsoft.com/kb/q288216/
Based on that article I understand that Microsoft does not recommend using
ExitProcess from a VB6 Exe (see article for details). I also understand that
ExitProcess is the only way for VB6 to return an Error Code that can be
interpreted by Windows Scripting Host.
My work around will be to have the VB6 Exe write to a file and use that file
to determine success of failure.
Thanks
"Todd M" wrote:
> I want to run a VB6 Exe using Windows Scripting Host. I need to determine if
> the VB6 Exe ran successfully or failed with an error. I'm using the
> following VB Script to run the Exe:
>
> Dim liReturnCode
> Dim loShell
>
>
> 'Run Executable
> Set loShell = WScript.CreateObject("WScript.Shell")
> liReturnCode = loShell.Run("myVB6Prog.exe, 1 , True)
>
> I want the VB6 Exe to Return 0 for success and a non-zero number for failure.
>
> I tried using Err.Raise to raise an error that I did not catch. That didn't
> work.
>
> Can anyone tell me how to do this?
>
> Thanks
>
> Todd M
>
>
| |
| Karl E. Peterson 2005-07-28, 5:04 pm |
| Todd M wrote:
> After searching on ExitProcess I found the following MSDN Knowledge
> Base Article:
>
> http://support.microsoft.com/kb/q288216/
>
> Based on that article I understand that Microsoft does not recommend
> using ExitProcess from a VB6 Exe (see article for details). I also
> understand that ExitProcess is the only way for VB6 to return an
> Error Code that can be interpreted by Windows Scripting Host.
>
> My work around will be to have the VB6 Exe write to a file and use
> that file to determine success of failure.
As Bryan advised, you'd be far better off taking advantage of the previous advice
offered in this forum than the KB. That article is unnecessarily pessimistic. You
*can* call ExitProcess, quite safely, but you *must* be aware of wth you're doing.
For example, the access violation they speak of can/will occur if you compile to
pcode, rather than native. Other than that, the other big red flag warnings you'll
find are to make the call to ExitProcess as the last executable statement in Sub Main
(preferably, only from an EXE, not within the IDE <g> ). If you do that, and you've
properly disposed of any global objects you've created, you'll be just fine. See:
http://vb.mvps.org/samples/Hello
http://vb.mvps.org/articles/ap200103.asp
Later... Karl
--
Working Without a .NET?
http://classicvb.org/petition
|
|
|
|
|