I'm trying to create a GUI for the powercfg battery report. I've written the below, but it doesn't seem to work. Can anyone help please?
private void button1_Click(object sender, EventArgs e)
var saveDialog = new SaveFileDialog();
saveDialog.OverwritePrompt = true;
saveDialog.Title = "Save your battery report";
saveDialog.Filter = "HTML | *.html";
var defaultSavePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
saveDialog.InitialDirectory = defaultSavePath;
var saveLocation = saveDialog.FileName;
if (saveLocation != null)
saveLocation = "\"" + saveLocation + "\"";
var startInfo = new ProcessStartInfo();
startInfo.FileName = "powercfg.exe";
startInfo.Arguments = " /batteryreport /output " + saveLocation;
startInfo.CreateNoWindow = false;
startInfo.ErrorDialog = true;
startInfo.UseShellExecute = true;
Since my OS is 64 bit, in project properties I un-checked Prefer 32-bit checkbox in Build tab and it worked properly.
It also works when you choose the same bitness as your OS for Platform Target. For example X4.