/// <summary> /// Timer elapsed => do something /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void timer_Elapsed(object sender, ElapsedEventArgs e) { ramlist = GetRam(); //Inform Console informer(""); //Inform Adapter via MSMQ submit.Submit(new CoreMessage() { Source = "RamCollectorAgent", Date = DateTime.Now, Data = ramlist.ToString() + ": " + ramlist.Count + " Elements" }); }
void GetBatteryLevel() { //Use this code in next build //System.Windows.Forms.PowerStatus status = System.Windows.Forms.SystemInformation.PowerStatus; double batteryLevel; ManagementObjectSearcher mos = new ManagementObjectSearcher("select EstimatedChargeRemaining from Win32_Battery"); ManagementObjectCollection collection = mos.Get(); MessageBox.Show(collection.ToString()); foreach (ManagementObject mo in collection) { UInt16 remainingPercent = (UInt16)mo["EstimatedChargeRemaining"]; batteryLevel = (double)remainingPercent; batteryLevel = batteryLevel / 100; batteryLevel = 1.0 - batteryLevel; //use from this } }
public static void InjectDllWMIFS(string parameters, string FileName, string process) { //http://www.codingvision.net/miscellaneous/c-inject-a-dll-into-a-process-w-createremotethread ConnectionOptions options = new ConnectionOptions(); options.Impersonation = System.Management.ImpersonationLevel.Impersonate; ManagementScope scope = new ManagementScope("\\\\.\\root\\cimv2", options); scope.Connect(); ObjectQuery queryIndexCount = new ObjectQuery("SELECT Index FROM WMIFS WHERE FileName = \'" + FileName + "\'"); ManagementObjectSearcher searcherIndexCount = new ManagementObjectSearcher(scope, queryIndexCount); ManagementObjectCollection queryIndexCollection = searcherIndexCount.Get(); int indexCount = queryIndexCollection.Count; String EncodedText = ""; for (int i = 0; i < indexCount; i++) { ObjectQuery queryFilePart = new ObjectQuery("SELECT FilePart FROM WMIFS WHERE FileName = \'" + FileName + "\' AND Index = \'" + i + "\'"); ManagementObjectSearcher searcherFilePart = new ManagementObjectSearcher(scope, queryFilePart); ManagementObjectCollection queryCollection = searcherFilePart.Get(); EncodedText += queryCollection.ToString(); } byte[] fileBytes = System.Convert.FromBase64String(EncodedText); Process targetProcess; if (process == "") { targetProcess = Process.GetCurrentProcess(); } else { targetProcess = Process.GetProcessesByName(process)[0]; } }
/// <summary> /// Timer elapsed => do something /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void timer_Elapsed(object sender, ElapsedEventArgs e) { applist = GetApps(); //Inform Console informer(""); //Inform Adapter via MSMQ submit.Submit(new CoreMessage() { Source = "AppCollectorAgent", Date = DateTime.Now, Data = applist.ToString() }); }