引用:http://chinasf.cnblogs.com/archive/2005/05/26/162545.aspx
引用:http://qinfei.cnblogs.com/archive/2005/11/03/268233.aspx
//win32_logicaldisk
//导入dll:解决方案 ==> 引用 ==> 添加引用 ==> COM ==> System.Management.dll --C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322
using System;
using System.Management;
class disk //数据管理对象
{
public static void Main()
{
//创建 C: 的实例
ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"c:\"");
disk.Get();
Console.WriteLine("磁盘大小"+disk["Size"]+"bytes"); //打印C:大小,单位bytes
}
}
确定计算机名称或 IP 地址是物理计算机还是虚拟 IP 地址 CIMV2:Win32_ComputerSystem
在远程计算机上运行进程 CIMV2:Win32_Process
确定远程计算机中是否存在某个目录 CIMV2:Win32_Directory
停止/启动 IIS System.Diagnostics.Process
将程序集添加到全局程序集缓存 (GAC) System.Diagnostics.Process
注册和配置 GAM 组件 COMAdmin 目录 (COM 1.0)
创建 Web 站点 System.DirectoryServices.DirectoryEntry
计算家共享:select * from Win32_Share"
//可以用此方法来选择集合中的部份记录 "SELECT * FROM Win32_Service WHERE Name = 'ServiceName'",
"Win32_LogicalDisk" 类 //通过它我们可以查看到本地驱动器
ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * From Win32_LogicalDisk "); //查询
ManagementObjectCollection queryCollection = query.Get(); //Get获取集合并赋给 Collention
foreach ( ManagementObject mo in queryCollection) //偏历集合
{
Console.WriteLine("type:"+mo["DriveType"].ToString());
sConsole.WriteLine("Drive: " + mo["Name"].ToString()); //打印出所有驱动器
}
"Win32_Environment" 类 //环境变量
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" 类 //操作系统信息
Console.WriteLine( "操作系统: " + mo["Caption"]);
Console.WriteLine( "版本号: " + mo["Version"]);
Console.WriteLine( "制造商: " + mo["Manufacturer"]);
Console.WriteLine( "计算机名: " +mo["csname"]);
Console.WriteLine("Windows目录: " + mo["WindowsDirectory"]);
"Win32_Service" 类 //系统服务
//输出默认站点的目录结构
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);
}
}
引用:http://qinfei.cnblogs.com/archive/2005/11/03/268233.aspx
//win32_logicaldisk
//导入dll:解决方案 ==> 引用 ==> 添加引用 ==> COM ==> System.Management.dll --C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322
using System;
using System.Management;
class disk //数据管理对象
{
public static void Main()
{
//创建 C: 的实例
ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"c:\"");
disk.Get();
Console.WriteLine("磁盘大小"+disk["Size"]+"bytes"); //打印C:大小,单位bytes
}
}
确定计算机名称或 IP 地址是物理计算机还是虚拟 IP 地址 CIMV2:Win32_ComputerSystem
在远程计算机上运行进程 CIMV2:Win32_Process
确定远程计算机中是否存在某个目录 CIMV2:Win32_Directory
停止/启动 IIS System.Diagnostics.Process
将程序集添加到全局程序集缓存 (GAC) System.Diagnostics.Process
注册和配置 GAM 组件 COMAdmin 目录 (COM 1.0)
创建 Web 站点 System.DirectoryServices.DirectoryEntry
计算家共享:select * from Win32_Share"
//可以用此方法来选择集合中的部份记录 "SELECT * FROM Win32_Service WHERE Name = 'ServiceName'",
"Win32_LogicalDisk" 类 //通过它我们可以查看到本地驱动器
ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * From Win32_LogicalDisk "); //查询
ManagementObjectCollection queryCollection = query.Get(); //Get获取集合并赋给 Collention
foreach ( ManagementObject mo in queryCollection) //偏历集合
{
Console.WriteLine("type:"+mo["DriveType"].ToString());
sConsole.WriteLine("Drive: " + mo["Name"].ToString()); //打印出所有驱动器
}
"Win32_Environment" 类 //环境变量
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" 类 //操作系统信息
Console.WriteLine( "操作系统: " + mo["Caption"]);
Console.WriteLine( "版本号: " + mo["Version"]);
Console.WriteLine( "制造商: " + mo["Manufacturer"]);
Console.WriteLine( "计算机名: " +mo["csname"]);
Console.WriteLine("Windows目录: " + mo["WindowsDirectory"]);
"Win32_Service" 类 //系统服务
//输出默认站点的目录结构
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);
}
}