// 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 >}