private void LoadServices(string Username, string Password, string Computer) { const string qry = "select AcceptPause, AcceptStop, Caption, CheckPoint, CreationClassName, Description, DesktopInteract, DisplayName, ErrorControl, ExitCode, InstallDate, Name, PathName, ProcessId,ServiceSpecificExitCode, ServiceType, Started, StartMode, StartName, State, Status, SystemCreationClassName, SystemName, TagId, WaitHint from win32_service"; ManagementObjectSearcher searcher; ObjectQuery query = new ObjectQuery(qry); if (Username != "" && Password != "" && Computer != "" && !Computer.StartsWith(@"\\localhost")) { ConnectionOptions oConn = new ConnectionOptions { Username = Username, Password = Password }; if (!Computer.StartsWith(@"\\")) { Computer = @"\\" + Computer; } if (!Computer.ToLower().EndsWith(@"\root\cimv2")) { Computer = Computer + @"\root\cimv2"; } ManagementScope oMs = new ManagementScope(Computer, oConn); searcher = new ManagementObjectSearcher(oMs, query); } else { searcher = new ManagementObjectSearcher(query); } DataTable dt = new DataTable(); bool needsSchema = true; int length = 0; object[] values = null; this.list.Clear(); foreach (ManagementObject share in searcher.Get()) { Share s = new Share(); this.list.Add(share); if (needsSchema) { foreach (PropertyData p in share.Properties) { DataColumn col = new DataColumn(p.Name, this.ConvertCimType(p.Type)); dt.Columns.Add(col); } length = share.Properties.Count; needsSchema = false; } if (values == null) { values = new object[length]; } int x = 0; foreach (PropertyData p in share.Properties) { if (p != null && x < length) { values[x] = p.Value; x++; } } dt.Rows.Add(values); values = null; } this.dataGridView1.DataSource = dt; }
private void LoadServices(string Username, string Password, string Computer) { StringBuilder sb = new StringBuilder(); string qry = "select AcceptPause, AcceptStop, Caption, CheckPoint, CreationClassName, Description, DesktopInteract, DisplayName, ErrorControl, ExitCode, InstallDate, Name, PathName, ProcessId,ServiceSpecificExitCode, ServiceType, Started, StartMode, StartName, State, Status, SystemCreationClassName, SystemName, TagId, WaitHint from win32_service"; ManagementObjectSearcher searcher; ObjectQuery query = new ObjectQuery(qry); if (Username != "" && Password != "" && Computer != "" && !Computer.StartsWith(@"\\localhost")) { System.Management.ConnectionOptions oConn = new System.Management.ConnectionOptions(); oConn.Username = Username; oConn.Password = Password; if (!Computer.StartsWith(@"\\")) Computer = @"\\" + Computer; if (!Computer.ToLower().EndsWith(@"\root\cimv2")) Computer = Computer + @"\root\cimv2"; System.Management.ManagementScope oMs = new System.Management.ManagementScope(Computer, oConn); searcher = new System.Management.ManagementObjectSearcher(oMs, query); } else { searcher = new System.Management.ManagementObjectSearcher(query); } System.Data.DataTable dt = new DataTable(); bool needsSchema = true; int length = 0; object[] values = null; list.Clear(); foreach (System.Management.ManagementObject share in searcher.Get()) { Share s = new Share(); list.Add(share); if (needsSchema) { foreach (System.Management.PropertyData p in share.Properties) { System.Data.DataColumn col = new DataColumn(p.Name, ConvertCimType(p.Type)); dt.Columns.Add(col); } length = share.Properties.Count; needsSchema = false; } if (values == null) values = new object[length]; int x = 0; foreach (System.Management.PropertyData p in share.Properties) { if (p != null && x < length) { values[x] = p.Value; x++; } } dt.Rows.Add(values); values = null; } this.dataGridView1.DataSource = dt; }
private void LoadShares(string Username, string Password, string Computer) { List<Share> shares = new List<Share>(); StringBuilder sb = new StringBuilder(); const string qry = "select * from win32_share"; ManagementObjectSearcher searcher; ObjectQuery query = new ObjectQuery(qry); if (Username != "" && Password != "" && Computer != "" && !Computer.StartsWith(@"\\localhost")) { ConnectionOptions oConn = new ConnectionOptions {Username = Username, Password = Password}; if (!Computer.StartsWith(@"\\")) Computer = @"\\" + Computer; if (!Computer.ToLower().EndsWith(@"\root\cimv2")) Computer = Computer + @"\root\cimv2"; ManagementScope oMs = new ManagementScope(Computer, oConn); searcher = new ManagementObjectSearcher(oMs, query); } else { searcher = new ManagementObjectSearcher(query); } foreach (ManagementObject share in searcher.Get()) { Share s = new Share(); foreach (PropertyData p in share.Properties) { switch (p.Name) { case "AccessMask": if (p.Value != null) s.AccessMask = p.Value.ToString(); break; case "MaximumAllowed": if (p.Value != null) s.MaximumAllowed = p.Value.ToString(); break; case "InstallDate": if (p.Value != null) s.InstallDate = p.Value.ToString(); break; case "Description": if (p.Value != null) s.Description = p.Value.ToString(); break; case "Caption": if (p.Value != null) s.Caption = p.Value.ToString(); break; case "AllowMaximum": if (p.Value != null) s.AllowMaximum = p.Value.ToString(); break; case "Name": if (p.Value != null) s.Name = p.Value.ToString(); break; case "Path": if (p.Value != null) s.Path = p.Value.ToString(); break; case "Status": if (p.Value != null) s.Status = p.Value.ToString(); break; case "Type": if (p.Value != null) s.Type = p.Value.ToString(); break; default: break; } } shares.Add(s); } this.dataGridView1.DataSource = shares; }
private void LoadShares(string Username, string Password, string Computer) { List <Share> shares = new List <Share>(); StringBuilder sb = new StringBuilder(); const string qry = "select * from win32_share"; ManagementObjectSearcher searcher; ObjectQuery query = new ObjectQuery(qry); if (Username != "" && Password != "" && Computer != "" && !Computer.StartsWith(@"\\localhost")) { ConnectionOptions oConn = new ConnectionOptions { Username = Username, Password = Password }; if (!Computer.StartsWith(@"\\")) { Computer = @"\\" + Computer; } if (!Computer.ToLower().EndsWith(@"\root\cimv2")) { Computer = Computer + @"\root\cimv2"; } ManagementScope oMs = new ManagementScope(Computer, oConn); searcher = new ManagementObjectSearcher(oMs, query); } else { searcher = new ManagementObjectSearcher(query); } foreach (ManagementObject share in searcher.Get()) { Share s = new Share(); foreach (PropertyData p in share.Properties) { switch (p.Name) { case "AccessMask": if (p.Value != null) { s.AccessMask = p.Value.ToString(); } break; case "MaximumAllowed": if (p.Value != null) { s.MaximumAllowed = p.Value.ToString(); } break; case "InstallDate": if (p.Value != null) { s.InstallDate = p.Value.ToString(); } break; case "Description": if (p.Value != null) { s.Description = p.Value.ToString(); } break; case "Caption": if (p.Value != null) { s.Caption = p.Value.ToString(); } break; case "AllowMaximum": if (p.Value != null) { s.AllowMaximum = p.Value.ToString(); } break; case "Name": if (p.Value != null) { s.Name = p.Value.ToString(); } break; case "Path": if (p.Value != null) { s.Path = p.Value.ToString(); } break; case "Status": if (p.Value != null) { s.Status = p.Value.ToString(); } break; case "Type": if (p.Value != null) { s.Type = p.Value.ToString(); } break; default: break; } } shares.Add(s); } this.dataGridView1.DataSource = shares; }
private void LoadServices(string Username, string Password, string Computer) { System.Text.StringBuilder sb = new StringBuilder(); string qry = "select * from win32_service"; System.Management.ManagementObjectSearcher searcher; System.Management.ObjectQuery query = new System.Management.ObjectQuery(qry); if(Username != "" && Password != "" && Computer != "" && !Computer.StartsWith(@"\\localhost")) { System.Management.ConnectionOptions oConn = new System.Management.ConnectionOptions(); oConn.Username = Username; oConn.Password = Password; if(!Computer.StartsWith(@"\\")) Computer = @"\\" + Computer; if(!Computer.ToLower().EndsWith(@"\root\cimv2")) Computer = Computer + @"\root\cimv2"; System.Management.ManagementScope oMs = new System.Management.ManagementScope(Computer, oConn); searcher = new System.Management.ManagementObjectSearcher(oMs, query); } else { searcher = new System.Management.ManagementObjectSearcher(query); } System.Data.DataTable dt = new DataTable(); bool needsSchema = true; int length = 0; object[] values = null; list.Clear(); foreach(System.Management.ManagementObject share in searcher.Get()) { Share s = new Share(); list.Add(share); if(needsSchema) { foreach(System.Management.PropertyData p in share.Properties) { System.Data.DataColumn col = new DataColumn(p.Name, ConvertCimType(p.Type)); dt.Columns.Add(col); } length = share.Properties.Count; needsSchema = false; } if(values == null) values = new object[length]; int x = 0; foreach(System.Management.PropertyData p in share.Properties) { values[x] = p.Value; x++; } dt.Rows.Add(values); values = null; } this.dataGridView1.DataSource = dt; }
private void LoadServices(string Username, string Password, string Computer) { System.Text.StringBuilder sb = new StringBuilder(); string qry = "select * from win32_service"; System.Management.ManagementObjectSearcher searcher; System.Management.ObjectQuery query = new System.Management.ObjectQuery(qry); if (Username != "" && Password != "" && Computer != "" && !Computer.StartsWith(@"\\localhost")) { System.Management.ConnectionOptions oConn = new System.Management.ConnectionOptions(); oConn.Username = Username; oConn.Password = Password; if (!Computer.StartsWith(@"\\")) { Computer = @"\\" + Computer; } if (!Computer.ToLower().EndsWith(@"\root\cimv2")) { Computer = Computer + @"\root\cimv2"; } System.Management.ManagementScope oMs = new System.Management.ManagementScope(Computer, oConn); searcher = new System.Management.ManagementObjectSearcher(oMs, query); } else { searcher = new System.Management.ManagementObjectSearcher(query); } System.Data.DataTable dt = new DataTable(); bool needsSchema = true; int length = 0; object[] values = null; list.Clear(); foreach (System.Management.ManagementObject share in searcher.Get()) { Share s = new Share(); list.Add(share); if (needsSchema) { foreach (System.Management.PropertyData p in share.Properties) { System.Data.DataColumn col = new DataColumn(p.Name, ConvertCimType(p.Type)); dt.Columns.Add(col); } length = share.Properties.Count; needsSchema = false; } if (values == null) { values = new object[length]; } int x = 0; foreach (System.Management.PropertyData p in share.Properties) { values[x] = p.Value; x++; } dt.Rows.Add(values); values = null; } this.dataGridView1.DataSource = dt; }