Library tutorials & articles
Shell and ShellExecute function
- Running another application
- Opening a file
Running another application
You can run another application by using the Shell statement.
'// this code calls c: est.exe
Shell "c:\test.exe", vbNormalFocus
You can also call any program in the windows directory, such as regsvr32, notepad, and explorer
So,
Shell "notepad", vbNormalFocus
Runs notepad, and
Shell "explorer", vbNormalFocus
runs explorer. You can also pass any command parameters you need. For example:
Shell "notepad C:\test.txt", vbNormalFocus
runs notepad, and tells it to open C:\test.txt. Note that if the path you pass contains spaces, you need to surround it by quotes:
Shell "notepad ""C:\dir with spaces\test.txt""", vbNormalFocus
which is actually the equivalent of passing this:
notepad "
C:\dir
with spaces\test.txt"
The second parameter specifies the startup position, and can be one of the following:
| Constant | Value | Description |
| vbHide | 0 | Window is hidden and focus is passed to the hidden window. |
| vbNormalFocus | 1 | Window has focus and is restored to its original size and position. |
| vbMinimizedFocus | 2 | Window is displayed as an icon with focus. |
| vbMaximizedFocus | 3 | Window is maximized with focus. |
| vbNormalNoFocus | 4 | Window is restored to its most recent size and position. The currently active window remains active. |
| vbMinimizedNoFocus | 6 | Window is displayed as an icon. The currently active window remains active. |
The shell function also returns a TaskID (double), that you can use with the AppActivate statement:
Private dblNotePadID As Double
'// runs word
Private Sub cmdRunNotePad_Click()
dblNotePadID = Shell("notepad", vbNormalFocus")
End Sub
'// activates word at a later stage
Private Sub cmdActivateNotePad_Click()
AppActivate dblNotePadID
End Sub
Related articles
Related discussion
-
VB6 Runtime error 381 subsript out of range Error
by Uncle (2 replies)
-
passing and reading parameters from using Shell
by jigartoliya (0 replies)
-
Convert C++ code to VB6
by mawcot (4 replies)
-
listbox scrollbar
by Dennijr (10 replies)
-
Can you describe Above simple VB6 code?
by pramodmca09 (0 replies)
Related podcasts
-
Christian Beauclair
14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...
hi!! i make a program with .net, in this program use the command shell for execute an aplication in visual basic 6 but i can not open de file "exe" why i need pass by parameters for opening the file.
Somebody can help me with my doubt.
!--removed tag-->Explorer File(s) (.html or htm) In New Window(new instance of IE for
every file) every time I clicked on the Different file.
Did you check this site?
http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=6071&lngWId=1
I have the same situation and would appreciate your sharing any answer.
Is there anyway of using information gathered from drive/dir/file list boxes in the path when using Shell? I have tried but I think I have the wrong syntax even though VB6 does not complain.
I would really appreciate any help,
Thank you
Hi,
very compliments for your tuttorial, it's very clarity.
I have another question, now.
The command "sendkeys" send data to the active application
in this moment.
I need to send data (key) to an aplication that is just
running, but in background, in minimize state.
It's possible to make this?
Thanks in advantage.
DaxDax
I want my program to wait till Shell or shellexecute command finishes zipping a file of size say 500mb. Please let me know the solution.
Thanks,
is there a possibility for me to open a program to another pc. im thinking like a server client program where the server opens the client or other program from the other terminal...??
Nice tutorial, but you seem to have overlooked something. How do I launch My Computer? Explorer with no parameter opens My Documents, Explorer mycomp~1 and Explorer ""My Computer"" both say the directory doesn't exist. (This is on XP Pro BTW.)
This thread is for discussions of Shell and ShellExecute function.