C # WMI Programming

Source: Internet
Author: User

 

// Win32_logicaldisk
// Import dll: solution ==> reference ==> add reference ==> com ==> system. Management. dll -- c: \ windows \ Microsoft. NET \ framework \ v1.1.4322
Using System;
Using System. Management;
Class Disk // Data management objects
{
Public   Static   Void Main ()
{
// Create a C: instance
Managementobject Disk =   New Managementobject ( " Win32_logicaldisk.deviceid = \ " C :\ "" );
Disk. Get ();
Console. writeline ( " Disk size " + Disk [ " Size " ] + " Bytes " ); // Print C: size, in bytes
}
}

 

Determine whether the computer name or IP address is a physical computer or virtual IP address cimv2: win32_computersystem
Run the process cimv2: win32_process on a remote computer
Check whether a directory cimv2: win32_directory exists in the remote computer.
Stop/Start IIS system. Diagnostics. Process
SetProgramSet added to Global Assembly Cache (GAC) system. Diagnostics. Process
Register and configure the GAM component comadmin directory (COM1.0)
Create a web site system. directoryservices. directoryentry

// You can use this method to select some records in the Set "select * From win32_service where name = 'servicename '",

" Win32_logicaldisk " Class // Through this we can view the local drive

Managementobjectsearcher Query =   New Managementobjectsearcher ( " Select * From win32_logicaldisk " ); // Query
Managementobjectcollection querycollection = Query. Get (); // Get gets the set and assigns it to collention
Foreach (Managementobject Mo In Querycollection) // Partial calendar set
{
Console. writeline ( " Type: " + Mo [ " Drivetype " ]. Tostring ());
Sconsole. writeline ( " Drive: "   + Mo [ " Name " ]. Tostring ()); // Print out All Drives
}

" Win32_environment " Class // Environment Variable
Using System;
Using System. Management;
Public   Class Enumerateinstances
{
Public   Static   Void Main ()
{
Selectquery Query =   New Selectquery ( " Win32_environment " );
Managementobjectsearcher searcher =   New Managementobjectsearcher (query );
Foreach (Managementbaseobject envvar In Searcher. Get ())
Console. writeline ( " Variable: {0}, value = {1} " , Envvar [ " Name " ], Envvar [ " Variablevalue " ]);
}
}

" Win32_operatingsystem " Class // Operating System Information
Console. writeline ( " Operating System: "   + Mo [ " Caption " ]);
Console. writeline ( " Version: "   + Mo [ " Version " ]);
Console. writeline ( " Manufacturer: "   + Mo [ " Manufacturer " ]);
Console. writeline ( " Computer Name: "   + Mo [ " Csname " ]);
Console. writeline ( " Windows directory: "   + Mo [ " Windows Directory " ]);

"Win32_service"Class//System Service

// Output the directory structure of the default site
Using System;
Using System. directoryservices;
Class Iisfolderlist
{
Static   Void Listfolder (directoryentry paraentry, Int Paraindent)
{
For ( Int I = Paraindent; I > 0 ; I -- )
Console. Write ( '   ' );
Console. writeline (paraentry. Name );
Paraindent ++ ;
Foreach (Directoryentry tempentry In Paraentry. Children)
Listfolder (tempentry, paraindent );
Paraentry. Dispose ();
}
Static   Void Main ( String [] ARGs)
{
Listfolder ( New Directoryentry ( " IIS: // localhost/w3svc/1/root " ), 0 );
}
}

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.