Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with openprocess function

Status
Not open for further replies.

Pistol34

MIS
Nov 17, 1999
55
US
I have almost never used the API before. I am tring to close a self-extracting zip file. I call the syncshell function and then wait for it to finish unzipping. When it is done I want to close the dos shell and move to the next file. I recieved some code from a previous post. I am just not sure if I am using it correctly. I have also noticed that the open process function is returning 0 and the If statement is not running. I think this is because I am using synchronized access on a windows 98 workstaion. What should I use?
Here is the code I am using:

Public Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long)

Public Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessID As Long) As Long

Public Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long

Public Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hProcess As Long, _
ByVal dwMilliseconds As Long) As Long

'---------------- global constants -------
Global Const INFINITE = &HFFFFFFFF
Global Const SYNCHRONIZED = &H100000

Public Sub SyncShell(ByVal sql As String, _
Optional ByVal vbwindowmode As VbAppWinStyle = vbMinimizedFocus)
Dim pid As Long
Dim phnd As Long
pid = Shell(sql)
If pid <> 0 Then
phnd = OpenProcess(SYNCHRONIZED, 0, pid)
If phnd <> 0 Then
DoEvents
WaitForSingleObject phnd, INFINITE
CloseHandle phnd
DoEvents
End If
End If
End Sub
 
there's a FAQ on the subject in the vg gen forum which might help you, i'll post the ref below

i saw the other post, interesting approach.. I'm going to be trying it out and incorporating it if the poster is ok with that
Mike
michael.j.lacey@ntlworld.com
 
faq222-32 it's kb44's faq actually, thought it was mine for some reason (doh!)
Mike
michael.j.lacey@ntlworld.com
 
I have read these faqs. The problem is that the functions don't see the process as ending until the DOS shell is closed. So if the exe runs but the shell stays open then the process has not actually finished.
 
ok......

karl -- are you following this thread?
Mike
michael.j.lacey@ntlworld.com
 
The FAQ I posted, is intended for 32bit, he complains about 16bit, he could goto pkware and download the console-only version which could still act as 32bit native when made into a sfx, (which is what I do for my installer, I use their console version, to make an Sfx, then use the program to call it then wait on it) I'll show you the function I wrote, so I could just pass it a command to execute then return, (just be sure to use the API declarations in the FAQ.


Code:
Public Function ExecCmd(cmdline$, curFolder$)
      Dim proc As PROCESS_INFORMATION
      Dim start As STARTUPINFO
      Dim ret As Long

      start.cb = Len(start)
      
      ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
         CREATE_NEW_CONSOLE, 0&, curFolder$, start, proc)

         ret& = WaitForSingleObject(proc.hProcess, INFINITE)
         Call GetExitCodeProcess(proc.hProcess, ret&)
         Call CloseHandle(proc.hThread)
         Call CloseHandle(proc.hProcess)
         ExecCmd = ret&
  End Function

to call this:

Code:
rt = ExecCmd(WebServer & SarasRoot & InstallFile & &quot; -directories&quot;, WebServer & SarasRoot)

basically thats what I use above to execute my Sfx with the parameter to extract with directories.

rt = ExecCmd(Command to Execute, Working Directory)

if rt returns less than zero, your executable either wasnt started or not found.
Karl
kb244@kb244.com
Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top