Process.Start命令行的5种使用方法

来源:百度文库 编辑:神马文学网 时间:2024/04/28 23:11:21
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            '''             ''' Open the user's default browser and search for the parameter.            '''             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.