Solved

Using Shell Command with Windows NT

Posted on 2002-05-07
12
172 Views
Last Modified: 2010-05-02
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!!!
0
Comment
Question by:Barb4253
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 20

Expert Comment

by:hes
ID: 6994514
Try using this

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)

0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 100 total points
ID: 6995189
Try surround path with double quotes.
I'm using the Shell command in Visual Basic to run an exe:
   lRetVal = Shell(chr$(34) & exetorun & chr$(34), vbNormalFocus)
I am using the return value (Instance handle) in an if statement:
   If lRetVal <> 0 Then

0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 6995296
Richie,is the exe you are shelling 16-bit?
0
 
LVL 20

Expert Comment

by:hes
ID: 6995329
vinnyd79, (not Richie)
The one I am starting is. I wait for it to quit then destroy it.
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 6996272
Hes,I know your comment will work with a 16-bit.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6996304
Take in mind that NT manage 16-bit app in a different way that 32-bit ones.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Barb4253
ID: 6996333
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.
0
 

Author Comment

by:Barb4253
ID: 6996340
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.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6996351
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",pathto_your_exe_here,"paremeters(if any otherwise vbnullstring)",vbnullstring,vbnormal)
0
 
LVL 20

Expert Comment

by:hes
ID: 6996691
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
0
 

Author Comment

by:Barb4253
ID: 6997424
Thank You!!!
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6997453
glad to help but you said that my post doesn't works!
Thanks for "A" grade!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel object stays open 19 71
SSRS expression Issue finding a string 10 66
Convert VB6 MSXML2.ServerXMLHTTP process to C# 2 41
VB6 - Convert HH:MM into Decimal 8 51
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now