




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、用WMI獲取遠(yuǎn)程系統(tǒng)信息WMI(Windows管理規(guī)范:Windows Management Instrumentation)是Microsoft基于Web的企業(yè)管理(WBEM)的實(shí)現(xiàn),同時也是一種基于標(biāo)準(zhǔn)的系統(tǒng)管理接口。WMI是一種輕松獲取系統(tǒng)信息的強(qiáng)大工具, 而且不依賴IPC$。 我把zzzevazzz的rs系列的幾個腳本用C寫了一遍,可以查/殺進(jìn)程、列舉系統(tǒng)信息、列舉/停止/啟動服務(wù)、注銷用戶登陸/重啟目標(biāo)/關(guān)機(jī)/斷電、列舉用戶信息。WMI的應(yīng)用遠(yuǎn)不止這些,更多功能等你挖掘了。后附源代碼(ps:代碼結(jié)構(gòu)很差,將就著看吧)。 另:由于是用C寫的,所以需要.NET Framework 的支持
2、。 ftp:.1incomingWMImwmi.exe .NET Framework安裝文件: ftp:.1incomingWMINET 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 myld");
3、0;Console.WriteLine(); Console.WriteLine("Usage: "); Console.WriteLine(" -pslist <IP> <Account> <Password> ->List processes."); Console.WriteLine(" -pskill <IP> <Account> <Password> <PID> ->K
4、ill process."); Console.WriteLine(" -osinfo <IP> <Account> <Password> ->Show SystemInfo."); Console.WriteLine(" -shut <IP> <Account> <Password> ->Shutdowm system."); Console.WriteLine(" -svclist <IP>
5、; <Account> <Password> ->List service."); Console.WriteLine(" -startsvc <IP> <Account> <Password> <SvcName> ->Start a service."); Console.WriteLine(" -stopsvc <IP> <Account> <Password> <SvcName
6、> ->Stop a service."); Console.WriteLine(" -userlist <IP> <Account> <Password> ->Show all users."); Console.WriteLine(); / 應(yīng)用程序的主入口點(diǎn)。 public static void Main(string args) if ( args.Length < 4 )
7、; usage(); Environment.Exit(0); if( args0 = "-pslist") ConnectionOptions Conn = new ConnectionOptions(); Conn.Username =args2; if(args3="NULL")
8、160; Conn.Password ="" else Conn.Password =args3; ManagementScope ms = new ManagementScope( ""+args1+"rootcimv2", Conn ); try
9、0; ms.Connect(); ObjectQuery Query = new ObjectQuery("SELECT ProcessId,Name,ExecutablePath FROM Win32_Process"); ManagementObjectSearcher link = new ManagementObjectSearcher(ms,Query); ManagementObjectCollection C
10、ollection = link.Get(); Console.WriteLine(); Console.WriteLine("PID Name ExecutablePath"); foreach (ManagementObject Process in Collection) Console.WriteLine( Conv
11、ert.ToString(Process"ProcessId").PadRight(6)+ Convert.ToString(Process"Name").PadRight(20)+Process"ExecutablePath" ); Console.WriteLine(); catch(Ex
12、ception exObj) Console.WriteLine(); Console.WriteLine("Failed! Error code: "+exObj.Message); Console.WriteLine(); / END -pslist else if( args0 = "-pski
13、ll" ) if ( args.Length != 5 ) usage(); Environment.Exit(0); try ConnectionOptions Conn = new ConnectionOptions();
14、60; Conn.Username =args2; if(args3="NULL") Conn.Password ="" else Conn.Password =args3; /string ProName = args4
15、; ManagementScope ms = new ManagementScope( "" + args1 + "rootcimv2", Conn); ms.Connect(); ObjectQuery Query = new ObjectQuery("SELECT * FROM Win32_Process");
16、160;ManagementObjectSearcher link = new ManagementObjectSearcher(ms,Query); ManagementObjectCollection Collection = link.Get(); foreach (ManagementObject Process in Collection) if ( Convert.ToStrin
17、g(Process"ProcessId") = args4 ) string Tparas = "1" Process.InvokeMethod("Terminate", Tparas); Console.WriteLine();
18、60; Console.WriteLine("Kill process 0 Successful!", Process"Name" ); catch(Exception exObj)
19、60; Console.WriteLine(); Console.WriteLine("Failed! Error code: "+exObj.Message ); Console.WriteLine(); /END -pskill else if (args0 = "-osinfo")
20、160; ConnectionOptions Conn = new ConnectionOptions(); Conn.Username =args2; if(args3="NULL") Conn.Password ="" else Conn.Password =args3; &
21、#160; ManagementScope ms = new ManagementScope( "" + args1 + "rootcimv2", Conn); try /Win32_ComputerSystem ms.Connect(); ObjectQuery Query = new ObjectQuery("SEL
22、ECT Name,UserName,Domain,DomainRole FROM Win32_ComputerSystem"); ManagementObjectSearcher link = new ManagementObjectSearcher(ms,Query); ManagementObjectCollection Collection = link.Get(); foreach (ManagementObject OsInfo i
23、n Collection) Console.WriteLine(); Console.WriteLine("OS Info:"); Console.WriteLine(" Computer Name : "+ OsInfo"Name" ); Cons
24、ole.WriteLine(" User Name : "+ OsInfo"UserName" ); Console.WriteLine(" Domain : "+ OsInfo"Domain" ); Console.Write(" Domain Role : "); switch(Convert.ToInt32( O
25、sInfo"DomainRole" ) ) case 0: ne("Standalone Workstation"); break; case 1: Console.WriteLine(
26、"Member Workstation"); break; case 2: Console.WriteLine("Standalone Server"); break;
27、60;case 3: Console.WriteLine("Member Server"); break; case 4: Console.WriteLine("Backup Domain Controller");
28、60; break; case 5: Console.WriteLine("Primary Domain Controller"); break; default:
29、0; break; /Win32_OperatingSystem ms.Connect(); ObjectQuery Query1 = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
30、60;ManagementObjectSearcher link1 = new ManagementObjectSearcher(ms,Query1); ManagementObjectCollection Collection1 = link1.Get(); foreach (ManagementObject OsInfo1 in Collection1) Console.WriteLin
31、e(" Caption : "+ OsInfo1"Caption" ); Console.WriteLine(" Organization : "+ OsInfo1"Organization" ); Console.WriteLine(" RegisteredUser : "+ OsInfo1"RegisteredUser" ); &
32、#160; Console.WriteLine(" BuildType : "+ OsInfo1"BuildType" ); Console.WriteLine(" CSDVersion : "+ OsInfo1"CSDVersion" ); Console.WriteLine(" Version : "+ OsInfo1"Version&quo
33、t; ); Console.WriteLine(" ServicePack : "+ OsInfo1"ServicePackMajorVersion" +"."+ OsInfo1"ServicePackMinorVersion" ); Console.Write(" ProductSuite : " );
34、 switch( Convert.ToInt32( OsInfo1"OSProductSuite" ) ) case 1: Console.WriteLine("Small Business");
35、break; case 2: Console.WriteLine("Enterprise"); break; case 4: Console.WriteLine("BackO
36、ffice"); break; case 8: Console.WriteLine("Communication Server"); break; case 16:
37、0; Console.WriteLine("Terminal Server"); break; case 32: Console.WriteLine("Small Business (Restricted)");
38、 break; case 64: Console.WriteLine("Embedded NT"); break; case 128: C
39、onsole.WriteLine("Data Center"); break; default: break; Console.Write(" InstallDate : ");
40、60; string id = Convert.ToString(OsInfo1"InstallDate"); Console.WriteLine(id.Substring(0,4)+"/"+id.Substring(4,2)+"/"+id.Substring(6,2) +" "+id.Substring(8,2)+":"+ id.Substring(10,2) );
41、0; Console.WriteLine(" System Directory: "+ OsInfo1"SystemDirectory" ); Console.WriteLine(" WindowsDirectory: "+ OsInfo1"WindowsDirectory" ); Console.Wr
42、iteLine(" Boot Device : "+ OsInfo1"BootDevice" ); Console.WriteLine(" FreeMemory : "+ Convert.ToInt32( OsInfo1"FreePhysicalMemory")/1024+" MB" ); / Win32_Processor &
43、#160; Console.WriteLine(); Console.WriteLine("Processor Info :"); ms.Connect(); ObjectQuery Query2 = new ObjectQuery("SELECT * FROM Win32_Processor"); ManagementObjectSearch
44、er link2 = new ManagementObjectSearcher(ms,Query2); ManagementObjectCollection Collection2 = link2.Get(); foreach (ManagementObject ProcessorInfo in Collection2) Console.WriteLine(" Processors
45、Name : "+ ProcessorInfo"Name" ); Console.WriteLine(" CurClockSpeed : "+ ProcessorInfo"CurrentClockSpeed"+" MHz" ); Console.WriteLine(" Description : "+ ProcessorInfo"Description&qu
46、ot; ); Console.WriteLine(" Manufacturer : "+ ProcessorInfo"Manufacturer" ); /Win32_LogicalMemoryConfiguration Console.WriteLine(); Console.WriteLine(&quo
47、t;Memory Info :"); ms.Connect(); ObjectQuery Query3 = new ObjectQuery("SELECT TotalPhysicalMemory FROM Win32_LogicalMemoryConfiguration"); ManagementObjectSearcher link3 = new ManagementObjectSearcher(ms,Query3);
48、 ManagementObjectCollection Collection3 = link3.Get(); foreach (ManagementObject MemoryInfo in Collection3) Console.WriteLine(" TotalMemory : "+Convert.ToInt32(MemoryInfo"TotalPhysica
49、lMemory")/1024+" MB" ); /Win32_BIOS Console.WriteLine(); Console.WriteLine("BIOS Info :"); ms.Connect(); ObjectQuery Query4 = new
50、ObjectQuery("SELECT Description,Version,Manufacturer FROM Win32_BIOS"); ManagementObjectSearcher link4 = new ManagementObjectSearcher(ms,Query4); ManagementObjectCollection Collection4 = link4.Get(); foreach (Managemen
51、tObject BIOSInfo in Collection4) Console.WriteLine(" Description : "+ BIOSInfo"Description" ); Console.WriteLine(" Version : "+ BIOSInfo"Version" );
52、160;Console.WriteLine(" Manufacturer : "+ BIOSInfo"Manufacturer" ); /Win32_DisplayConfiguration Console.WriteLine(); Console.WriteLine("Display Configuration :");
53、0; ms.Connect(); ObjectQuery Query5 = new ObjectQuery("SELECT * FROM Win32_DisplayConfiguration"); ManagementObjectSearcher link5 = new ManagementObjectSearcher(ms,Query5); ManagementObjectCollection Collect
54、ion5 = link5.Get(); foreach (ManagementObject DisInfo in Collection5) e(" Caption : "+ DisInfo"Caption" ); Console.WriteLine(" DeviceName : "+ DisInfo"DeviceName" );
55、60; Console.WriteLine(" DriverVersion : "+ DisInfo"DriverVersion" ); Console.WriteLine(" DispFrequency : "+ DisInfo"DisplayFrequency" +" Hz" ); Console.WriteLine(" Bits Per P
56、el : "+ DisInfo"BitsPerPel" +" Bits" ); Console.WriteLine(" Pels : "+DisInfo"PelsWidth"+" X "+DisInfo"PelsHeight" ); /Win32_DiskDrive
57、0;Console.WriteLine(); Console.WriteLine("Disk Info :"); ms.Connect(); ObjectQuery Query6 = new ObjectQuery("SELECT * FROM Win32_DiskDrive"); ManagementObjectSearcher link6 = new Manag
58、ementObjectSearcher(ms,Query6); ManagementObjectCollection Collection6 = link6.Get(); foreach (ManagementObject DiskInfo in Collection6) Console.WriteLine(" DeviceID : "+ DiskInfo"De
59、viceID" ); Console.WriteLine(" Caption : "+ DiskInfo"Caption" ); Console.WriteLine(" Interface Type : "+ DiskInfo"InterfaceType" ); Console.WriteLine(" SCSI Bus
60、 : "+ DiskInfo"SCSIBus" ); Console.WriteLine(" SCSI Port : "+ DiskInfo"SCSIPort" ); Console.WriteLine(" SectorsPerTrack : "+ DiskInfo"SectorsPerTrack" ); C
61、onsole.WriteLine(" Partitions : "+ DiskInfo"Partitions" ); Console.WriteLine(" Size : "+ Convert.ToInt64(DiskInfo"Size")/1000000000 +" GB"); /Win32_LogicalDisk
62、; Console.WriteLine(); Console.WriteLine(" Volume Type Size / Free"); ms.Connect(); ObjectQuery Query7 = new ObjectQuery("SELECT * FROM Win32_LogicalDisk"); ManagementObject
63、Searcher link7 = new ManagementObjectSearcher(ms,Query7); ManagementObjectCollection Collection7 = link7.Get(); foreach (ManagementObject DiskInfo1 in Collection7) Console.Write( " "+Conv
64、ert.ToString(DiskInfo1"Caption").PadRight(8) ); switch(Convert.ToInt16(DiskInfo1"DriveType") ) case 2: Console.WriteLine("Removable Disk
65、 "); break; case 3: Console.Write("Local Disk "); Console.Write( Convert.ToString(DiskInfo1"").PadRight(15) );
66、160; Console.Write( Convert.ToInt64(DiskInfo1"Size")/1000000+"MB Total "); Console.WriteLine( Convert.ToInt64(DiskInfo1"FreeSpace")/1000000+"MB Free"); &
67、#160; break; case 4: Console.WriteLine("Network Drive"); break; case 5: Console.WriteLi
68、ne("CD-ROM"); break; case 6: Console.WriteLine("RAM Disk"); break; default:
69、 break; catch(Exception exObj) Console.WriteLine(); Console.WriteLine("Failed. Error code : "+e
70、xObj.Message); / END -psinfo else if (args0 = "-shut") if ( args.Length < 5 ) Console.WriteLine();
71、0; Console.WriteLine(" MWmi -shut <IP> <Account> <Password> <logout|reboot|shutdown|poweroff>" ); Environment.Exit(0); try ConnectionOptions Conn = new Conne
72、ctionOptions(); Conn.Username =args2; if(args3="NULL") Conn.Password ="" else Conn.Password =args3; Mana
73、gementScope ms = new ManagementScope( ""+args1+"rootcimv2", Conn ); ms.Connect(); ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_OperatingSystem"); ManagementObjectSearcher link = new Mana
74、gementObjectSearcher(ms,query); ManagementObjectCollection Collection = link.Get(); switch( args4 ) case "logout": foreach( ManagementObject choise in
75、Collection ) string ss = "0" choise.InvokeMethod("Win32Shutdown",ss); Console.WriteLin
76、e(); Console.WriteLine("Logout Successful!"); break; case "shutdown": foreach( ManagementObject choise in Collection )
77、; string ss = "1" choise.InvokeMethod("Win32Shutdown",ss); Console.WriteLine(); &
78、#160;Console.WriteLine("Shutdown Successful!"); break; case "reboot": foreach( ManagementObject choise in Collection )
79、0; string ss = "2" choise.InvokeMethod("Win32Shutdown",ss); Console.WriteLine(); Console.WriteLine("Reboot
80、Successful!"); break; case "poweroff": foreach( ManagementObject choise in Collection ) string ss = &quo
81、t;8" choise.InvokeMethod("Win32Shutdown",ss); Console.WriteLine(); Console.WriteLine("PowerOff Successful!");
82、160; break; default : Console.WriteLine(); Console.WriteLine("Input Error!"); Environment.Exit(0);
83、; break; catch(Exception exObj) Console.WriteLine(); Console.WriteLine("Failed. Error code : "+exObj.
84、Message); / END -shut else if (args0 = "-svclist") try ConnectionOptions Conn = new ConnectionOptions(); Conn.Username =args2;
85、60;if(args3="NULL") Conn.Password ="" else Conn.Password =args3; ManagementScope ms = new ManagementScope(""+args1+"ro
86、otcimv2", Conn ); ms.Connect(); ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_Service"); ManagementObjectSearcher link = new ManagementObjectSearcher(ms,query); ManagementObjectC
87、ollection Collection = link.Get(); foreach(ManagementObject service in Collection) Console.WriteLine(); Console.WriteLine("ServiceName : "+ service"Name");
88、60; Console.WriteLine("DisplayName : "+ service"DisplayName"); Console.WriteLine("State : "+ service"State"); Console.WriteLine("StartMode : "+ service"Star
89、tMode"); Console.WriteLine("ServiceType : "+ service"ServiceType"); Console.WriteLine("PathName : "+ service"PathName"); catch
90、(Exception exObj) Console.WriteLine(); ); /END svclist else if (args0 = "-stopsvc") if ( args.Length != 5 ) usage(); &
91、#160; Environment.Exit(0); try ConnectionOptions Conn = new ConnectionOptions(); Conn.Username =args2; if(args3="NULL")
92、 Conn.Password ="" else Conn.Password =args3; ManagementScope ms = new ManagementScope( "" + args1 + "rootcimv2", Conn); ms.Connect();
93、160; ObjectQuery Query = new ObjectQuery("SELECT * FROM Win32_Service"); ManagementObjectSearcher link = new ManagementObjectSearcher(ms,Query); ManagementObjectCollection Collection = link.Get(); fore
94、ach (ManagementObject service in Collection) if ( Convert.ToString( service"Name" ) = args4 ) string Tparas = "1" service.
95、InvokeMethod("StopService", Tparas); Console.WriteLine(); Console.WriteLine("Stop Service "+service"Name" +" Successful!");
96、160; catch(Exception exObj) Console.WriteLine(); Console.WriteLine("Failed. Error code : "+exObj.Message); else if (args0 = "-startsvc")
97、160; if ( args.Length != 5 ) usage(); Environment.Exit(0); try ConnectionOptions Conn = new ConnectionOptions();
98、0;Conn.Username =args2; if(args3="NULL") Conn.Password ="" else Conn.Password =args3; ManagementScope ms = new ManagementScope( "" + args1 + "rootcimv2", Conn); ms.Connect(); ObjectQuery Query = new ObjectQuery("SELECT * FROM
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 節(jié)水技術(shù)的推廣與應(yīng)用計(jì)劃
- 確保企業(yè)形象的管理措施計(jì)劃
- 進(jìn)口醫(yī)療器械使用與管理計(jì)劃
- 增強(qiáng)社區(qū)兒童保護(hù)意識的個人方案計(jì)劃
- 健身教練技能提升計(jì)劃
- 班主任對學(xué)生品德培養(yǎng)的貢獻(xiàn)計(jì)劃
- 榮格游戲治療
- 《貴州恒睿礦業(yè)有限公司福泉市龍昌鎮(zhèn)順意煤礦(兼并重組)礦產(chǎn)資源綠色開發(fā)利用方案(三合一)》評審意見
- 檔案基本知識培訓(xùn)課件
- 第八章 走進(jìn)國家第一節(jié)日本(第1課時)教學(xué)設(shè)計(jì)2023-2024學(xué)年下學(xué)期七年級地理下冊同步課堂系列(湘教版)
- 2024年湖南科技職業(yè)學(xué)院高職單招語文歷年參考題庫含答案解析
- 《性病防治知識講座》課件
- 定額〔2025〕2號文-關(guān)于發(fā)布2020版電網(wǎng)技術(shù)改造及檢修工程概預(yù)算定額2024年下半年價格
- 2024年河南省中職對口升學(xué)高考語文試題真題(原卷版)
- 卵巢囊腫護(hù)理病例討論
- 《無線局域網(wǎng)組建》課件-0無線課程概述
- 拉薩市2025屆高三第一次聯(lián)考(一模)語文試卷(含答案解析)
- 危險品運(yùn)輸行業(yè)可行性分析報告
- 2024解析:第八章牛頓第一定律、二力平衡-講核心(解析版)
- 《勞動法與勞動關(guān)系》課件
- 2025陜西延長石油(集團(tuán))有限責(zé)任公司招聘(1881人)筆試備考題庫及答案解析
評論
0/150
提交評論