public void ExecutaAssinador() { string ArquivoTemp = ""; var Usuario = new UsuarioInstalador(); var oImpersonate = new Impersonate(); ArquivoTemp = System.AppDomain.CurrentDomain.BaseDirectory + "assinador.application"; WebClient wc = new WebClient(); MemoryStream f = new MemoryStream(wc.DownloadData("http://inbnet/instalacoes/Assinador/asssinador%20da%20Inb.application")); f.Flush(); FileStream fs = new FileStream(ArquivoTemp, FileMode.OpenOrCreate); f.CopyTo(fs); fs.Flush(); fs.Close(); f.Close(); var p = new ProcessStartInfo(ArquivoTemp); using (var exeProcess = Process.Start(p)) { exeProcess.StartInfo.UseShellExecute = false; exeProcess.StartInfo.UserName = UsuarioInstalador.Login; exeProcess.StartInfo.Domain = UsuarioInstalador.Dominio; exeProcess.StartInfo.Password = new SecureString(); foreach (char c in UsuarioInstalador.Senha) { exeProcess.StartInfo.Password.AppendChar(c); } exeProcess.WaitForExit(); } oImpersonate.undoImpersonation(); }
public void RestartShoppingCartService() { //--need to impersonate with the user having appropriate rights to start the service Impersonate objImpersonate = new Impersonate(_domainName, _userName, _userPassword); if (objImpersonate.impersonateValidUser()) { var starter = new WindowsServiceStarter(_nameOfService); starter.StopWindowService(); System.Threading.Thread.Sleep(1000); starter.StartWindowService(); objImpersonate.undoImpersonation(); } }