中使用文件名
本文演示如何啟動與給定文檔擴展名或文件類型關聯的應用程序,而不需知道關聯應用程序的名稱或位置。 例如,可以使用與 .bmp 文件擴展名關聯的應用程序啟動 p,大多數情況下,該應用程序為 e。 }gU]fEW
更重要的是拓展了回龍觀商圈的輻射半徑 O6T!)4M
MS ^TDJ,]
要求 Ln T7S H
Microsoft Visual Basic .NET M=Y-|BM
指定 ProcessStartInfo 信息 .\'\'d CQ
可以使用 .NET 框架 Process 類的 ProcessStartInfo 結構指定啟動進程時的選項。 本文概述了如何使用文件名選項。 另一個成員 UseShellExecute 指定根據文件擴展名或文件類型啟動進程,而不是根據可執行文件 (.exe) 的名稱。 默認情況下,此屬性設置為 True。 為了便于說明,在此代碼中特意明確設置了該屬性。 M\\d,Fp!o-
Dim fileName as String = \"\\t\" 33z;lT y
Dim sysFolder As String = _ 1u QZ
tFolderPath(stem) AP \"!\\l~^4
Dim pInfo As New ProcessStartInfo() *ATe`AV
leName = sysFolder fileName Rc(q\'T$l
eShellExecute = True tGmy|l-f
啟動應用程序 lW:6};i)
本示例打開一個名為 t 的文件。該文件是使用與 .txt 文件擴展名關聯的應用程序打開的,通常是 e。可以替換任何有關聯應用程序的文件名或類型。 *15Cm?zm
Dim p As Process = art(pInfo) ,RGC; qT
用于啟動應用程序的快捷方式 yJURF9
因為對進程而言 UseShellExecute 默認為 True,所以啟動進程時不需要使用 ProcessStartInfo。 可以使用一行代碼啟動關聯的應用程序(如下所示): wSX4f4+3D
Dim p As Process = art(\"c:\\winnt\\system32\\t\") e;uZ$v~r
完整代碼示例 Z_M`\\?
\'How to Start a Process with a File Name \\:n~3w
\'Specify a file. k\"qENhP
Dim fileName as String = \"\\t\" ;^ v|5
\'Get the name of the system folder. 3uS?fu]8\"t
$}: yHT
Dim sysFolder As String = _ 0c]`d.r
tFolderPath(stem) USKM8[^
\'Create a new ProcessStartInfo structure. VHVA1NU}
Dim pInfo As New ProcessStartInfo() (2AJ*Ib2
\'Set the file name member of pinfo to t in the system folder. +k[Oi ^JW
leName = sysFolder fileName Ra8;UYA
\'UseShellExecute is true by default. It is set here for illustration. +||PmXY#
eShellExecute = True 1B!v`kU
\'Start the process as specified in the process info structure. 2-= oX\"
Dim p As Process = art(pInfo) |:mVCp`
疑難解答 +eg\"5K8Oz
單臺計算機可能沒有安裝關聯的應用程序,或者注冊表中的關聯可能不正確。 最好將此代碼包含在 try...catch 塊中,這樣,當失敗時系統就會對應用程序發出警報 G`mAZE( 查看本文來源
拉薩男科治療哪家好臨沂治療早泄陽痿醫院哪家好
成都治療男性功能障礙費用