|
-
August 8th, 2001, 04:36 AM
#1
open another program
how do i open a program through a VB program eg another VB program.
-
August 8th, 2001, 04:49 AM
#2
Re: open another program
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
in a form:
Call ShellExecute(me.hwnd, vbNullString, "notepad.exe", vbNullString, "c:\", 1)
HTH
Daniel
-
August 8th, 2001, 08:35 AM
#3
Re: open another program
how do you open a specific file into the new app?
i've tried using the AppActivate statement but it doesn't appear to have any arguments for this?
code below
Dim FileName as string
Dim DbPath as string
Dim FilePath as string
FilePath = DbPath & "/" & "logs/" & FileName & ".txt"
DbPath = Application.CurrentProject.Path
FileName = date$
If Dir$(DbPath & "/" & "logs/" & FileName & ".txt") = FileName & ".txt" then
'Open file
MyAppID = Shell("C:\Program Files\WINDOWS NT\ACCESSORIES\WORDPAD.EXE", "FilePath", 1)
AppActivate MyAppID
End If
-
August 8th, 2001, 08:44 AM
#4
Re: open another program
A form with 3 buttons arrays: Command1() for Apps (6 buttons, indexes 0-5), Command2()(3 indexes 0-2) for Browsers, and Command3() (6 ,indexes 0-5)for Explorer methods. Paste the following code into the general declarations area of the form:
option Explicit
'code retrieved on the net
'someone may have copiright on this...
private Declare Function GetDesktopWindow Lib "user32" () as Long
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
private Const SW_SHOWNORMAL as Long = 1
private Const SW_SHOWMAXIMIZED as Long = 3
private Const SW_SHOWDEFAULT as Long = 10
private Const SE_ERR_NOASSOC as Long = 31
public Sub RunShellExecute(sTopic as string, _
sFile as Variant, _
sParams as Variant, _
sDirectory as Variant, _
nShowCmd as Long)
Dim hWndDesk as Long
Dim success as Long
'the desktop will be the
'default for error messages
hWndDesk = GetDesktopWindow()
'execute the passed operation
success = ShellExecute(hWndDesk, sTopic, sFile, sParams, sDirectory, nShowCmd)
'This is optional. Uncomment the three lines
'below to have the "Open With.." dialog appear
'when the ShellExecute API call fails
'If success = SE_ERR_NOASSOC then
' Call Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " & sFile, vbNormalFocus)
'End If
End Sub
private Sub Command1_Click(Index as Integer)
Dim sTopic as string
Dim sFile as string
Dim sParams as Variant
Dim sDirectory as Variant
Select Case Index
Case 0: 'open doc file with associated app
sTopic = "Open"
sFile = "c:\My Documents\Resources.doc"
sParams = 0&
sDirectory = 0&
Case 1: 'open txt file with associated app
sTopic = "Open"
sFile = "c:\My Documents\rundll.txt"
sParams = 0&
sDirectory = 0&
Case 2: 'open wav file with associated app
sTopic = "Open"
sFile = "c:\win\media\Notify.wav"
sParams = 0&
sDirectory = 0&
Case 3: 'play wav file with associated app
sTopic = "Play"
sFile = "c:\win\media\Notify.wav"
sParams = 0&
sDirectory = 0&
Case 4: 'open autoexec.bat with notepad
sTopic = "Open"
sFile = "C:\win\notepad.exe"
sParams = "C:\Autoexec.bat"
sDirectory = 0&
Case 5: 'play avi file with associated app
sTopic = "Play"
sFile = "E:\VB Graphics\avi\Cogs.avi"
sParams = 0&
sDirectory = 0&
Case else
End Select
Call RunShellExecute(sTopic, sFile, sParams, sDirectory, SW_SHOWNORMAL)
End Sub
private Sub Command2_Click(Index as Integer)
Dim sTopic as string
Dim sFile as string
Dim sParams as Variant
Dim sDirectory as Variant
Select Case Index
Case 0: 'send email to address using default email app
sTopic = "Open"
sFile = "mailto:[email protected]"
sParams = 0&
sDirectory = 0&
Case 1: 'open default browser to specified site
sTopic = "Open"
sFile = "http://www.mvps.org/vbnet/"
sParams = 0&
sDirectory = 0&
Case 2: 'open specified browser to specified site
sTopic = "Open"
sFile = "C:\Program Files\Internet Explorer\iexplore.exe"
sParams = "http://www.mvps.org/vbnet/"
sDirectory = 0&
Case else
End Select
Call RunShellExecute(sTopic, sFile, sParams, sDirectory, SW_SHOWNORMAL)
End Sub
private Sub Command3_Click(Index as Integer)
Dim sTopic as string
Dim sFile as string
Dim sParams as Variant
Dim sDirectory as Variant
Select Case Index
Case 0: 'explorer - rooted, normal view
sTopic = "Open"
sFile = "explorer.exe"
sParams = "/root,c:\program files"
sDirectory = 0&
Case 1: 'explorer - rooted, explorer view
sTopic = "Open"
sFile = "explorer.exe"
sParams = "/e,/root,c:\program files"
sDirectory = 0&
Case 2: 'explorer - explorer view, with specified folder
sTopic = "Open"
sFile = "explorer.exe"
sParams = "/e,c:\program files"
sDirectory = 0&
Case 3: 'explorer - explorer view, with specified drive
sTopic = "Open"
sFile = "explorer.exe"
sParams = "/e,c:\"
sDirectory = 0&
Case 4: 'explorer - explorer view, current drive
sTopic = "Open"
sFile = "explorer.exe"
sParams = "/e,\"
sDirectory = 0&
Case 5: 'recycle bin
sTopic = "Open"
sFile = "explorer.exe"
sParams = "/root,::{645FF040-5081-101B-9F08-00AA002F954E}"
sDirectory = 0&
Case else
End Select
Call RunShellExecute(sTopic, sFile, sParams, sDirectory, SW_SHOWNORMAL)
End Sub
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
The Rater
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
August 10th, 2001, 03:35 AM
#5
Re: open another program
im sorry i have tried your ways but i am only a beginner so i am very confused with what i should be puttine where and so on. thank you for your help but plese could you help me some more and explain to me what is happening and what i need to do
thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|