Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2006

Tip: Looking for answers? Try searching our database.

Problem getting exit code returned by DOS command

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pkirow - 30 Oct 2006 14:33 GMT
Hi folks,

When I try to invoke MS-DOS programm from VB, the exit code return is aways
0.
My code is:

 Option Explicit
 
  Private Type STARTUPINFO
     cb As Long
     lpReserved As String
     lpDesktop As String
     lpTitle As String
     dwX As Long
     dwY As Long
     dwXSize As Long
     dwYSize As Long
     dwXCountChars As Long
     dwYCountChars As Long
     dwFillAttribute As Long
     dwFlags As Long
     wShowWindow As Integer
     cbReserved2 As Integer
     lpReserved2 As Long
     hStdInput As Long
     hStdOutput As Long
     hStdError As Long
  End Type

  Private Type PROCESS_INFORMATION
     hProcess As Long
     hThread As Long
     dwProcessId As Long
     dwThreadID As Long
  End Type

  Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
     hHandle As Long, ByVal dwMilliseconds As Long) As Long

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess
As Long, _
   ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
 
  Private Declare Function GetExitCodeProcess Lib "kernel32" _
     (ByVal hProcess As Long, lpExitCode As Long) As Long

  Public Function ExecCmd(cmdline$)
     Dim proc As PROCESS_INFORMATION
     Dim start As STARTUPINFO
     Dim procId As Long

     start.cb = Len(start)
   
   procId = Shell(cmdline$, vbNormalFocus)

     proc.hProcess = OpenProcess(ACCESS_TYPE, False, procId)

        Call WaitForSingleObject(proc.hProcess, INFINITE)
        Call GetExitCodeProcess(proc.hProcess, procId)
   
        ExecCmd = procId
  End Function

Private Sub CommandButton1_Click()
    Dim retval As Long
     retval = ExecCmd("java -jar Test.jar abc")
     MsgBox "Process Finished, Exit Code " & retval
End Sub

When I run this command (java -jar Test.jar abc) the exit codes are between
3 and -6.

Any help and/or ideas?

Plamen.
Jonathan West - 30 Oct 2006 14:45 GMT
Hi Plamen,

If you are trying to code a "Shall and Wait" process, there's no need to go
in for wheel-reinvention. Use the code here instead

http://vb.mvps.org/samples/project.asp?id=Shell32

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

> Hi folks,
>
[quoted text clipped - 73 lines]
>
> Plamen.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.