




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、用WMI获取远程系统信息WMI(Windows管理规范:Windows Management Instrumentation)是Microsoft基于Web的企业管理(WBEM)的实现,同时也是一种基于标准的系统管理接口。WMI是一种轻松获取系统信息的强大工具, 而且不依赖IPC$。 我把zzzevazzz的rs系列的几个脚本用C写了一遍,可以查/杀进程、列举系统信息、列举/停止/启动服务、注销用户登陆/重启目标/关机/断电、列举用户信息。WMI的应用远不止这些,更多功能等你挖掘了。后附源代码(ps:代码结构很差,将就着看吧)。 另:由于是用C写的,所以需要.NET Framework 的支持
2、。 编译好的可执行文件: ftp:incomingWMImwmi.exe .NET Framework安装文件: ftp:incomingWMINET Framework v1.0.3705 Setup.exe -cut here- using System; using System.Management; class MWmi /帮助 public static void usage() Console.WriteLine(); Console.WriteLine("MWmi v0.1 , by
3、myld"); Console.WriteLine(); Console.WriteLine("Usage: "); Console.WriteLine(" -pslist <IP> <Account> <Password> ->List processes."); Console.WriteLine(" -pskill <IP> <Account> <Password
4、> <PID> ->Kill process."); Console.WriteLine(" -osinfo <IP> <Account> <Password> ->Show SystemInfo."); Console.WriteLine(" -shut <IP> <Account> <Password> ->Shutdowm system."); Console.WriteLine(&q
5、uot; -svclist <IP> <Account> <Password> ->List service."); Console.WriteLine(" -startsvc <IP> <Account> <Password> <SvcName> ->Start a service."); Console.WriteLine(" -stopsvc <IP> <Account> <P
6、assword> <SvcName> ->Stop a service."); Console.WriteLine(" -userlist <IP> <Account> <Password> ->Show all users."); Console.WriteLine(); / 应用程序的主入口点。 public static void Main(string args) if ( args.Length <
7、 4 ) usage(); Environment.Exit(0); if( args0 = "-pslist") ConnectionOptions Conn = new ConnectionOptions(); Conn.Username =args2; if(arg
8、s3="NULL") Conn.Password ="" else Conn.Password =args3; ManagementScope ms = new ManagementScope( ""+args1+"rootcimv2", Conn ); try
9、 ms.Connect(); ObjectQuery Query = new ObjectQuery("SELECT ProcessId,Name,ExecutablePath FROM Win32_Process"); ManagementObjectSearcher link = new ManagementObjectSearcher(ms,Query); Manag
10、ementObjectCollection Collection = link.Get(); Console.WriteLine(); Console.WriteLine("PID Name ExecutablePath"); foreach (ManagementObject Process in Collection)
11、Console.WriteLine( Convert.ToString(Process"ProcessId").PadRight(6)+ Convert.ToString(Process"Name").PadRight(20)+Process"ExecutablePath" ); Console.WriteLine();
12、60; catch(Exception exObj) Console.WriteLine(); Console.WriteLine("Failed! Error code: "+exObj.Message); Console.WriteLine(); / END -pslist else
13、if( args0 = "-pskill" ) if ( args.Length != 5 ) usage(); Environment.Exit(0); try ConnectionOptions Conn = new C
14、onnectionOptions(); Conn.Username =args2; if(args3="NULL") Conn.Password ="" else Conn.Password =args3;
15、/string ProName = args4; ManagementScope ms = new ManagementScope( "" + args1 + "rootcimv2", Conn); ms.Connect(); ObjectQuery Query = new ObjectQuery("SELECT * FROM Win32_Process"
16、); ManagementObjectSearcher link = new ManagementObjectSearcher(ms,Query); ManagementObjectCollection Collection = link.Get(); foreach (ManagementObject Process in Collection)
17、60;if ( Convert.ToString(Process"ProcessId") = args4 ) string Tparas = "1" Process.InvokeMethod("Terminate", Tparas); Console.Write
18、Line(); Console.WriteLine("Kill process 0 Successful!", Process"Name" ); catch(Exception exObj)
19、 Console.WriteLine(); Console.WriteLine("Failed! Error code: "+exObj.Message ); Console.WriteLine(); /END -pskill else if (args0 = "-osinfo")
20、0; ConnectionOptions Conn = new ConnectionOptions(); Conn.Username =args2; if(args3="NULL") Conn.Password ="" else Conn.P
21、assword =args3; ManagementScope ms = new ManagementScope( "" + args1 + "rootcimv2", Conn); try /Win32_ComputerSystem ms.Connect(); ObjectQuery Query = ne
22、w ObjectQuery("SELECT Name,UserName,Domain,DomainRole FROM Win32_ComputerSystem"); ManagementObjectSearcher link = new ManagementObjectSearcher(ms,Query); ManagementObjectCollection Collection = link.Get(); foreach (Ma
23、nagementObject OsInfo in Collection) Console.WriteLine(); Console.WriteLine("OS Info:"); Console.WriteLine(" Computer Name : "+ OsInfo"Name" );
24、; Console.WriteLine(" User Name : "+ OsInfo"UserName" ); Console.WriteLine(" Domain : "+ OsInfo"Domain" ); Console.Write(" Domain Role : "); sw
25、itch(Convert.ToInt32( OsInfo"DomainRole" ) ) case 0: Console.WriteLine("Standalone Workstation"); break;
26、 case 1: Console.WriteLine("Member Workstation"); break; case 2: Console.WriteLine("Standalone Server");
27、160; break; case 3: Console.WriteLine("Member Server"); break; case 4:
28、0; Console.WriteLine("Backup Domain Controller"); break; case 5: Console.WriteLine("Primary Domain Controller");
29、 break; default: break; /Win32_OperatingSystem ms.Connect(); ObjectQuery Query1 = new Obj
30、ectQuery("SELECT * FROM Win32_OperatingSystem"); ManagementObjectSearcher link1 = new ManagementObjectSearcher(ms,Query1); ManagementObjectCollection Collection1 = link1.Get(); foreach (ManagementObject OsInfo1 in Coll
31、ection1) Console.WriteLine(" Caption : "+ OsInfo1"Caption" ); Console.WriteLine(" Organization : "+ OsInfo1"Organization" ); Console.WriteLine(&q
32、uot; RegisteredUser : "+ OsInfo1"RegisteredUser" ); Console.WriteLine(" BuildType : "+ OsInfo1"BuildType" ); Console.WriteLine(" CSDVersion : "+ OsInfo1"CSDVersion" );
33、; Console.WriteLine(" Version : "+ OsInfo1"Version" ); Console.WriteLine(" ServicePack : "+ OsInfo1"ServicePackMajorVersion" +"."+ OsInfo1"ServicePackMinorVersion"
34、; ); Console.Write(" ProductSuite : " ); switch( Convert.ToInt32( OsInfo1"OSProductSuite" ) ) case 1: Console.W
35、riteLine("Small Business"); break; case 2: Console.WriteLine("Enterprise"); break;
36、;case 4: Console.WriteLine("BackOffice"); break; case 8: Console.WriteLine("Communication Server");
37、 break; case 16: Console.WriteLine("Terminal Server"); break; case 32:
38、0;Console.WriteLine("Small Business (Restricted)"); break; case 64: Console.WriteLine("Embedded NT"); break;
39、60; case 128: Console.WriteLine("Data Center"); break; default: break;
40、60; Console.Write(" InstallDate : "); string id = Convert.ToString(OsInfo1"InstallDate"); Console.WriteLine(id.Substring(0,4)+"/"+id.Substring(4,2)+"/"+id.Substring(6,2)
41、+" "+id.Substring(8,2)+":"+ id.Substring(10,2) ); Console.WriteLine(" System Directory: "+ OsInfo1"SystemDirectory" ); Console.WriteLine(" WindowsDirectory: "+
42、 OsInfo1"WindowsDirectory" ); Console.WriteLine(" Boot Device : "+ OsInfo1"BootDevice" ); Console.WriteLine(" FreeMemory : "+ Convert.ToInt32( OsInfo1"FreePhysicalMemory")/1024+" MB&quo
43、t; ); / Win32_Processor Console.WriteLine(); Console.WriteLine("Processor Info :"); ms.Connect(); ObjectQuery Query2 = new ObjectQuery("SELE
44、CT * FROM Win32_Processor"); ManagementObjectSearcher link2 = new ManagementObjectSearcher(ms,Query2); ManagementObjectCollection Collection2 = link2.Get(); foreach (ManagementObject ProcessorInfo in Collection2)
45、0; Console.WriteLine(" ProcessorsName : "+ ProcessorInfo"Name" ); Console.WriteLine(" CurClockSpeed : "+ ProcessorInfo"CurrentClockSpeed"+" MHz" );
46、Console.WriteLine(" Description : "+ ProcessorInfo"Description" ); Console.WriteLine(" Manufacturer : "+ ProcessorInfo"Manufacturer" ); /Win32_LogicalMemoryConfiguration
47、; Console.WriteLine(); Console.WriteLine("Memory Info :"); ms.Connect(); ObjectQuery Query3 = new ObjectQuery("SELECT TotalPhysicalMemory FROM Win32_LogicalMemoryConfiguration");
48、 ManagementObjectSearcher link3 = new ManagementObjectSearcher(ms,Query3); ManagementObjectCollection Collection3 = link3.Get(); foreach (ManagementObject MemoryInfo in Collection3) Console.Wr
49、iteLine(" TotalMemory : "+Convert.ToInt32(MemoryInfo"TotalPhysicalMemory")/1024+" MB" ); /Win32_BIOS Console.WriteLine(); Console.WriteLine("BIOS Info :"); &
50、#160; ms.Connect(); ObjectQuery Query4 = new ObjectQuery("SELECT Description,Version,Manufacturer FROM Win32_BIOS"); ManagementObjectSearcher link4 = new ManagementObjectSearcher(ms,Query4); ManagementObject
51、Collection Collection4 = link4.Get(); foreach (ManagementObject BIOSInfo in Collection4) Console.WriteLine(" Description : "+ BIOSInfo"Description" ); Console.WriteLine(&q
52、uot; Version : "+ BIOSInfo"Version" ); Console.WriteLine(" Manufacturer : "+ BIOSInfo"Manufacturer" ); /Win32_DisplayConfiguration Console.WriteLine();
53、0; Console.WriteLine("Display Configuration :"); ms.Connect(); ObjectQuery Query5 = new ObjectQuery("SELECT * FROM Win32_DisplayConfiguration"); ManagementObjectSearcher link5 = new ManagementObjec
54、tSearcher(ms,Query5); ManagementObjectCollection Collection5 = link5.Get(); foreach (ManagementObject DisInfo in Collection5) Console.WriteLine(" Caption : "+ DisInfo"Caption" )
55、; Console.WriteLine(" DeviceName : "+ DisInfo"DeviceName" ); Console.WriteLine(" DriverVersion : "+ DisInfo"DriverVersion" ); Console.WriteLine(" DispFrequency : &qu
56、ot;+ DisInfo"DisplayFrequency" +" Hz" ); Console.WriteLine(" Bits Per Pel : "+ DisInfo"BitsPerPel" +" Bits" ); Console.WriteLine(" Pels : "+DisInfo"PelsWidth"+" X &q
57、uot;+DisInfo"PelsHeight" ); /Win32_DiskDrive Console.WriteLine(); Console.WriteLine("Disk Info :"); ms.Connect(); ObjectQuery Query6 =
58、new ObjectQuery("SELECT * FROM Win32_DiskDrive"); ManagementObjectSearcher link6 = new ManagementObjectSearcher(ms,Query6); ManagementObjectCollection Collection6 = link6.Get(); foreach (ManagementObject DiskInfo in Co
59、llection6) Console.WriteLine(" DeviceID : "+ DiskInfo"DeviceID" ); Console.WriteLine(" Caption : "+ DiskInfo"Caption" ); Console.WriteLine("
60、 Interface Type : "+ DiskInfo"InterfaceType" ); Console.WriteLine(" SCSI Bus : "+ DiskInfo"SCSIBus" ); Console.WriteLine(" SCSI Port : "+ DiskInfo"SCSIPort" ); &
61、#160;Console.WriteLine(" SectorsPerTrack : "+ DiskInfo"SectorsPerTrack" ); Console.WriteLine(" Partitions : "+ DiskInfo"Partitions" ); Console.WriteLine(" Size : "+ Convert.ToInt64(DiskInfo&
62、quot;Size")/1000000000 +" GB"); /Win32_LogicalDisk Console.WriteLine(); Console.WriteLine(" Volume Type Size / Free"); ms.Connect();
63、60;ObjectQuery Query7 = new ObjectQuery("SELECT * FROM Win32_LogicalDisk"); ManagementObjectSearcher link7 = new ManagementObjectSearcher(ms,Query7); ManagementObjectCollection Collection7 = link7.Get(); foreach (Manag
64、ementObject DiskInfo1 in Collection7) Console.Write( " "+Convert.ToString(DiskInfo1"Caption").PadRight(8) ); switch(Convert.ToInt16(DiskInfo1"DriveType") )
65、; case 2: Console.WriteLine("Removable Disk "); break; case 3: Console.Write("Local Dis
66、k "); Console.Write( Convert.ToString(DiskInfo1"").PadRight(15) ); Console.Write( Convert.ToInt64(DiskInfo1"Size")/1000000+"MB Total "); Co
67、nsole.WriteLine( Convert.ToInt64(DiskInfo1"FreeSpace")/1000000+"MB Free"); break; case 4: Console.WriteLine("Network Drive");
68、 break; case 5: Console.WriteLine("CD-ROM"); break; case 6: Console.WriteLi
69、ne("RAM Disk"); break; default: break; catch(Exception exObj)
70、60; Console.WriteLine(); Console.WriteLine("Failed. Error code : "+exObj.Message); / END -psinfo else if (args0 = "-shut")
71、; if ( args.Length < 5 ) Console.WriteLine(); Console.WriteLine(" MWmi -shut <IP> <Account> <Password> <logout|reboot|shutdown|poweroff>" ); Environment.E
72、xit(0); try ConnectionOptions Conn = new ConnectionOptions(); Conn.Username =args2; if(args3="NULL") Conn.P
73、assword ="" else Conn.Password =args3; ManagementScope ms = new ManagementScope( ""+args1+"rootcimv2", Conn ); ms.Connect(); ObjectQuery query = new
74、ObjectQuery("SELECT * FROM Win32_OperatingSystem"); ManagementObjectSearcher link = new ManagementObjectSearcher(ms,query); ManagementObjectCollection Collection = link.Get(); switch( args4 ) &
75、#160; case "logout": foreach( ManagementObject choise in Collection ) string ss = "0" choise.InvokeM
76、ethod("Win32Shutdown",ss); Console.WriteLine(); Console.WriteLine("Logout Successful!"); break; case &quo
77、t;shutdown": foreach( ManagementObject choise in Collection ) string ss = "1" choise.InvokeMethod("Win32Shutdown",ss);
78、 Console.WriteLine(); Console.WriteLine("Shutdown Successful!"); break; case "reboot":
79、 foreach( ManagementObject choise in Collection ) string ss = "2" choise.InvokeMethod("Win32Shutdown",ss);
80、; Console.WriteLine(); Console.WriteLine("Reboot Successful!"); break; case "poweroff": foreach( Managemen
81、tObject choise in Collection ) string ss = "8" choise.InvokeMethod("Win32Shutdown",ss);
82、0;Console.WriteLine(); Console.WriteLine("PowerOff Successful!"); break; default : Console.WriteLine();
83、; Console.WriteLine("Input Error!"); Environment.Exit(0); break; catch(Exception exObj) &
84、#160; Console.WriteLine(); Console.WriteLine("Failed. Error code : "+exObj.Message); / END -shut else if (args0 = "-svclist") try
85、60; ConnectionOptions Conn = new ConnectionOptions(); Conn.Username =args2; if(args3="NULL") Conn.Password ="" else Conn.Pa
86、ssword =args3; ManagementScope ms = new ManagementScope(""+args1+"rootcimv2", Conn ); ms.Connect(); ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_Service");
87、; ManagementObjectSearcher link = new ManagementObjectSearcher(ms,query); ManagementObjectCollection Collection = link.Get(); foreach(ManagementObject service in Collection) Console.Writ
88、eLine(); Console.WriteLine("ServiceName : "+ service"Name"); Console.WriteLine("DisplayName : "+ service"DisplayName"); Console.WriteLine("State : "+ serv
89、ice"State"); Console.WriteLine("StartMode : "+ service"StartMode"); Console.WriteLine("ServiceType : "+ service"ServiceType"); Console.WriteLine(&qu
90、ot;PathName : "+ service"PathName"); catch(Exception exObj) Console.WriteLine(); Console.WriteLine("Failed. Error code : "+exObj.Message);
91、 /END svclist else if (args0 = "-stopsvc") if ( args.Length != 5 ) usage(); Environment.Exit(0); try
92、 ConnectionOptions Conn = new ConnectionOptions(); Conn.Username =args2; if(args3="NULL") Conn.Password =""
93、160; else Conn.Password =args3; ManagementScope ms = new ManagementScope( "" + args1 + "rootcimv2", Conn); ms.Connect(); ObjectQuery Query = new ObjectQuery("SELECT * FROM Win32_S
94、ervice"); ManagementObjectSearcher link = new ManagementObjectSearcher(ms,Query); ManagementObjectCollection Collection = link.Get(); foreach (ManagementObject service in Collection)
95、60; if ( Convert.ToString( service"Name" ) = args4 ) string Tparas = "1" service.InvokeMethod("StopService", Tparas); Co
96、nsole.WriteLine(); Console.WriteLine("Stop Service "+service"Name" +" Successful!"); catch(Exception exObj)
97、160; Console.WriteLine(); Console.WriteLine("Failed. Error code : "+exObj.Message); else if (args0 = "-startsvc") if ( args.Length != 5 ) &
98、#160;usage(); Environment.Exit(0); try ConnectionOptions Conn = new ConnectionOptions(); Conn.Username =args2; if(args3="NULL") Conn.Password ="" else Conn.Password =args3; ManagementScope ms = new ManagementScope( "" + args1 + "rootcimv2", Conn
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 超神数学-高考数学总复习基础篇(一轮)(练习册)专题01集合(含答案或解析)
- 自动步枪斜角射击技巧
- 中国高校新文科发展报告
- 历史隋唐时期的民族交往与交融 课件 2024-2025学年统编版七年级历史下册
- 2025年乡村文化旅游与乡村旅游人才培养研究报告
- 2025年电商平台内容营销与种草经济在宠物医疗行业的互动营销报告
- 2025年海上风力发电场运维管理智能化技术创新路径研究报告
- 2025年特色农产品加工园区社会稳定风险评估与农村社会治理创新研究
- 数字化转型2025年制造业供应链协同管理供应链金融创新报告
- 外卖平台食品安全监管现状及发展趋势报告2025
- EHS专项施工EHS管理组织机构
- 2024年南安市国有资本投资运营有限责任公司招聘笔试冲刺题(带答案解析)
- T/CEC 143-2017 超高性能混凝土电杆完整
- MOOC 工程电磁场与波-浙江大学 中国大学慕课答案
- 清罐应急预案
- 《水泥熟料的组成》课件
- 草籽采购(牧草种子采购)投标方案(技术方案)
- 金融纠纷调解培训课件模板
- wedo2完整版本.0第一课拉力小车
- 超声检查健康宣教课件
- 广西创业担保贷款培训课件
评论
0/150
提交评论