Ejemplo n.º 1
0
 private void buttonAnswerFile_Click(object sender, EventArgs e)
 {
     try
     {
         string answerPath = this.SysprepAnswerFile;
         if (!File.Exists(answerPath))
         {
             MessageBox.Show(string.Format("Sysprep answer file is not found ({0})", answerPath));
             return;
         }
         Win32_CommandResult result = EucaUtil.SpawnProcessAndWait("notepad.exe", answerPath);
     }
     catch (Exception ie) {
         MessageBox.Show(string.Format("Unexpected exception thrown: {0}", ie.Message), "WARNING");
         EucaLogger.Exception("Unexpected exception thrown while opening sysprep answer file", ie);
         return;
     }
 }
Ejemplo n.º 2
0
        private void buttonSysprep_Click(object sender, EventArgs e)
        {
            //   IMPLEMENT_SYS_PREP;
            try
            {
                DialogResult answer = MessageBox.Show("Sysprep should be performed only when you are finished with VM setup. Do you want to run the sysprep now?",
                                                      "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (answer == DialogResult.No)
                {
                    return;
                }

                string answerPath = this.SysprepAnswerFile;
                if (answerPath == null)
                {
                    MessageBox.Show("Sysprep is not supported on this Windows version. Please check with the administration manual to find the supported OS",
                                    "WARNING");
                    return;
                }

                if (!File.Exists(answerPath))
                {
                    MessageBox.Show(string.Format("Sysprep answer file is not found ({0})", answerPath));
                    return;
                }

                string sysprepDest = string.Format("C:\\{0}", (new FileInfo(answerPath)).Name);
                if (File.Exists(sysprepDest))
                {
                    File.Delete(sysprepDest);
                }

                File.Copy(answerPath, sysprepDest);
                string sysprepExec = string.Format("{0}\\sysprep\\sysprep.exe",
                                                   Environment.GetFolderPath(Environment.SpecialFolder.System));

                string arg = string.Format("/generalize /oobe /quit /unattend:\"{0}\"", sysprepDest);
                EucaLogger.Debug("sysprep argument: " + arg);

                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo.UseShellExecute = true;

                Win32_CommandResult result = EucaUtil.SpawnProcessAndWait(sysprepExec, arg);
                if (result.ExitCode != 0)
                {
                    MessageBox.Show(string.Format("Sysprep returned exit code: {0}", result.ExitCode));
                    EucaLogger.Debug(string.Format("Sysprep exit code: {0}, stdout: {1}, stderr: {2}", result.ExitCode, result.Stdout, result.Stderr));
                    return;
                }
                else
                {
                    MessageBox.Show("Sysprep finished successfully. You can shutdown the VM and register it with Eucalyptus front-end.");
                    System.Environment.Exit(0);
                }
            }
            catch (Exception ie)
            {
                MessageBox.Show(string.Format("Unexpected exception thrown: {0}", ie.Message), "WARNING");
                EucaLogger.Exception("Unexpected exception thrown while running sysprep", ie);
                return;
            }
        }