public static List <string> GetLoggedUsers() { List <string> retList = new List <string>(); try { using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_UserProfile WHERE Loaded = True")) { using (var data = searcher.Get()) { foreach (ManagementObject user in data) { string username = new SecurityIdentifier(user["SID"].ToString()).Translate(typeof(NTAccount)).ToString(); if (!username.Contains("NT AUTHORITY")) { retList.Add(username); } } } } } catch (Exception ex) { Beaprint.PrintException(ex.Message); } return(retList); }
public static List <string> GetEverLoggedUsers() { List <string> retList = new List <string>(); try { SelectQuery query = new SelectQuery("Win32_UserProfile"); ManagementObjectSearcher searcher = new ManagementObjectSearcher(query); foreach (ManagementObject user in searcher.Get()) { string username = new SecurityIdentifier(user["SID"].ToString()).Translate(typeof(NTAccount)).ToString(); if (!username.Contains("NT AUTHORITY")) { retList.Add(username); } } } catch (Exception ex) { Beaprint.GrayPrint(String.Format(" [X] Exception: {0}", ex)); } return(retList); }
public static List <string> GetEverLoggedUsers() { List <string> retList = new List <string>(); try { SelectQuery query = new SelectQuery("Win32_UserProfile"); using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query)) { using (var data = searcher.Get()) { foreach (ManagementObject user in data) { try { string username = new SecurityIdentifier(user["SID"].ToString()).Translate(typeof(NTAccount)).ToString(); if (!username.Contains("NT AUTHORITY")) { retList.Add(username); } } // user SID could not be translated, ignore catch (Exception) { } } } } } catch (Exception ex) { Beaprint.PrintException(ex.Message); } return(retList); }
public void ConnectionToRemoteComputer() { string result = ""; List <string> users = new List <string>(); try { ConnectionOptions options = new ConnectionOptions(); //options.Username = "******"; //options.Password = "******"; ManagementScope scope = new ManagementScope("\\\\" + pc_combobox.Text + "\\root\\cimv2", options); scope.Connect(); ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_UserProfile Where Special = False"); ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query); foreach (ManagementObject queryObj in searcher.Get()) { try { var profileSID = queryObj["SID"].ToString(); string full_account = new SecurityIdentifier(profileSID).Translate(typeof(NTAccount)).ToString(); if (!full_account.Contains("admin")) { string[] account = full_account.Split(new char[] { '\\' }); users.Add(account[1]); userD.Add(profileSID, account[1]); //users_combobox.Items.Add(account[1]); } button_connect.Background = Brushes.LightGreen; button_connect.Content = "Подключено"; } catch { } } users.Sort(); users_combobox.ItemsSource = users; //query = new ObjectQuery("SELECT Caption FROM Win32_OperatingSystem"); query = new ObjectQuery("SELECT * FROM Win32_OperatingSystem"); searcher = new ManagementObjectSearcher(scope, query); ManagementObjectCollection queryCollection = searcher.Get(); foreach (ManagementObject m in queryCollection) { result = m["Caption"].ToString() + "\n" + m["OSArchitecture"].ToString(); } os_info.Content = "ОC на ПК: " + pc_combobox.Text + "\n" + result; string softwareRegLoc = @"Software\Microsoft\Windows\CurrentVersion\Uninstall"; ManagementClass registry = new ManagementClass(scope, new ManagementPath("StdRegProv"), null); ManagementBaseObject inParams_reg = registry.GetMethodParameters("EnumKey"); inParams_reg["hDefKey"] = 0x80000002;//HKEY_LOCAL_MACHINE inParams_reg["sSubKeyName"] = softwareRegLoc; // Read Registry Key Names ManagementBaseObject outParams_reg = registry.InvokeMethod("EnumKey", inParams_reg, null); string[] programGuids = outParams_reg["sNames"] as string[]; foreach (string subKeyName in programGuids) { inParams_reg = registry.GetMethodParameters("GetStringValue"); inParams_reg["sSubKeyName"] = softwareRegLoc + @"\" + subKeyName; inParams_reg["sValueName"] = "DisplayName"; // Read Registry Value outParams_reg = registry.InvokeMethod("GetStringValue", inParams_reg, null); if (outParams_reg.Properties["sValue"].Value != null) { string softwareName = outParams_reg.Properties["sValue"].Value.ToString(); programs.Add(softwareName); } } if (programs.Any(sublist => sublist.Contains("Microsoft Dynamics AX 2009"))) { Programms.Content = "Axapta" + " установлена"; } else { Programms.Content = "Axapta" + " не установлена"; } if (programs.Any(sublist => sublist.Contains("DIRECTUM 5.7"))) { Programms.Content += "\n" + "DIRECTUM 5.7" + " установлен"; } else { Programms.Content += "\n" + "DIRECTUM 5.7" + " не установлен"; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }