Process.Start命令行的5種使用方法 |
作者:Ilu 來源:樂博網整理 更新時間:2009-9-5 |
Process.Start命令行的5種使用方法 1. Process.Start 實例First, here is an example VB.NET program that uses Process.Start to open the file manager on your C:\ drive. When you run this example the root directory folder will open. Module Module1 Sub Main() Process.Start("C:\") End Sub End Module Description of the example code. The Main entry point is declared above and it contains a single line of code, which calls the Process.Start Shared method. It passes one parameter to Process.Start, the directory root. 2. Process.Start打開TXT文本文件Here we see that when you specify a certain file for Process.Start to open, the default Windows file viewer for the file type will open. This is useful for text files, Microsoft Office files, and many other files. Module Module1 Sub Main() 'vb.net源碼和實例,來自樂博網 www.lob.cn ' Open the file 'example.txt' at the current program's directory. ' It will appear in the default text file viewer. Process.Start("example.txt") End Sub End Module Description of the example VB.NET code. The Main entry point subroutine is declared above. It contains a comment and one call to Process.Start. The "example.txt" file must be found in the program's current directory. Notepad or any text viewer will open. This can be useful for "Read Me" files. Description of file paths. Instead of just passing "example.txt", you could pass "C:\Users\Sam\example.txt" to specify the absolute directory. 3. Process.Start進行google搜索In many programs, resources can be given to the user in the form of URLs. You can tell Windows to launch a web browser window with a specific URL. All you have to do is send Process.Start the URL. It is important that you do not specify IEXPLORE unless IE is required. Module Module1 Sub Main() SearchGoogle("樂博網") End Sub ''' <summary> ''' Open the user's default browser and search for the parameter. ''' </summary> Private Sub SearchGoogle(ByVal t As String) Process.Start("http://www.google.cn/search?q=" & t) End Sub End Module Description of the example subroutines. You can see that the subroutine SearchGoogle() is called with a String parameter. The SearchGoogle function is then run, and it calls Process.Start. The base URL for a Google search is specified. The query string is then set to the parameter. ![]() Note on specifying browser executables. Many users and organizations have certain web browsers they use. However, these should be set at the system-level in Windows. Therefore, you shouldn't normally specify IEXPLORE.EXE here. |