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

How works ShellExecute? 1

Status
Not open for further replies.

aweiss

Programmer
Dec 9, 1999
15
0
0
DE
Hello!<br>
<br>
I want to use the Win32 API function ShellExecute. Can some give me an example?<br>
Thanks<br>
<br>
aweiss
 
Hello,<br>
<br>
I know now how it's work:<br>
<br>
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<br>
<br>
dim result, File<br>
<br>
File = &quot;C:\weiss.bat&quot;<br>
<br>
result = ShellExecute(0, &quot;OPEN&quot;, File, &quot;&quot;, App.Path & &quot;\&quot;, 0)<br>
<br>
Now my new question:<br>
<br>
I want to do this syncron! Can some help me and say me the right parameter?<br>
<br>
thanks<br>
<br>
aweiss
 
I don't think it's a parameter.<br>
<br>
The only way I know how to do it is a bit involved but it is in a module and quite easy to use. I can email you the code if you like - drop me a line<br>
<br>
-ml <p>Mike Lacey<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
What do you actually want to do with it. <br>
Open a particular file with a particular editor or something else ? <p>Ravi Kochher<br><a href=mailto:rkochher@ssius.com>rkochher@ssius.com</a><br><a href= > </a><br>
 
Here is it :<br>
<br>
Private Declare Function GetDesktopWindow Lib &quot;user32&quot; () As Long<br>
<br>
Private Declare Function ShellExecute Lib &quot;shell32.dll&quot; _<br>
Alias &quot;ShellExecuteA&quot; _<br>
(ByVal hwnd As Long, ByVal lpOperation As String, _<br>
ByVal lpFile As String, ByVal lpParameters As String, _<br>
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long<br>
<br>
Private Const SW_SHOWNORMAL As Long = 1<br>
Private Const SW_SHOWMAXIMIZED As Long = 3<br>
Private Const SW_SHOWDEFAULT As Long = 10<br>
<br>
<br>
Public Sub RunShellExecute(sTopic As String, sFile As Variant, _<br>
sParams As Variant, sDirectory As Variant, _<br>
nShowCmd As Long)<br>
<br>
Dim hWndDesk As Long<br>
Dim success As Long<br>
Const SE_ERR_NOASSOC = &H31<br>
<br>
'the desktop will be the<br>
'default for error messages<br>
hWndDesk = GetDesktopWindow()<br>
<br>
'execute the passed operation<br>
success = ShellExecute(hWndDesk, sTopic, sFile, sParams, sDirectory, nShowCmd)<br>
<br>
'This is optional. Uncomment the three lines<br>
'below to have the &quot;Open With..&quot; dialog appear<br>
'when the ShellExecute API call fails<br>
'If success = SE_ERR_NOASSOC Then<br>
' Call Shell(&quot;rundll32.exe shell32.dll,OpenAs_RunDLL &quot; & sFile, vbNormalFocus)<br>
'End If<br>
<br>
End Sub<br>
<br>
<br>
Private Sub cmdApps_Click(Index As Integer)<br>
<br>
Dim sTopic As String<br>
Dim sFile As String<br>
Dim sParams As Variant<br>
Dim sDirectory As Variant<br>
<br>
Select Case Index<br>
Case 0: 'open doc file with associated app<br>
sTopic = &quot;Open&quot;<br>
sFile = &quot;c:\My Documents\Resources.doc&quot;<br>
sParams = 0&<br>
sDirectory = 0&<br>
<br>
Case 1: 'open txt file with associated app<br>
sTopic = &quot;Open&quot;<br>
sFile = &quot;c:\My Documents\rundll.txt&quot;<br>
sParams = 0&<br>
sDirectory = 0&<br>
<br>
Case 2: 'open wav file with associated app<br>
sTopic = &quot;Open&quot;<br>
sFile = &quot;c:\win\media\Notify.wav&quot;<br>
sParams = 0&<br>
sDirectory = 0&<br>
<br>
Case 3: 'play wav file with associated app<br>
sTopic = &quot;Play&quot;<br>
sFile = &quot;c:\win\media\Notify.wav&quot;<br>
sParams = 0&<br>
sDirectory = 0&<br>
<br>
Case 4: 'open autoexec.bat with notepad<br>
sTopic = &quot;Open&quot;<br>
sFile = &quot;C:\win\notepad.exe&quot;<br>
sParams = &quot;C:\Autoexec.bat&quot;<br>
sDirectory = 0&<br>
<br>
Case 5: 'play avi file with associated app<br>
sTopic = &quot;Play&quot;<br>
sFile = &quot;E:\VB Graphics\avi\Cogs.avi&quot;<br>
sParams = 0&<br>
sDirectory = 0&<br>
Case Else<br>
End Select<br>
<br>
Call RunShellExecute(sTopic, sFile, sParams, sDirectory, SW_SHOWNORMAL)<br>
<br>
End Sub<br>
<br>
<br>
Private Sub cmdBrowser_Click(Index As Integer)<br>
<br>
Dim sTopic As String<br>
Dim sFile As String<br>
Dim sParams As Variant<br>
Dim sDirectory As Variant<br>
<br>
Select Case Index<br>
Case 0: 'send email to address using default email app<br>
sTopic = &quot;Open&quot;<br>
sFile = &quot;mailto:<A HREF="mailto:vbg.be@vbgrpup.nl">vbg.be@vbgrpup.nl</A>&quot;<br>
sParams = 0&<br>
sDirectory = 0&<br>
<br>
Case 1: 'open default browser to specified site<br>
sTopic = &quot;Open&quot;<br>
sFile = &quot;<A HREF=" TARGET="_new"> sParams = 0&<br>
sDirectory = 0&<br>
<br>
Case 2: 'open specified browser to specified site<br>
sTopic = &quot;Open&quot;<br>
sFile = &quot;C:\Program Files\Internet Explorer\iexplore.exe&quot;<br>
sParams = &quot;<A HREF=" TARGET="_new"> sDirectory = 0&<br>
<br>
Case Else<br>
End Select<br>
<br>
Call RunShellExecute(sTopic, sFile, sParams, sDirectory, SW_SHOWNORMAL)<br>
<br>
End Sub<br>
<br>
<br>
Private Sub cmdExplorer_Click(Index As Integer)<br>
<br>
Dim sTopic As String<br>
Dim sFile As String<br>
Dim sParams As Variant<br>
Dim sDirectory As Variant<br>
<br>
Select Case Index<br>
Case 0: 'explorer - rooted, normal view<br>
sTopic = &quot;Open&quot;<br>
sFile = &quot;explorer.exe&quot;<br>
sParams = &quot;/root,c:\program files&quot;<br>
sDirectory = 0&<br>
<br>
Case 1: 'explorer - rooted, explorer view<br>
sTopic = &quot;Open&quot;<br>
sFile = &quot;explorer.exe&quot;<br>
sParams = &quot;/e,/root,c:\program files&quot;<br>
sDirectory = 0& <br>
<br>
Case 2: 'explorer - explorer view, with specified folder<br>
sTopic = &quot;Open&quot;<br>
sFile = &quot;explorer.exe&quot;<br>
sParams = &quot;/e,c:\program files&quot;<br>
sDirectory = 0&<br>
<br>
Case 3: 'explorer - explorer view, with specified drive<br>
sTopic = &quot;Open&quot;<br>
sFile = &quot;explorer.exe&quot;<br>
sParams = &quot;/e,c:\&quot;<br>
sDirectory = 0&<br>
<br>
Case 4: 'explorer - explorer view, current drive<br>
sTopic = &quot;Open&quot;<br>
sFile = &quot;explorer.exe&quot;<br>
sParams = &quot;/e,\&quot;<br>
sDirectory = 0&<br>
<br>
Case 5: 'recycle bin<br>
sTopic = &quot;Open&quot;<br>
sFile = &quot;explorer.exe&quot;<br>
sParams = &quot;/root,::{645FF040-5081-101B-9F08-00AA002F954E}&quot;<br>
sDirectory = 0&<br>
<br>
Case Else<br>
End Select<br>
<br>
Call RunShellExecute(sTopic, sFile, sParams, sDirectory, SW_SHOWNORMAL)<br>
<br>
End Sub<br>
<br>
<br>
Eric De Decker
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top