NET Common Skills 1

Source: Internet
Author: User

1. How to Apply in. netProgramRun other EXE files?

A: mainly applies the process class in the system. Diagnostics namespace.

MainCode:
Process proc = new process ();
Proc. startinfo. filename = @ "D: \ Program Files \ Foxmail \ foxmail.exe"; // you can use an absolute path.
Proc. startinfo. Arguments = "";
Proc. Start ();

2. How to detect the current operating system?

Answer: Environment class in the application system namespace

Main Code:
String versiontext = environment. osversion. version. tostring ();

3. How do I obtain the path of a running program?

A: Call executablepath in the application class to obtain the path from a static member.

Main Code:
Textbox1.text = application. executablepath;
4. How do I view all the installed assemblies on my computer?

A:. NET Framework installs all the assembly in the \ winnt \ assembly (implicit) Directory of the system installation disk. You can view all the details of the Assembly by viewing the properties.

5. How to Use System. Windows. Forms. application. companyName to set the company name?

A: set it in Assembly. In the development environment of vs. net, it is set in the assemblyinfo. CS (VB) file. You can check the file.
Company Information and version information

Main Code:
[Assembly: assemblycompany ("cnblog copyright")]

6. If the. NET runtime framework is not installed on your computer, can you run the. NET program?

A: No. You must install. NET Framework.

You can download it at the address below.
Http://msdn.microsoft.com/library/default.asp? Url =/downloads/LIST/netdevframework. asp

7. How do I obtain a local IP address?

A: In the namespace system. net defines a DNS class. One of the methods is gethostbyname (), which is used to return the iphostentry object. This object has an attribute Addresslist, which is an array of the IPaddress type, contains all the IP addresses of the computer at this time, including the temporary allocated IP addresses obtained by dialing the Internet and the fixed IP addresses of the LAN.

Main Code:
String S = "";
System. net. IPaddress [] Addresslist = DNS. gethostbyname (DNS. gethostname (). Addresslist;
For (INT I = 0; I <Addresslist. length; I ++)
{
S + = Addresslist [I]. tostring ();
}

8. How to ensure that only one program (Instance) runs in C?

Answer: The main application is system. the process class in the diagnostics namespace is implemented. Before running the program, we can check whether there are any processes with the same name in the process, and the running location is the same. If the program is not run, if yes, set the program window with the same name in the same position to the front.
Main Code:
Public static process runninginstance ()
{
Process current = process. getcurrentprocess ();
Process [] processes = process. getprocessesbyname (current. processname );
// Search for processes with the same name
Foreach (Process in processes)
{
// Ignore the current process
If (process. ID! = Current. ID)
{
// Check whether the running location of the same process is the same.
If (assembly. getexecutingassembly (). Location. Replace ("/", "\") = current. mainmodule. filename)
{
// Return the other process instance.
Return process;
}
}
}
// No other instance was found, return null.
Return NULL;
}

9. How can we display all processes running in all systems?

Answer: Use the process. getprocess () static member in the system. Diagnostics namespace.

Main Code:
Using system. diagnostics;
...
Foreach (PROCESS p in process. getprocesses ())
Console. writeline (p); // string S = P. tostring ();
10. How do I list all running applications?

A: The enumwindows function can be used to enumerate all existing windows on the computer. However, the static function process. getprocesses () in the system. Diagnostics namespace can be used to avoid the interoperability problem of enumwindows.

Main Code:
[C #]
Using system. diagnostics;
...
Foreach (PROCESS p in process. getprocesses (system. environment. machinename ))
{
If (P. main1_whandle! = Intptr. Zero)
{
// Display the user program name
Console. writeline (p); // string S = P. tostring ();
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.