我正在尝试编写一个程序,该程序将在我的工作中为新计算机自动进行一些设置。其中一项任务是更改 Windows 7 的电源选项。我正在尝试运行一个命令,该命令导入电源配置文件并将包含 GUID 的字符串输出返回给变量。当我运行程序时,它不会向我的字符串返回任何值。我确定我搞砸了,有人可以帮忙看看吗?这是我的代码:
if(chkPowerSettings.Checked == true && 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);
}