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

shell execute parameter

Status
Not open for further replies.

ghobbes98

Programmer
Feb 7, 2002
62
0
0
IE
I am calling shellexecute and the final value in the parameters being passed to it is
SW_SHOWNORMAL
but I am getting an error all of a sudden with this and I don't seem to be able to get any help from MSDN does anybody know the hard code value that this stands for like 5 or 6 I would imagine
Any help would be great
Hobbes
 
Dear ghobbes98

can you provide more details on what r u executing using the command...Why do'nt u try shell function which is used to run a excutable program

Regards
Mahesh
mshetti@yahoo.com
 
What I want to do is set off a load of exes to run and forget about them. I found I was not able to do this with shell as it waited for the exe to finish before it went on with rest of the code
It should not matter really what I am executing surely. All that it is is another vb program to write randomly to a database for a set length of time.
I got around using the SH_SHOWNORMAL by putting in the value 11. Not the prettiest solution but it seems to work so far but I am not happy with it.
 
If you are wanting to wait on the shelled app to finish then check this link out. I think it should lead you in the right direction.



I'm not sure I understand this sentence:

"I found I was not able to do this with shell as it waited for the exe to finish before it went on with rest of the code"

It's my understanding that shell continues on with execution of code after the shelled app has been launched.
 
nah from my experience it waits for the shelled app to finish before going on
MDP just to clarify it I don't want to wait for the app to finish. I want to start it and forget about it I don't care when it finishes.
I know how to declare a const but this should be a prdefined const that I should not have to try and redefine
Here is how I define shell execute at the top of the code

Private 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

as you can see nShowCmd is the last argument and is a long. there are 12 possibilities and I just figured as SH_SHOWNORMAL was the last one that its value was probably 11 but I would just like to be sure
Thanks
Hobbes
 

Private 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
Const SW_SHOWNORMAL = 1

Private Sub Command1_Click()
ShellExecute Me.hwnd, vbNullString, "notepad.exe", vbNullString, "C:\", SW_SHOWNORMAL

MsgBox "NotePad has been Opened"
End Sub


When ever I run the code listed above notepad immediately opens and then the message box appears indicating that execution of the code continued and did not wait for the program launched by the shellExecute command to close/stop.

Also, the SH_NORMAL command activates and displays the window. If you wanted to launch and forget it then you probably would want to use a different value for nShowCmd.


Here is some documentation on SH_NORMAL:
SW_SHOWNORMAL
Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when displaying the window for the first time.

According to the API viewer the value for SH_SHOWNORMAL is 1. I think you probably want to use SW_HIDE so you can forget about it. SW_HIDE const value is 0.

Here is some documentation of SW_HIDE:
SW_HIDE
Hides the window and activates another window.


again, I'm still a bit confused by this statement:
"from my experience it waits for the shelled app to finish before going on"
 
Thanks for that!
I don't know what is to be confused about though. All I meant was when I tried to use it before the code following the Shell command (as you suggested), not Shellexecute, did not run till the exe that was called had been closed. I don't know if I can make it any simpler. You might be able to get some code running for yourself but when I was trying to get a number of a particular exe running it would not work
Thanks for you help MDP
Hobbes
 
Sorry mdp it was mshetti that suggested the shell command......sorry again
 
Hobbes,

My one concern would be that you may have some other issue going on if Shell is somehow appearing to be waiting for the shelled application to finish execution. Both Shell and ShellExecute (and indeed ShellExecuteEx) are, by default, asynchronous; i.e. they don't bother waiting for the launched application to finish executing. This is documented in the help files. Indeed, one of the most asked questions in this forum concerns how to launch an application and wait until it has finished executing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top