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!

N00b question: Opening Apps from a VB App

Status
Not open for further replies.

plastic

Programmer
Jul 11, 2002
24
GB
Hey,
Im fairly new to vb and was wondering if there was a way to open applications such as notepad by, say, clicking on a command button from inside a vb application. I mean actually opening up notepad like it would if you were to double click on notepad.exe from C:\Windows.
Thanks so much in advance.

Plastic

 
On trying that with a command button, when i click on it in run time i get: Run time error 5 Invalid call or argument.

Also, is C:\Windows its default lookup directory or something, as you just put notepad.exe

Anyway, thanks in advance

Plastic
 
that weird, ok may try putting in the whole path, ie c:\windows\notepad.exe.

remember that if you r distributing this app that the windows directory has a differnet folder name for different versions of windows. There is code available that returns you the path of the win directory.
 
No such luck, still same error. On debug, all it does is highlights the whole line

Thanks

Plastic
 
Shell is a function, therefore the argument list should be inside of parenthesis

Try

Shell("notepad.exe", vbNormalFocus)

If you want to pass a parameter to, in this example, notepad, you need to include the parameter list for the application all in the first parameter to the shell

CmdLine = &quot;notepad.exe&quot; & &quot; &quot; & <somefilename>
Shell(CmdLine, vbNormalFocus)

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Oh dear, none of these seem to be working. I am running version 6. I am also having major problems with illegal operation.
Thanks in advance.

Plastic
 
Private Declare Function ShellExecute Lib &quot;shell32.dll&quot; _
Alias &quot;ShellExecuteA&quot; (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

Private Sub Command1_Click()
res = ShellExecute(hWnd, vbNullString, &quot;YOURFILENAME&quot;, vbNullString, vbNullString, vbNormalFocus)
End Sub Swi
 
Hey,
Swi's code got it working, thanks everyone for helping. I had no idea the code would be so complex just to open a single app!!! :D

plastic
 
You could also use this

make a form add a button, enter this code in for the button

Shell (&quot;c:\winnt\notepad.exe&quot;)

this should also run notepad!!!!!! James Mannion
IT Officer
James_m_is@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top