Difference between revisions of "ShellExecute"

From HashVB
Jump to: navigation, search
m (Changed nShowCmd to SW_NORMAL)
m (Used the new API link template)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
[[Category:API_Calls]]
 
ShellExecute is normally used for opening/running "files".
 
ShellExecute is normally used for opening/running "files".
  
 
This includes documents, audio files, pictures, URL links, etc...
 
This includes documents, audio files, pictures, URL links, etc...
  
===Declaration===
+
=== Declaration ===
 
+
 
  Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long,<br /> ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String,<br /> ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
 
  Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long,<br /> ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String,<br /> ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
  
===Parameters===
+
=== Parameters ===
 
+
 
The only parameter you really need to use is the lpFile parameter and maybe the lpOperation and the rest can be left at the default.<br />
 
The only parameter you really need to use is the lpFile parameter and maybe the lpOperation and the rest can be left at the default.<br />
 
You can pass the path to the file or the URL you would like to open and what you want to do with it.
 
You can pass the path to the file or the URL you would like to open and what you want to do with it.
  
===Sample usage===
+
=== Sample usage ===
 
+
 
Open a URL in the default web browser:
 
Open a URL in the default web browser:
 
  ShellExecute 0, "open", "<nowiki>http://www.earlsoft.co.uk/</nowiki>", "", "", 1
 
  ShellExecute 0, "open", "<nowiki>http://www.earlsoft.co.uk/</nowiki>", "", "", 1
Line 20: Line 18:
 
  ShellExecute 0, "print", App.Path & "\licence.rtf", "", "", 1
 
  ShellExecute 0, "print", App.Path & "\licence.rtf", "", "", 1
  
===See also===
+
=== VB.NET ===
  
* [http://www.earlsoft.co.uk/api/call.php?name=ShellExecute Earlsoft API page]
+
In VB.NET, you can use this as a replacement for ShellExecute but it does not allow you to specify anything apart from lpFile parameter.
  
[[Category:API_Calls]]
+
Private Function ShellExecute(ByVal File As String) As Boolean
 +
  Dim myProcess As New Process
 +
  myProcess.StartInfo.FileName = File
 +
  myProcess.StartInfo.UseShellExecute = True
 +
  myProcess.StartInfo.RedirectStandardOutput = False
 +
  myProcess.Start()
 +
  myProcess.Dispose()
 +
End Function
 +
 
 +
=== See also ===
 +
* {{API link|ShellExecute}}

Latest revision as of 00:54, 11 June 2006

ShellExecute is normally used for opening/running "files".

This includes documents, audio files, pictures, URL links, etc...

Declaration

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

Parameters

The only parameter you really need to use is the lpFile parameter and maybe the lpOperation and the rest can be left at the default.
You can pass the path to the file or the URL you would like to open and what you want to do with it.

Sample usage

Open a URL in the default web browser:

ShellExecute 0, "open", "http://www.earlsoft.co.uk/", "", "", 1

Print licence.rtf from the application directory:

ShellExecute 0, "print", App.Path & "\licence.rtf", "", "", 1

VB.NET

In VB.NET, you can use this as a replacement for ShellExecute but it does not allow you to specify anything apart from lpFile parameter.

Private Function ShellExecute(ByVal File As String) As Boolean
  Dim myProcess As New Process
  myProcess.StartInfo.FileName = File
  myProcess.StartInfo.UseShellExecute = True
  myProcess.StartInfo.RedirectStandardOutput = False
  myProcess.Start()
  myProcess.Dispose()
End Function

See also