English Sentence Loading...
英语句子加载中...

vb中的shell用法

经常在写程序的时候用shell函数
收集了一些shell的源码
分享一下


    Shell       "EXPLORER.EXE       /n,       /e,       "      
    Explorer       [/n][/e][[,/root],[path]][[,/select],[path       filename]]      
    参数说明      
      /n表示以“我的电脑”方式打开一个新的窗口,通常打开的是Windows安装分区的根目录。      
      
      /e表示以“资源管理器”方式打开一个新的窗口,通常打开的也是Windows安装分区的根目录。    

  
      
      /root,[path]表示打开指定的文件夹,/root表示只显示指定文件夹下面的文件(夹),不显示其他

磁盘分区和文件夹;[path]表示指定的路径。      
      
      如果不加/root参数,而只用[path]参数,则可以显示其他磁盘分区和文件夹中的内容。另外,

[path]还可以指定网络共享文件夹。      
      
      /select,[path       filename]表示打开指定的文件夹并且选中指定的文件,[path       filename]

表示指定的路径和文件名。      
      
      如果不加/select参数,则系统会用相应的关联程序打开该文件。如果[path       filename]不跟文

件名就会打开该文件夹的上级目录并选中该文件夹。      
  





VB ShellExecute 函数应用技巧
ShellExecute
声明:
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
原型:
HINSTANCE ShellExecute(
  HWND hwnd,          //父窗口句柄
  LPCTSTR lpOperation,     //操作,"open","print","explore"
  LPCTSTR lpFile,       //文件名,前面可加路径
  LPCTSTR lpParameters,    //参数
  LPCTSTR lpDirectory,     //默认文件夹
  INT nShowCmd         //显示方式
);

打开一个应用程序
ShellExecute(this->m_hWnd,"open","calc.exe","","", SW_SHOW );

ShellExecute(this->m_hWnd,"open","notepad.exe","c:MyLog.log","",SW_SHOW );

打开一个同系统程序相关连的文档
ShellExecute(this->m_hWnd,"open","c:abc.txt","","",SW_SHOW );

激活相关程序,发送EMAIL
ShellExecute(this->m_hWnd,"open",mailto:junyuqin@sohu.com,"","", SW_SHOW );

打开文件夹

ShellExecute(handle, "open", path_to_folder, NULL, NULL, SW_SHOWNORMAL)

用系统打印机打印文档
ShellExecute(this->m_hWnd,"print","c:abc.txt","","", SW_HIDE);


本函数还可以用来连接到网页,照下面写就行了:
ShellExecute 0&, vbNullString, "", vbNullString, vbNullString, vbNormalFocus

  或者这样写来发送Email:
ShellExecute me.hwnd, "open", "mailto:junyuqin@sohu.com", vbNullString, vbNullString, SW_SHOW

另外有ShellExecute的替代用法,更加简单实用,不用API,一句Shell搞定!

连接到网页:
  Shell "rundll32.exe url.dll,FileProtocolHandler "
打开文件:
  Shell "rundll32.exe url.dll,FileProtocolHandler " & App.Path & "SHELLTST.TXT"



ShellExecute API应用整理


作者: yanek

1.     执行“打开”,“查找”,“资源管理器”和“打印”
必要的声明:
’ nShowCmd
Public Const SW_HIDE = 0
Public Const SW_SHOWNORMAL = 1
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_SHOWMAXIMIZED = 3
Public Const SW_MAXIMIZE = 3
Public Const SW_SHOWNOACTIVATE = 4
Public Const SW_SHOW = 5
Public Const SW_MINIMIZE = 6
Public Const SW_SHOWMINNOACTIVE = 7
Public Const SW_SHOWNA = 8
Public Const SW_RESTORE = 9

’ Error Code
Public Const ERROR_FILE_NOT_FOUND = 2
Public Const ERROR_PATH_NOT_FOUND = 3
Public Const ERROR_BAD_FORMAT = 11

Public Const SE_ERR_FNF = 2
Public Const SE_ERR_PNF = 3
Public Const SE_ERR_ACCESSDENIED = 5
Public Const SE_ERR_OOM = 8
Public Const SE_ERR_SHARE = 26
Public Const SE_ERR_ASSOCINCOMPLETE = 27
Public Const SE_ERR_DDETIMEOUT = 28
Public Const SE_ERR_DDEFAIL = 29
Public Const SE_ERR_DDEBUSY = 30
Public Const SE_ERR_NOASSOC = 31
Public Const SE_ERR_DLLNOTFOUND = 32

