private void ExecutePowershell(String powershellFile) { String exec = "powershell.exe"; String args = String.Format("-NonInteractive -File {0}", powershellFile); EucaLogger.Debug(String.Format("Executing {0} {1}", exec, args)); try { Win32_CommandResult result = SystemsUtil.SpawnProcessAndWait(exec, args); EucaLogger.Debug(String.Format("Execution finished with exit code={0}", result.ExitCode)); EucaLogger.Debug(String.Format("Stdout: {0}", result.Stdout)); EucaLogger.Debug(String.Format("Stderr: {0}", result.Stderr)); } catch (Exception ex) { EucaLogger.Exception("Execution failed", ex); } }
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; } }
private void ExecuteCommandLine(String scriptFile) { String exec = "cmd.exe"; String args = String.Format("/c {0}", scriptFile); EucaLogger.Debug(String.Format("Executing {0} {1}", exec, args)); try { Win32_CommandResult result = SystemsUtil.SpawnProcessAndWait(exec, args); EucaLogger.Debug(String.Format("Execution finished with exit code={0}", result.ExitCode)); EucaLogger.Debug(String.Format("Stdout: {0}", result.Stdout)); EucaLogger.Debug(String.Format("Stderr: {0}", result.Stderr)); } catch (Exception ex) { EucaLogger.Exception("Execution failed", ex); } }
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; } }