Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to run a Command with C#
    primarykey
    data
    text
    <p>I am trying to write a program that will automate some setup for new computers at my job. One of the tasks is changing power options for Windows 7. I am trying to run a command that imports a power configuration file and returns the string output which contains a GUID to a variable. When I run the program, it does not return any value to my string. I'm sure I'm messing something up, can someone look and help? Here is my code:</p> <pre><code>if(chkPowerSettings.Checked == true &amp;&amp; radioDesktop.Checked == true) { //Establish the path to the power configuration file string DesktopFileName = "WTCPowerDesktop.pow"; string CFGFileSource = @"\\\\ops-data\\Apps\\Builds"; string TargetPath = @"c:\\"; //Creates the strings for the whole path string source = System.IO.Path.Combine(CFGFileSource, DesktopFileName); string destination = System.IO.Path.Combine(TargetPath, DesktopFileName); //Copies the file, the true will overwrite any already existing file System.IO.File.Copy(source, destination, true); System.Diagnostics.ProcessStartInfo importCFG = new System.Diagnostics.ProcessStartInfo("cmd","/c" + "powercfg –import C:\\WTCPowerDesktop.pow"); importCFG.RedirectStandardOutput = true; importCFG.UseShellExecute = false; importCFG.CreateNoWindow = false; System.Diagnostics.Process runImport = new System.Diagnostics.Process(); runImport.StartInfo = importCFG; runImport.Start(); string PowerCFGResult = runImport.StandardOutput.ReadToEnd(); MessageBox.Show(PowerCFGResult); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload