# 使用 ShellExecute API

Posted by 小吴 on June 30, 1997 at 19:39:45:

In Reply to: windows on files posted by jacky on June 26, 1997 at 18:25:29:

要开启我的电脑，设定一个我的电脑捷径即可

' ==== ShellExecute ====
Private Const SW_SHOWNORMAL = 1
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 Declare Function GetDesktopWindow Lib "user32" () As Long
' 传回值(错误)
Public Const ERROR_BAD_FORMAT = 11&
Public Const ERROR_FILE_NOT_FOUND = 2&
Public Const ERROR_PATH_NOT_FOUND = 3&
Public Const SE_ERR_ACCESSDENIED = 5
Public Const SE_ERR_ASSOCINCOMPLETE = 27
Public Const SE_ERR_DDEBUSY = 30
Public Const SE_ERR_DDEFAIL = 29
Public Const SE_ERR_DDETIMEOUT = 28
Public Const SE_ERR_DLLNOTFOUND = 32
Public Const SE_ERR_FNF = 2
Public Const SE_ERR_NOASSOC = 31
Public Const SE_ERR_OOM = 8
Public Const SE_ERR_PNF = 3
Public Const SE_ERR_SHARE = 26

' 本 Shell 可以执行关联档
Public Function ShellEx(ByVal sFileName, ByVal sParam, ByVal sDir, Optional ByRef vErr) As Long
Dim Scr_hDC As Long
Dim lReturn
Scr_hDC = GetDesktopWindow()
lReturn = ShellExecute(Scr_hDC, "Open", sFileName, sParam, sDir, SW_SHOWNORMAL)
' 传回执行结果
Select Case lReturn
Case Is > 32 ' 成功
Case 0: vErr = "系统记忆体或资源不足"
Case ERROR_FILE_NOT_FOUND: vErr = "档案找不到"
Case ERROR_BAD_FORMAT: vErr = "错误的 EXE 档案格式"
Case ERROR_PATH_NOT_FOUND: vErr = "路径找不到"
Case SE_ERR_ACCESSDENIED: vErr = "拒绝存取"
Case SE_ERR_ASSOCINCOMPLETE: vErr = "档案关连资讯错误"
Case SE_ERR_DDEBUSY: vErr = "DDE Busy"
Case SE_ERR_DDEFAIL: vErr = "DDE Fail"
Case SE_ERR_DDETIMEOUT: vErr = "DDE Timeout"
Case SE_ERR_DLLNOTFOUND: vErr = "找不到相关的动态连结档"
Case SE_ERR_FNF: vErr = "档案找不到"
Case SE_ERR_NOASSOC: vErr = "档案没有关连"
Case SE_ERR_OOM: vErr = "记忆体不足"
Case SE_ERR_PNF: vErr = "路径找不到"
Case SE_ERR_SHARE: vErr = "分享错误"
End Select
ShellEx = lReturn
End Function

Follow Ups:

- Re: 使用 ShellExecute API 黄嘉贤 09:55:47 7/03/97 (1)
  - Re: 使用 ShellExecute API 小吴 02:15:50 7/04/97 (0)