Barb4253
asked on
Using Shell Command with Windows NT
I'm using the Shell command in Visual Basic to run an exe:
lRetVal = Shell(exetorun, vbNormalFocus)
I am using the return value (Instance handle) in an if statement:
If lRetVal <> 0 Then
My program contains both 16 bit and 32 bit modules. (ie, exetorun is sometimes a 16bit, sometimes a 32bit)
VB Help states that the Shell Command:
Runs an executable program and returns a Variant (Double) representing the program's task ID if successful, otherwise it returns zero.
The problem is...If my program is being run on Windows NT and Shell is used to run a 16 bit application, the return value is ALWAYS 0! However, it does run the exe.
HELP!!!
lRetVal = Shell(exetorun, vbNormalFocus)
I am using the return value (Instance handle) in an if statement:
If lRetVal <> 0 Then
My program contains both 16 bit and 32 bit modules. (ie, exetorun is sometimes a 16bit, sometimes a 32bit)
VB Help states that the Shell Command:
Runs an executable program and returns a Variant (Double) representing the program's task ID if successful, otherwise it returns zero.
The problem is...If my program is being run on Windows NT and Shell is used to run a 16 bit application, the return value is ALWAYS 0! However, it does run the exe.
HELP!!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Richie,is the exe you are shelling 16-bit?
vinnyd79, (not Richie)
The one I am starting is. I wait for it to quit then destroy it.
The one I am starting is. I wait for it to quit then destroy it.
Hes,I know your comment will work with a 16-bit.
Take in mind that NT manage 16-bit app in a different way that 32-bit ones.
ASKER
HES: I'm still trying to figure out what the code you gave me is doing, I'm not a guru :-) -- My Co. requires that I know what the code means before I put it in an application, go figure.
RICHIE: With the code you gave me, it no longer executes 16 bit OR 32 bit....it just stalls out.
RICHIE: With the code you gave me, it no longer executes 16 bit OR 32 bit....it just stalls out.
ASKER
HES: I'm still trying to figure out what the code you gave me is doing, I'm not a guru :-) -- My Co. requires that I know what the code means before I put it in an application, go figure.
RICHIE: With the code you gave me, it no longer executes 16 bit OR 32 bit....it just stalls out.
RICHIE: With the code you gave me, it no longer executes 16 bit OR 32 bit....it just stalls out.
well, try with:
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
dim ret as long
ret=shellexecute(me.hwnd," open",path to_your_ex e_here,"pa remeters(i f any otherwise vbnullstring)",vbnullstrin g,vbnormal )
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
dim ret as long
ret=shellexecute(me.hwnd,"
Have a look at this article it gives a good explanation of the API and the parameters
http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnarvbtips/html/msdn_msdn173.asp
http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnarvbtips/html/msdn_msdn173.asp
ASKER
Thank You!!!
glad to help but you said that my post doesn't works!
Thanks for "A" grade!
Thanks for "A" grade!
Declare:
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 CreateProcessA Lib "kernel32" _
(ByVal lpApplicationName As Long, ByVal lpCommandLine As _
String, ByVal lpProcessAttributes As Long, ByVal _
lpThreadAttributes As Long, ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, _
ByVal lpCurrentDirectory As String, lpStartupInfo As _
STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) _
As Long
In your code:
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim ret As Long
start.cb = Len(start)
ret& = CreateProcessA(0&, "FileName", 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, "WorkingDirectory", start, proc)