Public 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


“打开“操作
               ShellExecute Me.hwnd, "open", _
                       Text1.Text, _
                       vbNullString, vbNullString, _
                       SW_SHOWNORMAL


“查找“操作
           ShellExecute Me.hwnd, "find", _
                   LocalDir, _
                   vbNullString, vbNullString, _
                   SW_SHOWNORMAL


“打印“操作
               ShellExecute Me.hwnd, "print", _
                       Text1.Text, _
                       vbNullString, vbNullString, _
                       SW_SHOWNORMAL


“资源管理器“
           ShellExecute Me.hwnd, "explore", _
                   LocalDir, _
                   vbNullString, vbNullString, _
                   SW_SHOWNORMAL


打开“我的文档“
       ShellExecute Me.hwnd, _
           "open", "explorer", _
           vbNullString, vbNullString, _
           SW_SHOWNORMAL


打开“我的电脑“
’ 我的电脑
’ HKEY_CLASSES_ROOTCLSID’ {20D04FE0-3AEA-1069-A2D8-08002B30309D}

       ShellExecute Me.hwnd, "open", _
           "explorer", _
           "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", _
           vbNullString, SW_SHOWNORMAL


打开“网上邻居“
’ 网上邻居
’ HKEY_CLASSES_ROOTCLSID’ {208D2C60-3AEA-1069-A2D7-08002B30309D}

       ShellExecute Me.hwnd, "open", _
           "explorer", _
           "::{208D2C60-3AEA-1069-A2D7-08002B30309D}", _
           vbNullString, SW_SHOWNORMAL


打开“回收站“
’ 回收站
’ HKEY_CLASSES_ROOTCLSID’ {645FF040-5081-101B-9F08-00AA002F954E}

       ShellExecute Me.hwnd, "open", _
           "explorer", _
           "::{645FF040-5081-101B-9F08-00AA002F954E}", _
           vbNullString, SW_SHOWNORMAL


ShellExecuteEx API演示
必要声明:
Public Type SHELLEXECUTEINFO
       cbSize As Long
       fMask As Long
       hwnd As Long
       lpVerb As String
       lpFile As String
       lpParameters As String
       lpDirectory As String
       nShow As Long
       hInstApp As Long
       ’     Optional fields
       lpIDList As Long
       lpClass As String
       hkeyClass As Long
       dwHotKey As Long
       hIcon As Long
       hProcess As Long
End Type

’ fMask
Public Const SEE_MASK_CLASSKEY = &H3
Public Const SEE_MASK_CLASSNAME = &H1
Public Const SEE_MASK_CONNECTNETDRV = &H80
Public Const SEE_MASK_DOENVSUBST = &H200
Public Const SEE_MASK_FLAG_DDEWAIT = &H100
Public Const SEE_MASK_FLAG_NO_UI = &H400
Public Const SEE_MASK_HOTKEY = &H20
Public Const SEE_MASK_ICON = &H10
Public Const SEE_MASK_IDLIST = &H4
Public Const SEE_MASK_INVOKEIDLIST = &HC
Public Const SEE_MASK_NOCLOSEPROCESS = &H40

Public Declare Function ShellExecuteEX Lib "shell32.dll" _
       Alias "ShellExecuteEx" _
       (lpExecInfo As SHELLEXECUTEINFO) As Boolean


执行调用“文件属性“对话框
       Dim dwReturn As Long
       Dim lpExecInfo As SHELLEXECUTEINFO
    
       With lpExecInfo
           .cbSize = Len(lpExecInfo)
           .fMask = SEE_MASK_NOCLOSEPROCESS or _
                    SEE_MASK_INVOKEIDLIST or _
                    SEE_MASK_FLAG_NO_UI
           .hwnd = Me.hwnd
           .lpVerb = "properties"
           .lpFile = LocalDir & File1.FileName
           .lpParameters = vbNullChar
           .lpDirectory = vbNullChar
           .nShow = SW_SHOWNORMAL
           .hInstApp = 0
           .lpIDList = 0
       End With
    
       dwReturn = ShellExecuteEX(lpExecInfo)
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: VB shell 源码
相关日志:
评论: 0 | 引用: 0 | 查看次数: 2394