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; } } }
public static string GetSecurePassword(this System.Management.ConnectionOptions obj) { #if MONO return(string.Empty); #else return(obj.SecurePassword); #endif }
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; } }
public static string Detect3264() { System.Management.ConnectionOptions oConn = new System.Management.ConnectionOptions(); System.Management.ManagementScope oMs = new System.Management.ManagementScope("\\\\localhost", oConn); System.Management.ObjectQuery oQuery = new System.Management.ObjectQuery("select AddressWidth from Win32_Processor"); System.Management.ManagementObjectSearcher oSearcher = new System.Management.ManagementObjectSearcher(oMs, oQuery); System.Management.ManagementObjectCollection oReturnCollection = oSearcher.Get(); string addressWidth = null; foreach (System.Management.ManagementObject oReturn in oReturnCollection) { addressWidth = oReturn["AddressWidth"].ToString(); } return addressWidth; }
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 } }
private void LoadShares(string Username, string Password, string Computer) { List<Share> shares = new List<Share>(); System.Text.StringBuilder sb = new StringBuilder(); string qry = "select * from win32_share"; 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); } foreach(System.Management.ManagementObject share in searcher.Get()) { Share s = new Share(); foreach(System.Management.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 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 LoadShares(string Username, string Password, string Computer) { List <Share> shares = new List <Share>(); System.Text.StringBuilder sb = new StringBuilder(); string qry = "select * from win32_share"; 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); } foreach (System.Management.ManagementObject share in searcher.Get()) { Share s = new Share(); foreach (System.Management.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; }