vb6.0的各种SHELL,CMD内部命令、外部命令、SHELL任意文件

时间:2021-09-28 10:41:03
 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
'能打开任意文件的shell
Public Function ShellAll(nHwnd As Long, ByVal strFilePath As String, Optional ByVal strCanShu As String = "") As Boolean
On Error GoTo ShellAllErr
ShellAll = True
strFilePath = Trim(strFilePath)
Dim nLs As Long
nLs = ShellExecute(nHwnd, "open", strFilePath, vbNullString, strCanShu, vbNormalFocus)
If nLs <= Then
ShellAll = False
End If
Exit Function
ShellAllErr:
Err.Clear
ShellAll = False
End Function
'不提示错误的shell,可SHELL外部DOs命令
Public Function myShell(strFile As String) As Boolean
On Error GoTo shellError
myShell = True
Dim k As Long
k = Shell(strFile, vbNormalFocus)
If k = Then myShell = False
Exit Function
shellError:
myShell = False
End Function
'SHELL DOS的内部命令
Public Sub ShellDocIn(ByVal strCmd As String)
On Error Resume Next '此过程不保证一定执行成功
strCmd = Trim(strCmd)
Shell "Cmd.exe /k " & strCmd, vbHide
End Sub