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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CreateProcess calls only from Windows dir 1

Status
Not open for further replies.

tracie

Programmer
Mar 14, 2001
3
US
Hi,

I'm rather new to API calls and am trying to use the CreateProcess call to open an application from within my VB app. I can get it to work just fine by calling a program in the C:\Windows directory (e.g., calc.exe) but of course the application I'm trying to call does not reside there. I don't know how to get CreateProcess to look in another directory (giving the full path did not work).

I'm using VB6 developing on Win98.

Any help would be greatly appreciated!

Tracie
 
This is what I declared in the module:

----------

Public Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type

Public 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

Public Declare Function CreateProcess Lib "kernel32" _
Alias "CreateProcessA" _
(ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, _
lpProcessAttributes As Any, _
lpThreadAttributes As Any, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
lpEnvironment As Any, _
ByVal lpCurrentDriectory As String, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION) As Long

Public Declare Function OpenProcess Lib "kernel32.dll" _
(ByVal dwAccess As Long, _
ByVal fInherit As Integer, _
ByVal hObject As Long) As Long

Public Declare Function TerminateProcess Lib "kernel32" _
(ByVal hProcess As Long, _
ByVal uExitCode As Long) As Long

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

Public Const NORMAL_PRIORITY_CLASS = &H20&
Public Const SYNCHRONIZE = 1048576

-----------
and this is what is behind the button to call the other application:

-----------

Dim pInfo As PROCESS_INFORMATION
Dim sInfo As STARTUPINFO
Dim sNull As String
Dim lSuccess As Long
Dim lRetValue As Long

sInfo.cb = Len(sInfo)
lSuccess = CreateProcess(sNull, _
"Clipbrd.exe", _
ByVal 0&, _
ByVal 0&, _
1&, _
NORMAL_PRIORITY_CLASS, _
ByVal 0&, _
sNull, _
sInfo, _
pInfo)

MsgBox "Program has been launched!"

lRetValue = TerminateProcess(pInfo.hProcess, 0&)
lRetValue = CloseHandle(pInfo.hThread)
lRetValue = CloseHandle(pInfo.hProcess)

MsgBox "Program has terminated!"

--------------------
in this case, Clipbrd.exe gets executed fine, but if i want to call an application from anywhere other than the windows directory, that app doesn't get executed.

I got this code from the MSDN help, so I'm not too familiar with it.

Thanks for looking into this for me!

Tracie
 
Hmmm,

This might be too easy:

Shell "e:\Program Files\Internet Explorer\Iexplore.exe", vbMaximizedFocus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top