public override void Run(ref ReturnCodeAction returnCode) { Logger.Write("Running ImportRegFileAction. FullPath = " + this.FullPath); System.Diagnostics.ProcessStartInfo processInfo = new System.Diagnostics.ProcessStartInfo(); FullPath = Tools.GetExpandedPath(FullPath); processInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; processInfo.FileName = "cmd.exe"; processInfo.Arguments = "/C reg import \"" + this.FullPath + "\""; processInfo.ErrorDialog = false; processInfo.CreateNoWindow = true; processInfo.UseShellExecute = false; System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = processInfo; process.Start(); if (!process.WaitForExit(10000)) { Logger.Write("Process running for too long. Killing Process…"); process.Kill(); Logger.Write("Process killed."); } else { Logger.Write("Process has finnish running."); } Logger.Write("Exite code : " + process.ExitCode.ToString()); Logger.Write("End of ImportRegFileAction."); }
public override void Run(ref ReturnCodeAction returnCode) { Logger.Write("Running DeleteRegKeyAction. Hive = " + this.Hive + " and RegKey = " + this.RegKey + " UseReg32 = " + this.UseReg32.ToString()); try { RegistryKey hiveKey; switch (this.Hive) { case "HKey_Current_User": hiveKey = Registry.CurrentUser; // Il n'y a pas de notion de registre 32bit ou 64bit dans la ruche CURRENT_USER break; case "HKey_Local_Machine": hiveKey = this.UseReg32 ? RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32) : RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); break; default: throw new Exception("The Hive is not recognized."); } hiveKey.DeleteSubKeyTree(this.RegKey, false); hiveKey.Close(); Logger.Write("Key successfully deleted."); } catch (Exception ex) { Logger.Write("**** An error occurs : " + ex.Message); } Logger.Write("End of DeleteRegKeyAction."); }
public override void Run(ref ReturnCodeAction returnCode) { Logger.Write("Running DeleteFolderAction. FolderPath = " + this.FolderPath); try { this.FolderPath = Tools.GetExpandedPath(this.FolderPath); DirectoryInfo folderToDelete = new DirectoryInfo(this.FolderPath); if (folderToDelete.Exists) { folderToDelete.Delete(true); folderToDelete.Refresh(); Logger.Write(folderToDelete.Exists ? "Unable to delete the folder." : "The folder has been successfully deleted."); } else { Logger.Write("The folder doesn't exists."); } } catch (Exception ex) { Logger.Write("Failed to delete the folder : " + this.FolderPath + "\r\n" + ex.Message); } Logger.Write("End of DeleteFolderAction."); }
public override void Run(ref ReturnCodeAction returnCode) { Logger.Write("Running CreateFolder. FullPath = " + this.FullPath); try { this.FullPath = Tools.GetExpandedPath(this.FullPath); DirectoryInfo destinationFolder = new DirectoryInfo(this.FullPath); if (!destinationFolder.Exists) { destinationFolder.Create(); destinationFolder.Refresh(); Logger.Write(destinationFolder.Exists ? "Successfully created : " + this.FullPath : "Unable to create : " + this.FullPath); } else { Logger.Write("The folder already exists."); } } catch (Exception ex) { Logger.Write("Failed to create the folder : " + this.FullPath + "\r\n" + ex.Message); } Logger.Write("End of CreateFolder."); }
public override void Run(ref ReturnCodeAction returnCode) { Logger.Write("Running DeleteFileAction. FullPath = " + this.FullPath); try { this.FullPath = Tools.GetExpandedPath(this.FullPath); FileInfo fileToDelete = new FileInfo(this.FullPath); if (fileToDelete.Exists) { fileToDelete.Delete(); fileToDelete.Refresh(); Logger.Write(fileToDelete.Exists ? "Unable to delete the file." : "The file has been successfully deleted."); } else { Logger.Write("The file doesn't exists."); } } catch (Exception ex) { Logger.Write("**** An error occurs : " + ex.Message); } Logger.Write("End of DeleteFileAction."); }
public override void Run(ref ReturnCodeAction returnCode) { Logger.Write("Running UninstallMsiProductByGuidAction. MsiProductCodes= " + this.MsiProductCodes + " Exceptions= " + this.Exceptions); try { Logger.Write("Getting all installed product on this computer"); List <MsiProduct> installedProducts = GetMsiProducts(); Logger.Write("Found " + installedProducts.Count + " products installed."); if (!this.DontUninstallIfNoException || this.IsAtLeastOneExceptionIsInstalled(installedProducts)) { Logger.Write("Searching products to uninstall"); List <MsiProduct> productsToUninstall = this.GetProductsToUninstall(installedProducts); Logger.Write(productsToUninstall.Count + " products to uninstall."); foreach (MsiProduct product in productsToUninstall) { this.UninstallProduct(product); } } } catch (Exception ex) { Logger.Write("An error occurs while preparing uninstallation : " + ex.Message); throw; } Logger.Write("End of UninstallMsiProductByGuidAction."); }
public override void Run(ref ReturnCodeAction returnCode) { // schtasks /Delete [/S <system> [/U <username> [/P [<password>]]]] /TN <taskname> [/F] Logger.Write("Running DeleteTaskAction. TaskName = " + this.TaskName); System.Diagnostics.Process process = new System.Diagnostics.Process(); try { System.Diagnostics.ProcessStartInfo processInfo = new System.Diagnostics.ProcessStartInfo(); processInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; processInfo.FileName = @"C:\Windows\System32\schtasks.exe"; processInfo.Arguments = "/Delete /TN \"" + this.TaskName + "\" /F"; processInfo.ErrorDialog = false; processInfo.CreateNoWindow = true; processInfo.UseShellExecute = false; process.StartInfo = processInfo; process.Start(); if (!process.WaitForExit(3000)) { process.Kill(); } Logger.Write("Successfuly delete task : " + this.TaskName); } catch (Exception ex) { Logger.Write("**** An error occurs : " + ex.Message); } Logger.Write("End of DeleteTaskAction."); }
public override void Run(ref ReturnCodeAction returnCode) { Logger.Write("Running RenameFolderAction. FolderPath = " + this.FolderPath + " and NewName = " + this.NewName); try { this.FolderPath = Tools.GetExpandedPath(this.FolderPath); DirectoryInfo oldDirectory = new DirectoryInfo(this.FolderPath); if (oldDirectory.Exists) { oldDirectory.MoveTo(Path.Combine(oldDirectory.Parent.FullName, this.NewName)); DirectoryInfo newDirectory = new DirectoryInfo(this.NewName); Logger.Write(newDirectory.Exists ? "The folder have been successfully renamed" : "The folder have NOT been renamed"); } else { Logger.Write("The folder to rename doesn't exists."); } } catch (Exception ex) { Logger.Write("**** An error occurs : " + ex.Message); } Logger.Write("End of RenameFolderAction."); }
public override void Run(ref ReturnCodeAction returnCode) { Logger.Write("Running CreateShortcutAction. Target = " + this.Target + " and ShortcutName = " + this.ShortcutName); try { string shortcutLocation = Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory); if (IsDesktopLocation) { if (DesktopTarget == 1) { shortcutLocation = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); } } else { shortcutLocation = PersoLocation; } if (!AbortIfTargetDontExist || System.IO.File.Exists(Target)) { CreateShortcut(Target, ShortcutName, shortcutLocation, Description, Icon, Arguments, WorkingDirectory, WindowStyle); } else { Logger.Write("The Target of the shortcut doesn't exits, aborting"); } } catch (Exception ex) { Logger.Write("Failed to create the shortcut : " + this.ShortcutName + "\r\n" + ex.Message); } Logger.Write("End of CreateShortcutAction."); }
public override void Run(ref ReturnCodeAction returnCode) { Logger.Write("Running UnregisterDLL. FullPath = " + this.FullPath); try { this.FullPath = Tools.GetExpandedPath(this.FullPath); if (!System.IO.File.Exists(this.FullPath)) { Logger.Write("!!!! Warning, the file was not found on this system."); } Process proc = new Process(); ProcessStartInfo startInfo = new ProcessStartInfo("RegSVR32.exe"); startInfo.Arguments = "/s /u " + this.FullPath; proc.StartInfo = startInfo; proc.Start(); if (!proc.WaitForExit(10000)) { Logger.Write("Killing process…"); proc.Kill(); } else { Logger.Write("Process stop by itself. Returned code : " + proc.ExitCode); } Logger.Write("DLL has been successfully unregistered."); } catch (Exception ex) { Logger.Write("An error occurs while unregistering DLL " + FullPath + " : " + ex.Message); } Logger.Write("End of UnregisterDLL"); }
public static List <GenericAction> ParseActionsFile(string fullPath) { List <GenericAction> actions = new List <GenericAction>(); XmlReader reader = XmlReader.Create(new StreamReader(fullPath, System.Text.Encoding.Unicode)); if (!reader.ReadToFollowing("CustomUpdate")) { throw new Exception("Unable to find the token : CustomUpdate"); } int version = int.Parse(reader.GetAttribute("Version")); if (version != 2) { throw new Exception("Wrong version (expected version = 2, this version = " + version + ")"); } while (reader.ReadToFollowing("Action")) { GenericAction currentAction = GetActionFromXML(reader.ReadOuterXml()); if (currentAction.GetType() == typeof(ReturnCodeAction)) { _returnCode = (ReturnCodeAction)currentAction; } else { actions.Add(currentAction); } } return(actions); }
public override void Run(ref ReturnCodeAction returnCode) { Logger.Write("Running KillProcessAction. Hive = " + this.ProcessName); try { Process[] processes = Process.GetProcessesByName(this.ProcessName); foreach (Process process in processes) { try { process.Kill(); Logger.Write("Process killed"); } catch (Exception ex) { Logger.Write("Unable to kill process : " + ex.Message); } } } catch (Exception ex) { Logger.Write("**** An error occurs : " + ex.Message); } Logger.Write("End of KillProcessAction."); }
public override void Run(ref ReturnCodeAction returnCode) { Logger.Write("Running CreateTextFileAction. FilePath = " + this.FilePath + " and Filename = " + this.Filename); try { this.FilePath = Tools.GetExpandedPath(this.FilePath); DirectoryInfo folder = new DirectoryInfo(this.FilePath); if (!folder.Exists) { Logger.Write("The folder doesn't exists. Creating the folder…"); folder.Create(); Logger.Write("Folder successfully created."); } StreamWriter writer = new StreamWriter(Path.Combine(this.FilePath, this.Filename), false, Encoding.Unicode); writer.Write(this.Content); writer.Close(); Logger.Write("File successfully written"); } catch (Exception ex) { Logger.Write("**** An error occurs : " + ex.Message); } Logger.Write("End of CreateTextFileAction."); }
public override void Run(ref ReturnCodeAction returnCode) { Logger.Write("Running RenameFileAction. FullPath = " + this.FullPath + " and NewName = " + this.NewName); try { this.FullPath = Tools.GetExpandedPath(this.FullPath); FileInfo fileToRename = new FileInfo(this.FullPath); if (fileToRename.Exists) { FileStream newFile = File.Create(Path.Combine(fileToRename.DirectoryName, this.NewName)); newFile.Close(); File.Replace(fileToRename.FullName, newFile.Name, null); FileInfo renamedFile = new FileInfo(newFile.Name); Logger.Write(renamedFile.Exists ? "The file have been successfully renamed" : "The file have NOT been renamed"); } else { Logger.Write("The file to rename doesn't exists."); } } catch (Exception ex) { Logger.Write("**** An error occurs : " + ex.Message); } Logger.Write("End of RenameFileAction."); }
public override void Run(ref ReturnCodeAction returnCode) { Logger.Write("Running CopyFileAction. SourceFile = " + this.SourceFile + " and DestinationFolder = " + this.DestinationFolder); try { this.SourceFile = Tools.GetExpandedPath(this.SourceFile); this.DestinationFolder = Tools.GetExpandedPath(this.DestinationFolder); FileInfo sourceFile = new FileInfo(this.SourceFile); DirectoryInfo destinationFolder = new DirectoryInfo(this.DestinationFolder); if (!destinationFolder.Exists) { Logger.Write("Creating : " + this.DestinationFolder); destinationFolder.Create(); } FileInfo destinationFile = sourceFile.CopyTo(Path.Combine(this.DestinationFolder, sourceFile.Name), true); if (destinationFile.Exists) { Logger.Write("Successfully copied : " + this.SourceFile + " to : " + this.DestinationFolder); } else { Logger.Write("Unable to copy : " + this.SourceFile + " to : " + this.DestinationFolder); } } catch (Exception ex) { Logger.Write("Failed to copy the file : " + this.SourceFile + " to : " + this.DestinationFolder + "\r\n" + ex.Message); } Logger.Write("End of CopyFileAction."); }
public override void Run(ref ReturnCodeAction returnCode) { Logger.Write("Running WaitElement."); System.Threading.Thread.Sleep(SecondToWait * 1000); Logger.Write("End waiting."); }
public override void Run(ref ReturnCodeAction returnCode) { Logger.Write("Running AddRegValueAction. Hive = " + this.Hive + " and RegKey = " + this.RegKey + " UseReg32 = " + this.UseReg32.ToString() + " ValueName = " + ValueName + " Data = " + Data + " valueType = " + ValueType); try { RegistryKey hiveKey; switch (this.Hive) { case "HKey_Current_User": hiveKey = Registry.CurrentUser; // Il n'y a pas de notion de registre 32bit ou 64bit dans la ruche CURRENT_USER break; case "HKey_Local_Machine": hiveKey = this.UseReg32 ? RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32) : RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); break; default: throw new Exception("The Hive is not recognized."); } RegistryKey targetKey; targetKey = hiveKey.CreateSubKey(RegKey); // Open or Create if missing switch (GetValueType(ValueType)) { case RegistryValueKind.Binary: targetKey.SetValue(ValueName, this.GetBinaryData(Data), GetValueType(ValueType)); break; case RegistryValueKind.MultiString: targetKey.SetValue(ValueName, this.GetStringData(Data), GetValueType(ValueType)); break; case RegistryValueKind.DWord: case RegistryValueKind.QWord: case RegistryValueKind.String: case RegistryValueKind.ExpandString: targetKey.SetValue(ValueName, (object)Data, GetValueType(ValueType)); break; } targetKey.Flush(); object newValue = targetKey.GetValue(ValueName, null); targetKey.Close(); hiveKey.Close(); Logger.Write(newValue != null ? "Value successfully created." : "**** Value not created."); } catch (Exception ex) { Logger.Write("**** An error occurs : " + ex.Message); } Logger.Write("End of AddRegValueAction."); }
public override void Run(ref ReturnCodeAction returnCode) { Logger.Write("Running ExecutableAction. PathToTheFile = " + this.PathToTheFile + " and Parameters = " + this.Parameters + " KillProcess = " + this.KillProcess.ToString()); System.Diagnostics.Process process = new System.Diagnostics.Process(); try { System.Diagnostics.ProcessStartInfo processInfo = new System.Diagnostics.ProcessStartInfo(); processInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; processInfo.FileName = Tools.GetExpandedPath(PathToTheFile); if (!string.IsNullOrEmpty(Parameters)) { processInfo.Arguments = Parameters; } processInfo.ErrorDialog = false; processInfo.CreateNoWindow = true; processInfo.UseShellExecute = false; process.StartInfo = processInfo; process.Start(); if (this.KillProcess) { if (!process.WaitForExit(this.DelayBeforeKilling * 60 * 1000)) { Logger.Write("Process running for too long. Killing Process…"); process.Kill(); Logger.Write("Process killed."); } else { Logger.Write("Process has finnish running."); } } else { process.WaitForExit(int.MaxValue); Logger.Write("Process has finnish running."); } Logger.Write("Exite code : " + process.ExitCode.ToString()); } catch (Exception) { Logger.Write("The process is already stopped or doesn't have start. No ExitCode can be set."); } if (returnCode.ReturnMethod == ReturnCodeAction.ReturnCodeMethod.Variable && this.StoreToVariable) { returnCode.ReturnValue = process.ExitCode; } Logger.Write("End of ExecutableAction."); }
public override void Run(ref ReturnCodeAction returnCode) { Logger.Write("Running RenameRegValueAction. Hive = " + this.Hive + " and RegKey = " + this.RegKey + " UseReg32 = " + this.UseReg32.ToString() + " ValueName = " + ValueName + " NewName = " + NewName); try { RegistryKey hiveKey; switch (this.Hive) { case "HKey_Current_User": hiveKey = Registry.CurrentUser; // Il n'y a pas de notion de registre 32bit ou 64bit dans la ruche CURRENT_USER break; case "HKey_Local_Machine": hiveKey = this.UseReg32 ? RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32) : RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); break; default: throw new Exception("The Hive is not recognized."); } RegistryKey targetKey; targetKey = hiveKey.OpenSubKey(RegKey, true); if (targetKey != null) { RegistryValueKind valueKind = targetKey.GetValueKind(this.ValueName); object data = targetKey.GetValue(this.ValueName); targetKey.SetValue(this.NewName, data, valueKind); // Creating the new value targetKey.DeleteValue(this.ValueName); // Deleting the old value targetKey.Close(); hiveKey.Close(); } else { Logger.Write("The registryKey " + this.RegKey + " doesn't exists."); } } catch (Exception ex) { Logger.Write("**** An error occurs : " + ex.Message); } Logger.Write("End of RenameRegValueAction."); }
public override void Run(ref ReturnCodeAction returnCode) { Logger.Write("Running ChangeServiceAction. ServiceName = " + this.ServiceName + " and Mode = " + this.Mode); try { uint resultCode = 1; string filter = String.Format("SELECT * FROM Win32_Service WHERE Name = '{0}'", this.ServiceName); ManagementObjectSearcher query = new ManagementObjectSearcher(filter); if (query != null) { ManagementObjectCollection services = query.Get(); foreach (ManagementObject service in services) { ManagementBaseObject inParams = service.GetMethodParameters("ChangeStartMode"); inParams["startmode"] = this.Mode; ManagementBaseObject outParams = service.InvokeMethod("ChangeStartMode", inParams, null); resultCode = Convert.ToUInt16(outParams.Properties["ReturnValue"].Value); if (resultCode == 0) { Logger.Write("Successfully changed the startup mode of " + ServiceName); } else { Logger.Write("Failed to change the startup mode of " + ServiceName + ". Result code = " + resultCode + " : " + this.GetResultCodeMeaning(resultCode)); } } } else { Logger.Write("The service " + ServiceName + " was not found."); } } catch (Exception ex) { Logger.Write("Failed to change the startup mode of " + ServiceName + "\r\n" + ex.Message); } Logger.Write("End of ChangeServiceAction."); }
public override void Run(ref ReturnCodeAction returnCode) { Logger.Write("Running ShutdownAction."); try { Process proc = new Process(); ProcessStartInfo startInfo = new ProcessStartInfo("Shutdown.exe"); startInfo.Arguments = "/s /c \"Shutdown initiated by CustomUpdateEngine\" /f /t 5"; proc.StartInfo = startInfo; proc.Start(); } catch (Exception ex) { Logger.Write("**** An error occurs : " + ex.Message); } Logger.Write("End of ShutdownAction."); }
public override void Run(ref ReturnCodeAction returnCode) { Logger.Write("Running UnregisterServiceAction."); try { ServiceInstaller ServiceInstallerObj = new ServiceInstaller(); System.Configuration.Install.InstallContext Context = new System.Configuration.Install.InstallContext(); ServiceInstallerObj.Context = Context; ServiceInstallerObj.ServiceName = ServiceName; ServiceInstallerObj.Uninstall(null); Logger.Write("Service successfully unregistered."); } catch (Exception ex) { Logger.Write("**** An error occurs : " + ex.Message); } Logger.Write("End of UnregisterServiceAction."); }
public override void Run(ref ReturnCodeAction returnCode) { Logger.Write("Running ChangeRegDataAction. Hive = " + this.Hive + " and RegKey = " + this.RegKey + " RegValue = " + (this.DefaultValue ? "DefaultValue" : this.RegValue) + " NewData = " + this.NewData + " UseReg32 = " + this.UseReg32.ToString()); try { RegistryKey hiveKey; switch (this.Hive) { case "HKey_Current_User": hiveKey = Registry.CurrentUser; // Il n'y a pas de notion de registre 32bit ou 64bit dans la ruche CURRENT_USER break; case "HKey_Local_Machine": hiveKey = this.UseReg32 ? RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32) : RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); break; default: throw new Exception("The Hive is not recognized."); } if (this.DefaultValue) { this.RegValue = String.Empty; } RegistryKey targetKey; targetKey = hiveKey.CreateSubKey(this.RegKey); targetKey.SetValue(RegValue, (object)NewData); object targetValueContent = targetKey.GetValue(RegValue, null); targetKey.Close(); hiveKey.Close(); Logger.Write((targetValueContent != null && (object)targetValueContent == (object)NewData) ? "Value successfully modified." : "**** Value not modified."); } catch (Exception ex) { Logger.Write("**** An error occurs : " + ex.Message); } Logger.Write("End of ChangeRegDataAction."); }
public override void Run(ref ReturnCodeAction returnCode) { Logger.Write("Running RenameRegKeyAction. Hive = " + this.Hive + " and RegKey = " + this.RegKey + " UseReg32 = " + this.UseReg32.ToString() + " NewName = " + this.NewName); try { RegistryKey hiveKey; switch (this.Hive) { case "HKey_Current_User": hiveKey = Registry.CurrentUser; // Il n'y a pas de notion de registre 32bit ou 64bit dans la ruche CURRENT_USER break; case "HKey_Local_Machine": hiveKey = this.UseReg32 ? RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32) : RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); break; default: throw new Exception("The Hive is not recognized."); } RegistryKey parentKey = hiveKey.OpenSubKey(RegKey.Substring(0, RegKey.LastIndexOf(@"\")), true); string subKeyName = RegKey.Substring(RegKey.LastIndexOf(@"\") + 1); CopyKey(parentKey, subKeyName, this.NewName); parentKey.DeleteSubKeyTree(subKeyName); parentKey.Flush(); parentKey.Close(); } catch (Exception ex) { Logger.Write("**** An error occurs : " + ex.Message); } Logger.Write("End of RenameRegKeyAction."); }
public override void Run(ref ReturnCodeAction returnCode) { Logger.Write("Running DeleteRegValueAction. Hive = " + this.Hive + " and RegKey = " + this.RegKey + " UseReg32 = " + this.UseReg32.ToString() + " ValueName = " + ValueName); try { RegistryKey hiveKey; switch (this.Hive) { case "HKey_Current_User": hiveKey = Registry.CurrentUser; // Il n'y a pas de notion de registre 32bit ou 64bit dans la ruche CURRENT_USER break; case "HKey_Local_Machine": hiveKey = this.UseReg32 ? RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32) : RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); break; default: throw new Exception("The Hive is not recognized."); } RegistryKey targetKey = hiveKey.OpenSubKey(this.RegKey, true); targetKey.DeleteValue(this.ValueName, false); object oldValue = targetKey.GetValue(this.ValueName, null); targetKey.Close(); hiveKey.Close(); Logger.Write(oldValue == null ? "Value successfully deleted." : "Unable to delete the value."); } catch (Exception ex) { Logger.Write("**** An error occurs : " + ex.Message); } Logger.Write("End of DeleteRegValueAction."); }
public override void Run(ref ReturnCodeAction returnCode) { Logger.Write("Running RunVbScriptAction. FullPath= " + this.FullPath + " Parameters= " + this.Parameters + " KillProcess= " + this.KillProcess + " DelayBeforeKilling = " + this.DelayBeforeKilling + "StoreToVariable= " + this.StoreToVariable); try { System.Diagnostics.ProcessStartInfo processInfo = new System.Diagnostics.ProcessStartInfo(); string currentPath = Environment.CurrentDirectory; processInfo.FileName = @"C:\Windows\system32\Cscript.exe"; processInfo.Arguments = "\"" + Tools.GetExpandedPath(FullPath) + "\" " + Parameters; processInfo.WorkingDirectory = currentPath; processInfo.ErrorDialog = false; processInfo.CreateNoWindow = true; processInfo.UseShellExecute = false; Logger.Write("Running : " + processInfo.FileName + " With arguments : " + processInfo.Arguments); System.Diagnostics.Process process = new System.Diagnostics.Process(); if (System.IO.File.Exists(processInfo.FileName)) { if (System.IO.File.Exists(Tools.GetExpandedPath(FullPath))) { try { process.StartInfo = processInfo; process.Start(); } catch (Exception ex) { Logger.Write("Error running : " + processInfo.FileName + ". \r\n" + ex.Message); } if (this.KillProcess) { if (!process.WaitForExit(this.DelayBeforeKilling * 60 * 1000)) { Logger.Write("Killing process."); process.Kill(); } } else { process.WaitForExit(int.MaxValue); } Logger.Write("Exiting process with ExitCode = " + process.ExitCode.ToString()); if (returnCode.ReturnMethod == ReturnCodeAction.ReturnCodeMethod.Variable && this.StoreToVariable) { returnCode.ReturnValue = process.ExitCode; } } else { Logger.Write(FullPath + ", not found !"); } } else { Logger.Write(processInfo.FileName + ", not found !"); } } catch (Exception ex) { Logger.Write("**** An error occurs : " + ex.Message); } Logger.Write("End of RunVbScriptAction."); }
public override void Run(ref ReturnCodeAction returnCode) { Logger.Write("Running InstallMsiAction. MsiName= " + this.MsiName + " Parameters= " + this.Parameters); try { System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.StartInfo.Arguments = "/package \"" + this.MsiName + "\" " + GetUiLevel(this.UiLevel) + " " + GetRestartBehavior(RestartBehavior) + (IsLogRequested ? " /log \"" + this.LogPath + "\"" : String.Empty); proc.StartInfo.FileName = Tools.GetExpandedPath(@"%windir%\system32\msiexec.exe"); proc.Start(); try { if (this.KillProcess) { if (!proc.WaitForExit(this.KillAfter * 60 * 1000)) { proc.Kill(); Logger.Write("Process killed."); } } else { proc.WaitForExit(int.MaxValue); } Logger.Write("Exiting process. With Exite code : " + proc.ExitCode.ToString()); } catch (Exception) { Logger.Write("The process is already stopped or doesn't have start."); } switch (proc.ExitCode) { case 0: Logger.Write("Successfully installed " + this.MsiName); break; case 1641: Logger.Write("Successfully installed " + this.MsiName + " (A restart have been initiated)"); break; case 3010: Logger.Write("Successfully installed " + this.MsiName + " (A restart is required)"); break; default: Logger.Write("An error occurs while installing " + this.MsiName + " (MsiError : " + proc.ExitCode + ")"); break; } if (returnCode.ReturnMethod == ReturnCodeAction.ReturnCodeMethod.Variable && this.StoreToVariable) { returnCode.ReturnValue = proc.ExitCode; } } catch (Exception ex) { Logger.Write("An error occurs while preparing installation : " + ex.Message); throw; } Logger.Write("End of InstallMsiAction."); }
private static GenericAction GetActionFromXML(string xmlAction) { GenericAction action; Logger.Write("Get Element from : " + xmlAction); XmlReader reader = XmlReader.Create(new StringReader(xmlAction)); if (!reader.ReadToFollowing("ElementType")) { throw new Exception("Unable to find the token : ElementType"); } string elementType = reader.ReadString(); switch (elementType) { case "CustomActions.ReturnCode": action = new ReturnCodeAction(xmlAction); break; case "CustomActions.AddRegKeyAction": action = new AddRegKeyAction(xmlAction); break; case "CustomActions.AddRegValueAction": action = new AddRegValueAction(xmlAction); break; case "CustomActions.ChangeRegDataAction": action = new ChangeRegDataAction(xmlAction); break; case "CustomActions.ChangeServiceAction": action = new ChangeServiceAction(xmlAction); break; case "CustomActions.CopyFileAction": action = new CopyFileAction(xmlAction); break; case "CustomActions.CreateFolderAction": action = new CreateFolderAction(xmlAction); break; case "CustomActions.CreateShortcutAction": action = new CreateShortcutAction(xmlAction); break; case "CustomActions.CreateTextFileAction": action = new CreateTextFileAction(xmlAction); break; case "CustomActions.DeleteFileAction": action = new DeleteFileAction(xmlAction); break; case "CustomActions.DeleteFolderAction": action = new DeleteFolderAction(xmlAction); break; case "CustomActions.DeleteRegKeyAction": action = new DeleteRegKeyAction(xmlAction); break; case "CustomActions.DeleteRegValueAction": action = new DeleteRegValueAction(xmlAction); break; case "CustomActions.DeleteTaskAction": action = new DeleteTaskAction(xmlAction); break; case "CustomActions.ExecutableAction": action = new ExecutableAction(xmlAction); break; case "CustomActions.ImportRegFileAction": action = new ImportRegFileAction(xmlAction); break; case "CustomActions.KillProcessAction": action = new KillProcessAction(xmlAction); break; case "CustomActions.RebootAction": action = new RebootAction(xmlAction); break; case "CustomActions.RegisterDLLAction": action = new RegisterDLLAction(xmlAction); break; case "CustomActions.RenameFileAction": action = new RenameFileAction(xmlAction); break; case "CustomActions.RenameFolderAction": action = new RenameFolderAction(xmlAction); break; case "CustomActions.RenameRegKeyAction": action = new RenameRegKeyAction(xmlAction); break; case "CustomActions.RenameRegValueAction": action = new RenameRegValueAction(xmlAction); break; case "CustomActions.RunPowershellScriptAction": action = new RunPowershellScriptAction(xmlAction); break; case "CustomActions.RunVbScriptAction": action = new RunVbScriptAction(xmlAction); break; case "CustomActions.ShutdownAction": action = new ShutdownAction(xmlAction); break; case "CustomActions.StartServiceAction": action = new StartServiceAction(xmlAction); break; case "CustomActions.StopServiceAction": action = new StopServiceAction(xmlAction); break; case "CustomActions.UnregisterDLLAcion": action = new UnregisterDLLAction(xmlAction); break; case "CustomActions.UnregisterServiceAction": action = new UnregisterServiceAction(xmlAction); break; case "CustomActions.UninstallMsiProductByGuidAction": action = new UninstallMsiProductByGuidAction(xmlAction); break; case "CustomActions.UninstallMsiProductByNameAction": action = new UninstallMsiProductByNameAction(xmlAction); break; case "CustomActions.InstallMsiAction": action = new InstallMsiAction(xmlAction); break; case "CustomActions.WaitAction": action = new WaitAction(xmlAction); break; default: throw new Exception("Unknown ElementType : " + elementType); } if (action == null) { throw new Exception("Unable to create an Action from the xmlFragment."); } return(action); }
public virtual void Run(ref ReturnCodeAction returnCode) { }