C # Common Code

Source: Internet
Author: User
// Retrieve system folders
String Folder = System. environment. getfolderpath (environment. specialfolder. system );

// Bind system process
Private   Void Bindprocess ()
{
Try
{
System. Diagnostics. Process [] PS
= System. Diagnostics. process. getprocesses ();

Foreach (System. Diagnostics. PROCESS p In PS)
{
// The "system" and "idle" processes have no modules associated with the process, so they cannot go through the complete path of the module.
If (P. processname. tolower () ! =   " System "   && P. processname. tolower () ! =   " Idle " )
{
// Process name, physical memory, path
This . Listbox1.items. Add (P. processname +   " \ T "   + P. workingset64.tostring () +   " \ T "   + P. mainmodule. filename );
}
Else
{
// Process name, physical memory
This . Listbox1.items. Add (P. processname +   " \ T "   + P. workingset64.tostring ());
}

Text =   " Total processes: "   + PS. length. tostring ();
}
}
Catch (Exception exc)
{
MessageBox. Show (EXC. Message );
}
}

// Open a text file
Private   Void Opennotepad ()
{
// DeclareProgramInformation
System. Diagnostics. processstartinfo info =   New System. Diagnostics. processstartinfo ();

//Set external program name
Info. filename= "Notepad.exe";

// set the Startup menu for the program to test.txt
info. arguments = " test.txt " ;

//Set the external program working directory to c :\
Info. workingdirectory= "C :\\";

//Declare a program class
System. Diagnostics. Process proc;

Try
{
// Start external program
Proc = System. Diagnostics. process. Start (Info );
}
Catch (System. componentmodel. win32exception exc)
{
MessageBox. Show (
" The system cannot find the specified program file. \ R {0} " , Exc. Message );
}
}

// To disable the system service, you must reference the namespace system. serviceprocess.
Private   Void Stopservice ( String Servecename)
{
Try
{
System. serviceprocess. servicecontroller SC
=   New System. serviceprocess. servicecontroller (servecename );
If (SC. Status = System. serviceprocess. servicecontrollerstatus. Running)
{
SC. Stop ();
}
}
Catch (exception exc)
{< br> MessageBox. show (EXC. message);
}< BR >}

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.