Esempio n. 1
0
        /// <summary>
        /// Installs application on specified machine.
        /// </summary>
        /// <param name="computerName">Server on which to Uninstall application.</param>
        /// <param name="packageToInstall">Full path of the package to install.</param>
        /// ///<returns>Returns the result of execution as string.</returns>
        public static string Install(string computerName, string msiLocation, string targetDir)
        {
            string result = string.Empty;

            try
            {
                string path = GenericHelper.CopyToTempFolder(computerName, msiLocation);
                result = WMIInstall.Install(computerName, path, targetDir);
                File.Delete(path);
                if (result == "0")
                {
                    result = String.Format("Installation done successfully with code {0} for computer {1}", result, computerName);
                }
                else
                {
                    result = String.Format("Installation done with error, with error message '{0}' and error code {1} for computer {2}", WMIInstallErrorCodeResolver.GetInstallErrorMessage(result), result, computerName);
                }
            }
            catch (Exception exe)
            {
                result = String.Format("WMI method error for computer {0}: {1}", computerName, exe.Message);
            }

            return(result);
        }
Esempio n. 2
0
        public override bool Execute(out string message)
        {
            string tempAssemblyPath = string.Empty;
            string batchFile        = string.Empty;
            string batchFileLog     = string.Empty;
            bool   result           = false;
            string exceptionMessage = string.Empty;

            message = string.Empty;
            try
            {
                tempAssemblyPath = GenericHelper.CopyToTempFolder(this.resourceInfo.ServerName, this.resourceInfo.ResourceName);
                string uniqueName = Guid.NewGuid().ToString();
                batchFile    = Path.Combine(GenericHelper.GetTempFolder(this.resourceInfo.ServerName), uniqueName) + ".bat";
                batchFileLog = Path.ChangeExtension(batchFile, "txt");
                CreateAndSaveBatchFile(gacUtilLoc.Encode(), tempAssemblyPath, batchFile, batchFileLog);
                result = Win32_Process.Create(this.resourceInfo.ServerName, batchFile, out message);
                if (File.Exists(batchFileLog))
                {
                    message = message + File.ReadAllText(batchFileLog);
                }
            }
            catch (Exception exe)
            {
                exceptionMessage = exe.Message;
            }
            finally
            {
                if (File.Exists(tempAssemblyPath))
                {
                    File.Delete(tempAssemblyPath);
                }
                if (File.Exists(batchFile))
                {
                    File.Delete(batchFile);
                }
                if (File.Exists(batchFileLog))
                {
                    File.Delete(batchFileLog);
                }
            }
            message = result ? message : exceptionMessage;
            return(result);
        }
Esempio n. 3
0
        public override bool Execute(out string message)
        {
            string tempMsiPath  = string.Empty;
            string batchFile    = string.Empty;
            string batchFileLog = string.Empty;
            bool   result       = false;

            message = string.Empty;
            try
            {
                tempMsiPath = GenericHelper.CopyToTempFolder(this.resourceInfo.ServerName, this.resourceInfo.ResourceName);
                string uniqueName = Guid.NewGuid().ToString();
                batchFile    = Path.Combine(GenericHelper.GetTempFolder(this.resourceInfo.ServerName), uniqueName) + ".bat";
                batchFileLog = Path.ChangeExtension(batchFile, "txt");
                CreateAndSaveBatchFile(tempMsiPath, batchFile, batchFileLog);
                result = Win32_Process.Create(this.resourceInfo.ServerName, batchFile, out message);
                if (File.Exists(batchFileLog))
                {
                    message = message + File.ReadAllText(batchFileLog);
                }
                ExtractSettings(GenericHelper.FormatPath(this.resourceInfo.ServerName, this.TargetDir));
            }
            catch (Exception exe)
            {
                message = exe.Message;
            }
            finally
            {
                if (File.Exists(tempMsiPath))
                {
                    File.Delete(tempMsiPath);
                }
                if (File.Exists(batchFile))
                {
                    File.Delete(batchFile);
                }
                if (File.Exists(batchFileLog))
                {
                    File.Delete(batchFileLog);
                }
            }
            result = (message.Contains("Installation completed successfully") || message.Contains("Configuration completed successfully")) ? true : false;
            return(result);
        }