Shell是用來執行外部的可執行文件
如果是一個文件,那要用ShellExecute來啟動預設的程式來開啟文件
'HINSTANCE ShellExecute(
' HWND hwnd, // handle to parent window
' LPCTSTR lpOperation, // pointer to string that specifies operation to perform
' LPCTSTR lpFile, // pointer to filename string
' LPTSTR lpParameters, // pointer to string that specifies executable-file parameters
' LPCTSTR lpDirectory, // pointer to string that specifies default directory
' INT nShowCmd // whether file is shown when opened
' );
例:.doc 是由word或wordpad來開啟
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
Const SW_SHOW = 5
ret = ShellExecute(me.hWnd, "open" , "文件完整路徑及名稱","", "", SW_SHOW
事實上有一個更快的方式,便是使用Start指令,這個指令用法簡單
eg. Start mydoc.doc
故,在vb中便是使用 Shell "start mydoc.doc"
如何查看某個文件是和誰相關聯呢?例如:.txt是由哪個程式開啟,
1.查[HKEY_CLASSES_ROOT\.txt]
取預設值,如本人電腦預設值為 "txtfile"
2.查[HKEY_CLASSES_ROOT\txtfile\shell\open\command]
取預設值,如本人電腦預設值為 "C:\WINDOWS\NOTEPAD.EXE %1"
如此可知.txt 是內定由NotePad.exe所執行。
注:若step 1.取得的預設值是 "xxxx",則step 2.便是查
[HKEY_CLASSES_ROOT\xxxx\shell\open\command]的預設值