Exemplo n.º 1
0
        internal void CopySourceToRemoteComputer(string rootFolder, string subfolder, string mainFile, List <string> additionalFiles, List <string> additionalFolders)
        {
            try
            {
                string fullPath = Path.Combine(rootFolder, subfolder);

                if (NetUse.Mount(string.Empty, rootFolder, Username, Password))
                {
                    if (!Directory.Exists(fullPath))
                    {
                        Directory.CreateDirectory(fullPath);
                    }
                    // Copy of the main file
                    FileInfo mainFileInfo = new FileInfo(mainFile);
                    File.Copy(mainFile, Path.Combine(fullPath, mainFileInfo.Name), true);
                    // Copy of the additional files
                    CopyFiles(additionalFiles, fullPath);
                    // Copy of the additional folders
                    foreach (string folder in additionalFolders)
                    {
                        CopyFolders(folder, fullPath);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new CopyFailedException(ex.Message);
            }
        }
Exemplo n.º 2
0
        private void BtnInstall_Click(object sender, EventArgs e)
        {
            LockUI(false);
            txtBxResult.Clear();
            txtBxResult.Refresh();
            string rootFolder = @"\\" + _targetComputer.ComputerName + @"\C$\Windows";
            string subFolder  = Path.Combine(@"Temp\MsiManager", Path.GetRandomFileName());

            try
            {
                List <string> additionalFiles   = new List <string>();
                List <string> additionalFolders = new List <string>();
                FileInfo      mainFileInfo      = new FileInfo(txtBxLocalPackage.Text);

                foreach (var item in chkLstFiles.Items)
                {
                    additionalFiles.Add(item.ToString());
                }
                foreach (var item in chklstFolders.Items)
                {
                    additionalFolders.Add(item.ToString());
                }

                DisplayStatus(_localization.GetLocalizedString("Copying"));
                _targetComputer.CopySourceToRemoteComputer(rootFolder, subFolder, mainFileInfo.FullName, additionalFiles, additionalFolders);

                DisplayStatus(_localization.GetLocalizedString("Installing"));
                var options = txtBxOptions.Text;

                if (ChkBxNeverRestart.Checked && !options.ToLower().Contains("reboot=reallysuppress"))
                {
                    options += (!string.IsNullOrEmpty(options) ? " " : string.Empty) + "REBOOT=ReallySuppress";
                }
                uint result = _targetComputer.InstallProduct(Path.Combine(rootFolder, subFolder, mainFileInfo.Name), options);

                DisplayResult(result);
            }
            catch (Computer.CopyFailedException ex)
            {
                txtBxResult.Text      = ex.Message;
                txtBxResult.BackColor = Color.Orange;
            }
            catch (Exception ex)
            {
                txtBxResult.Text      = ex.Message;
                txtBxResult.BackColor = Color.Orange;
            }
            try
            {
                DisplayStatus(_localization.GetLocalizedString("DeletingTemporaryFiles"));
                Directory.Delete(Path.Combine(rootFolder, subFolder), true);
                NetUse.UnMount(rootFolder);
                DisplayStatus(String.Empty);
            }
            catch (Exception) {}
            LockUI(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Checks if credential for this computer are valid by trying to connect to C:\Windows.
        /// </summary>
        /// <returns>True if the connection succeed, otherwise, false.</returns>
        internal bool IsCredentialOk()
        {
            string rootFolder = @"\\" + ComputerName + @"\C$\Windows";

            try
            {
                return(NetUse.Mount(string.Empty, rootFolder, Username, Password));
            }
            catch (Exception) { }

            return(false);
        }