internal static byte[] GetDmi() { var scope = new System.Management.ManagementScope("\\\\" + "." + "\\root\\WMI"); scope.Connect(); var wmiquery = new System.Management.ObjectQuery("SELECT * FROM MSSmBios_RawSMBiosTables"); var searcher = new System.Management.ManagementObjectSearcher(scope, wmiquery); var coll = searcher.Get(); var M_ByMajorVersion = 0; var M_ByMinorVersion = 0; byte[] data = null; foreach (var O in coll) { var queryObj = (System.Management.ManagementObject)O; if (queryObj["SMBiosData"] != null) { data = (byte[])(queryObj["SMBiosData"]); } if (queryObj["SmbiosMajorVersion"] != null) { M_ByMajorVersion = (byte)(queryObj["SmbiosMajorVersion"]); } if (queryObj["SmbiosMinorVersion"] != null) { M_ByMinorVersion = (byte)(queryObj["SmbiosMinorVersion"]); } //if (queryObj["Size"] != null) m_dwLen = (long)(queryObj["Size"]); //m_dwLen = m_pbBIOSData.Length; } Version = (ushort)(M_ByMajorVersion << 8 | M_ByMinorVersion); return(data); }
public void ausfuehrungdeinstallation(string workstationname, string username, string password, bool durchfuehren, int msgboxjaneinvalue) { if (durchfuehren && msgboxjaneinvalue == 2) { this.unauthorised = false; this.authorized = true; var connection = new System.Management.ConnectionOptions(); connection.Username = username; //auskommentieren, wenn der Rechnername 127.0.0.1 ist. connection.Password = password; //auskommentieren, wenn der Rechnername 127.0.0.1 ist. //Ausfuehrung der PMI.exe ohne Benutzerinteraktion object[] theProcessToRun1 = { @"C:\PMI.exe /uninstall /quiet /norestart /log C:\log.txt" }; //uninstall PMI silently var wmiScope = new System.Management.ManagementScope(@"\\" + workstationname + @"\root\cimv2", connection); try { wmiScope.Connect(); using (var managementClass = new System.Management.ManagementClass(wmiScope, new System.Management.ManagementPath("Win32_Process"), new System.Management.ObjectGetOptions())) { managementClass.InvokeMethod("Create", theProcessToRun1); } } catch (System.UnauthorizedAccessException) { this.unauthorised = true; this.authorized = false; } } }
private void LoginButton_Click(object sender, System.EventArgs e) { bool success = false; if (this.MachineNameTextBox.Text == string.Empty) { this.MachineNameTextBox.Text = @"\\localhost\root\cimv2"; } else { if (!this.MachineNameTextBox.Text.StartsWith(@"\\")) { this.MachineNameTextBox.Text = @"\\" + this.MachineNameTextBox.Text; } } if (!this.MachineNameTextBox.Text.StartsWith(@"\\localhost")) { if (this.UsernameTextBox.Text != string.Empty && this.PasswordTextBox.Text != string.Empty && this.MachineNameTextBox.Text != string.Empty) { try { System.Management.ConnectionOptions oConn = new System.Management.ConnectionOptions(); oConn.Username = this.UsernameTextBox.Text; oConn.Password = this.PasswordTextBox.Text; oConn.Impersonation = System.Management.ImpersonationLevel.Impersonate; //oConn.Authority = this.MachineNameTextBox.Text; oConn.Authentication = System.Management.AuthenticationLevel.Connect; System.Management.ManagementScope oMs = new System.Management.ManagementScope(this.MachineNameTextBox.Text, oConn); oMs.Path = new System.Management.ManagementPath(this.MachineNameTextBox.Text); oMs.Connect(); success = oMs.IsConnected; } catch (Exception exc) { Terminals.Logging.Info("Login Failed", exc); MessageBox.Show(exc.Message); } if (success) { this.Cancelled = false; this.Visible = false; } } } else { this.Cancelled = false; this.Visible = false; } }
private void CreateWmiDataProviderFromWmiItem(wmi_item wmiItem) { if (this.WmiDataProvider == null) { var wmiNamespace = String.Format(@"{0}\{1}", this.TargetInfo.GetAddress(), [email protected]); var wmiNamespacePath = new System.Management.ManagementPath(wmiNamespace); var wmiConnectionOptions = WmiDataProviderFactory.CreateConnectionOptions(this.TargetInfo); var wmiManagementScope = new System.Management.ManagementScope(wmiNamespacePath, wmiConnectionOptions); wmiManagementScope.Connect(); this.WmiDataProvider = new WmiDataProvider(wmiManagementScope); } }
private WmiDataProvider GetWmiDataProvider(string @namespace) { if (this.WmiDataProvider != null) { return(this.WmiDataProvider); } var wmiNamespace = String.Format(@"\\{0}\{1}", this.TargetInfo.GetAddress(), @namespace); var wmiNamespacePath = new System.Management.ManagementPath(wmiNamespace); var wmiConnectionOptions = WmiDataProviderFactory.CreateConnectionOptions(this.TargetInfo); var wmiManagementScope = new System.Management.ManagementScope(wmiNamespacePath, wmiConnectionOptions); wmiManagementScope.Connect(); return(new WmiDataProvider(wmiManagementScope)); }
private void vInitializeRegistryToInteractWithDesktop() { try { System.Management.ConnectionOptions coOptions = new System.Management.ConnectionOptions(); coOptions.Impersonation = System.Management.ImpersonationLevel.Impersonate; System.Management.ManagementScope mgmtScope = new System.Management.ManagementScope(@"root\CIMV2", coOptions); mgmtScope.Connect(); System.Management.ManagementObject wmiService; wmiService = new System.Management.ManagementObject("Win32_Service.Name='" + mdlConstantes.clsConstantes.WINDOWSSERVICE_SISCOMENSAGEM_NAME + "'"); System.Management.ManagementBaseObject InParam = wmiService.GetMethodParameters("Change"); InParam["DesktopInteract"] = true; System.Management.ManagementBaseObject OutParam = wmiService.InvokeMethod("Change", InParam, null); } catch { // Cant access the registry } }
/** * Look for any currently installed printers that were installed through this Service, but are no longer in the printers list file. Those printers should * be removed from the system. * * @param List<string> A list of currently installed printer names that were installed through this Service * */ void DeletePrinters(List <string> installedPrinters) { // For each printer in the installed List<> if it is NOT in the printers list, delete it List <string> lPrinters = new List <string>(); if (File.Exists(working_directory)) { System.IO.StreamReader file = new System.IO.StreamReader(working_directory); string line; while ((line = file.ReadLine()) != null) { lPrinters.Add(line); } file.Close(); } foreach (string iPrinter in installedPrinters) { if (!lPrinters.Contains(iPrinter)) { // Delete System.Management.ManagementScope oManagementScope = new System.Management.ManagementScope(System.Management.ManagementPath.DefaultPath); oManagementScope.Connect(); System.Management.SelectQuery query = new System.Management.SelectQuery("SELECT * FROM Win32_Printer"); System.Management.ManagementObjectSearcher search = new System.Management.ManagementObjectSearcher(oManagementScope, query); System.Management.ManagementObjectCollection printers = search.Get(); foreach (System.Management.ManagementObject printer in printers) { string pName = printer["Name"].ToString().ToLower(); if (pName.Equals(iPrinter.ToLower())) { printer.Delete(); break; } } } } }
private static void StopAppPool(string pPoolName, bool DoRestart) { try { System.Management.ManagementScope scope = new System.Management.ManagementScope("root\\MicrosoftIISv2"); scope.Connect(); System.Management.ManagementObject appPool = new System.Management.ManagementObject(scope, new System.Management.ManagementPath("IIsApplicationPool.Name='W3SVC/AppPools/" + pPoolName + "'"), null); if (appPool != null) { if (DoRestart) { appPool.InvokeMethod("Recycle", null, null); } else { appPool.InvokeMethod("Stop", null, null); } } } catch (Exception ee) { StartupLog($"IIS Shutdown problem : {ee}"); } }
private void LoginButton_Click(object sender, System.EventArgs e) { bool success = false; if (this.MachineNameTextBox.Text == string.Empty) { this.MachineNameTextBox.Text = @"\\localhost\root\cimv2"; } else { if (!this.MachineNameTextBox.Text.StartsWith(@"\\")) this.MachineNameTextBox.Text = @"\\" + this.MachineNameTextBox.Text; } if (!this.MachineNameTextBox.Text.StartsWith(@"\\localhost")) { if (this.UsernameTextBox.Text != string.Empty && this.PasswordTextBox.Text != string.Empty && this.MachineNameTextBox.Text != string.Empty) { try { System.Management.ConnectionOptions oConn = new System.Management.ConnectionOptions(); oConn.Username = this.UsernameTextBox.Text; oConn.Password = this.PasswordTextBox.Text; oConn.Impersonation = System.Management.ImpersonationLevel.Impersonate; //oConn.Authority = this.MachineNameTextBox.Text; oConn.Authentication = System.Management.AuthenticationLevel.Connect; System.Management.ManagementScope oMs = new System.Management.ManagementScope(this.MachineNameTextBox.Text, oConn); oMs.Path = new System.Management.ManagementPath( this.MachineNameTextBox.Text ); oMs.Connect(); success = oMs.IsConnected; } catch (Exception exc) { Terminals.Logging.Info("Login Failed", exc); MessageBox.Show(exc.Message); } if (success) { this.Cancelled = false; this.Visible = false; } } } else { this.Cancelled = false; this.Visible = false; } }
private WmiDataProvider GetWmiDataProvider(string @namespace) { if (this.WmiDataProvider != null) return this.WmiDataProvider; var wmiNamespace = String.Format(@"\\{0}\{1}", this.TargetInfo.GetAddress(), @namespace); var wmiNamespacePath = new System.Management.ManagementPath(wmiNamespace); var wmiConnectionOptions = WmiDataProviderFactory.CreateConnectionOptions(this.TargetInfo); var wmiManagementScope = new System.Management.ManagementScope(wmiNamespacePath, wmiConnectionOptions); wmiManagementScope.Connect(); return new WmiDataProvider(wmiManagementScope); }