|
-
Jul 21st, 2005, 10:51 AM
#1
Thread Starter
New Member
Unable to open Shell process handle
In Excel I have a button that when I click it shell's out to a .exe file someone else made. I used the API function ShellExecute because I wanted to specify parameters.
I want to wait until the .exe file is done running until I continue on with my code. So I have been trying to use OpenProcess and GetExitCodeProcess API functions. The problem is whenever I try to get the .exe file's process handle it comes back as 0. I am not sure what the problem is. Any ideas would be greatly appreciated.
Thanks!
-
Jul 21st, 2005, 11:44 AM
#2
Re: Unable to open Shell process handle
You may also use the WaitForSingleObject API to do this, but post your code and lets see what may be going on.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 21st, 2005, 01:20 PM
#3
Thread Starter
New Member
Re: Unable to open Shell process handle
Here is my code...
VB Code:
Function RunRe_Synch() As Boolean
Dim lTaskID As Long
Dim lProcess As Long
Dim lExitCode As Long
Dim lResult As Long
Dim File, Operation, Parameters, Directory As String
File = "C:\ReSynch\WorksetVersion\executable\Re_Synch.exe"
Operation = "Open"
Parameters = "C:\ReSynch\WorksetVersion\executable\"
Directory = "C:\ReSynch\WorksetVersion\executable\"
'Run the Shell Function
lTaskID = ShellExecute(Application.hwnd, Operation, File, Parameters, Directory, 1)
'Check for errors.
If lTaskID = 0 Then MsgBox ("Shell function error.")
'Get the process handle from the task ID returned by Shell.
lProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0&, lTaskID)
'Check for errors.
If lProcess = 0 Then MsgBox ("Unable to open Shell process handle.")
'Loop while the shelled process is still running.
Do
'ExitCode will be set to STILL_ACTIVE as long as the shelled process is running.
lResult = GetExitCodeProcess(lProcess, lExitCode)
DoEvents
Loop While lExitCode = STILL_ACTIVE
RunRe_Synch = True
End Function
The error catches arn't done... I just have message boxes popping up now. The problem I have is that my lProcess equals 0 everytime I run my program.
-
Jul 21st, 2005, 01:31 PM
#4
Re: Unable to open Shell process handle
The lTaskID being returned from ShellExecute is not really the process id.
Return Values
If the function succeeds, the return value is the instance handle of the application that was run.
If the function fails, the return value is an error value that is less than or equal to 32.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|