In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to use the attributes and objects of Process in VB.NET. It is very detailed and has a certain reference value. Friends who are interested must read it!
You no longer need to use the Win32 API or VB's Shell function to launch external applications. Because you can use the System.Diagnostics.Process class in the .NET Framework to do this, which further simplifies the code.
Although .NET makes a lot of things more complicated, starting an external application is not one of them. In traditional VB programs, you can use the Shell function to start an application. When you transfer a data file name, VB opens the data file in the corresponding application. You can use an optional Windowstyle parameter to control the window mode of the launched application. For example, in VB6, the following line starts the default text editor (usually notepad) and opens the file "c:\ somepath\ somefile.txt":
ReturnID = Shell ("c:\ somepath\ somefile.txt", vbNormalFocus)
Through the Microsoft.VisualBasic.Comaptibility domain name space, the Shell function can still be used in VB.NET, and it has been changed, but it is not a way to start an application in the .NET Framework, because the Shell function has some strict restrictions, one of which is that you can only start the program asynchronously; after you start the application, your own program continues to run. So you can't use it directly to start a program, and you can't return to your own program until the program exits. To do this in traditional VB, you have to turn to Windows API, which requires knowledge of window handles, process identifiers, enumerated windows, and so on.
Using .NET, you can make this operation very simple. You can use the VB.NET Process class in the System.Diagnostics domain space to start external programs. You can simply use the shared Process.Start method to start a new process, passing an executable file name or an extended associated file name of the executable application as a parameter. For example, the following code starts the "c:\ somepath\ somefile.txt" file.
System.Diagnostics.Process.Start ("c:\ somepath\ somefile.txt")
The Start method has an overloaded version that returns a VB.NET Process object, so you can get a reference to the startup process and use it for a variety of purposes:
Dim myProcess As Process = System.Diagnostics.Process.Start ("c:\ somepath\ somefile.txt") MessageBox.Show (myProcess.ProcessName)
At first glance, it looks as if you have lost the ability to control the window style (remember the second argument to the Shell function? ), but this is not the case In many cases, you don't need to explicitly set the window style, because the default is to start the process in a normal window (ProcessWindowStyle.Normal) with focus. But if you want to use a different window style, you can use the overloaded Process.Start method to receive a ProcessStartInfo object parameter instead of a simple string. To use it, first create a ProcessStartInfo object, and then set the process initial value. Two overloading methods let you set a file name or a file name and a set of command line arguments. And the ProcessStartInfo object also has a WindowStyle property, which consists of the values of the System.Diagnostics.Process.WindowStyle enumeration. So you can call the Process.Start method and pass a ProcessStartInfo object to control the style of the launched window.
Dim psInfo As New _ System.Diagnostics.ProcessStartInfo _ ("c:\ somepath\ somefile.txt") psInfo.WindowStyle = _ System.Diagnostics.ProcessWindowStyle.Normal Dim myProcess As Process = _ System.Diagnostics.Process.Start (psInfo)
Because the VB.NET Process class has a StartInfo property, which is a ProcessStartInfo object, another way to produce the same result is to create a Process object and set its StartInfo property. When you pre-create a Process object, you can just call its Start method instead of using the shared Start method of the Process class.
Dim myProcess As System.Diagnostics.Process = _ new System.Diagnostics.Process () myProcess.StartInfo.FileName = _ "c:\ somepath\ somefile.txt" myProcess.StartInfo.WindowStyle = _ System.Diagnostics.ProcessWindowStyle.Normal myProcess.Start
Set Process parameters at design time
The .NET Framework is shipped with VB.NET Process components that encapsulate this code at design time. You can find it in the Components section of the toolbar. To use it, drag a Process component onto your form, then expand the StartInfo property in the properties window and set the value of StartInfo as shown in the following figure.
You can add a Process component to a form that allows you to set properties at design time instead of at run time.
The above is all the content of the article "how to use the attributes and objects of Process in VB.NET". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.