using System;
using System.Collections.Generic;
using System.Text;
using System.Management;
namespace GetSystemInfo
{
class GetSystemInfo
{
static void Main(string[] args)
{
if (1 != args.Length)
{
return;
}
//
// List Processes
string strComputerName = args[0];
string strScopePath = string.Format("\\\\{0}\\root\\cimv2", strComputerName);
ManagementScope scope = new ManagementScope(strScopePath);
scope.Connect();
ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_Process");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection colProcesses = searcher.Get();
foreach (ManagementObject oProcess in colProcesses)
{
Console.WriteLine("{0}\t{1}\t{2}", oProcess["ProcessId"], oProcess["Name"], oProcess["ExecutablePath"]);
}
//
// Registry
string strObjectPath = string.Format("\\\\{0}\\root\\DEFAULT:StdRegProv", strComputerName);
ManagementClass oReg = new ManagementClass(strObjectPath);
object[] methodArgs = {0x80000002, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", null};
object result = oReg.InvokeMethod("EnumValues", methodArgs);
string[] arrValues = (string[])methodArgs[2];
for (int i = 0; i < arrValues.Length; i++)
{
object[] methodArgs1 = { 0x80000002, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", arrValues[i], null};
object result1 = oReg.InvokeMethod("GetStringValue", methodArgs1);
Console.WriteLine("{0}\t{1}", arrValues[i], (string)methodArgs1[3]);
}
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Management;
namespace GetSystemInfo
{
class GetSystemInfo
{
static void Main(string[] args)
{
if (1 != args.Length)
{
return;
}
//
// List Processes
string strComputerName = args[0];
string strScopePath = string.Format("\\\\{0}\\root\\cimv2", strComputerName);
ManagementScope scope = new ManagementScope(strScopePath);
scope.Connect();
ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_Process");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection colProcesses = searcher.Get();
foreach (ManagementObject oProcess in colProcesses)
{
Console.WriteLine("{0}\t{1}\t{2}", oProcess["ProcessId"], oProcess["Name"], oProcess["ExecutablePath"]);
}
//
// Registry
string strObjectPath = string.Format("\\\\{0}\\root\\DEFAULT:StdRegProv", strComputerName);
ManagementClass oReg = new ManagementClass(strObjectPath);
object[] methodArgs = {0x80000002, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", null};
object result = oReg.InvokeMethod("EnumValues", methodArgs);
string[] arrValues = (string[])methodArgs[2];
for (int i = 0; i < arrValues.Length; i++)
{
object[] methodArgs1 = { 0x80000002, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", arrValues[i], null};
object result1 = oReg.InvokeMethod("GetStringValue", methodArgs1);
Console.WriteLine("{0}\t{1}", arrValues[i], (string)methodArgs1[3]);
}
}
}
}