try

{

ConnectionOptions connection = new ConnectionOptions();

connection.Username = userNameBox.Text;

connection.Password = passwordBox.Text;

connection.Authority = "ntlmdomain:Finance123";

ManagementScope scope = new ManagementScope(

"\\dell417\root\CIMV2", connection);

scope.Connect();

ObjectQuery query= new ObjectQuery(

"SELECT * FROM Win32_Battery");

ManagementObjectSearcher searcher =

new ManagementObjectSearcher(scope, query);

foreach (ManagementObject queryObj in searcher.Get())

{

Console.WriteLine("");

Console.WriteLine("Win32_Battery instance");

Console.WriteLine("");

Console.WriteLine("Availability: {0}", queryObj["Availability"]);

Console.WriteLine("BatteryRechargeTime: {0}", queryObj["BatteryRechargeTime"]);

Console.WriteLine("BatteryStatus: {0}", queryObj["BatteryStatus"]);

Console.WriteLine("Caption: {0}", queryObj["Caption"]);

Console.WriteLine("Chemistry: {0}", queryObj["Chemistry"]);

Console.WriteLine("ConfigManagerErrorCode: {0}", queryObj["ConfigManagerErrorCode"]);

Console.WriteLine("ConfigManagerUserConfig: {0}", queryObj["ConfigManagerUserConfig"]);

Console.WriteLine("CreationClassName: {0}", queryObj["CreationClassName"]);

Console.WriteLine("Description: {0}", queryObj["Description"]);

Console.WriteLine("DesignCapacity: {0}", queryObj["DesignCapacity"]);

Console.WriteLine("DesignVoltage: {0}", queryObj["DesignVoltage"]);

Console.WriteLine("DeviceID: {0}", queryObj["DeviceID"]);

Console.WriteLine("ErrorCleared: {0}", queryObj["ErrorCleared"]);

Console.WriteLine("ErrorDescription: {0}", queryObj["ErrorDescription"]);

Console.WriteLine("EstimatedChargeRemaining: {0}", queryObj["EstimatedChargeRemaining"]);

Console.WriteLine("EstimatedRunTime: {0}", queryObj["EstimatedRunTime"]);

Console.WriteLine("ExpectedBatteryLife: {0}", queryObj["ExpectedBatteryLife"]);

Console.WriteLine("ExpectedLife: {0}", queryObj["ExpectedLife"]);

Console.WriteLine("FullChargeCapacity: {0}", queryObj["FullChargeCapacity"]);

Console.WriteLine("InstallDate: {0}", queryObj["InstallDate"]);

Console.WriteLine("LastErrorCode: {0}", queryObj["LastErrorCode"]);

Console.WriteLine("MaxRechargeTime: {0}", queryObj["MaxRechargeTime"]);

Console.WriteLine("Name: {0}", queryObj["Name"]);

Console.WriteLine("PNPDeviceID: {0}", queryObj["PNPDeviceID"]);

if(queryObj["PowerManagementCapabilities"] == null)

Console.WriteLine("PowerManagementCapabilities: {0}", queryObj["PowerManagementCapabilities"]);

else

{

UInt16[] arrPowerManagementCapabilities = (UInt16[])(queryObj["PowerManagementCapabilities"]);

foreach (UInt16 arrValue in arrPowerManagementCapabilities)

{

Console.WriteLine("PowerManagementCapabilities: {0}", arrValue);

}

}

Console.WriteLine("PowerManagementSupported: {0}", queryObj["PowerManagementSupported"]);

Console.WriteLine("SmartBatteryVersion: {0}", queryObj["SmartBatteryVersion"]);

Console.WriteLine("Status: {0}", queryObj["Status"]);

Console.WriteLine("StatusInfo: {0}", queryObj["StatusInfo"]);

Console.WriteLine("SystemCreationClassName: {0}", queryObj["SystemCreationClassName"]);

Console.WriteLine("SystemName: {0}", queryObj["SystemName"]);

Console.WriteLine("TimeOnBattery: {0}", queryObj["TimeOnBattery"]);

Console.WriteLine("TimeToFullCharge: {0}", queryObj["TimeToFullCharge"]);

}

Close();

}

catch(ManagementException err)

{

MessageBox.Show("An error occurred while querying for WMI data: " + err.Message);

}

catch(System.UnauthorizedAccessException unauthorizedErr)

{

MessageBox.Show("Connection error (user name or password might be incorrect): " + unauthorizedErr.Message);

}

Advertisements