积极答复者
c#调用cmd输出本地安全策略消息

问题
-
在cmd中输入secedit /export /cfg c:\Report.txt 可以在c盘跟目录下导出本地安全策略信息,我写了一段代码可是始终无法导出,求高手指点!
private void MyButton_Click_1(object sender, RoutedEventArgs e) { Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = false; p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = true; p.Start(); string strDosCommand = @"secedit /export /cfg c:\Report.txt"; p.StandardInput.WriteLine(strDosCommand); p.StandardInput.WriteLine("exit"); p.WaitForExit(); p.Close(); }
- 已更改类型 valentine is me 2012年9月13日 0:56
答案
-
谢谢,您的帮助非常有意义!附上解决代码
private void MyButton_Click_1(object sender, RoutedEventArgs e) { Process p = new System.Diagnostics.Process(); p.StartInfo.FileName = "cmd.exe "; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.CreateNoWindow = true; p.Start(); p.StandardInput.WriteLine(@"cd\"); p.StandardInput.WriteLine(@"c:"); p.StandardInput.WriteLine(@"cd /d c:windows\system32\"); string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); p.StandardInput.WriteLine(@"secedit /export /cfg " + desktopPath + @"\Report.txt"); p.StandardInput.WriteLine("exit"); MessageBox.Show(p.StandardOutput.ReadToEnd()); p.Close(); }
- 已标记为答案 valentine is me 2012年9月13日 0:56
全部回复
-
谢谢,您的帮助非常有意义!附上解决代码
private void MyButton_Click_1(object sender, RoutedEventArgs e) { Process p = new System.Diagnostics.Process(); p.StartInfo.FileName = "cmd.exe "; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.CreateNoWindow = true; p.Start(); p.StandardInput.WriteLine(@"cd\"); p.StandardInput.WriteLine(@"c:"); p.StandardInput.WriteLine(@"cd /d c:windows\system32\"); string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); p.StandardInput.WriteLine(@"secedit /export /cfg " + desktopPath + @"\Report.txt"); p.StandardInput.WriteLine("exit"); MessageBox.Show(p.StandardOutput.ReadToEnd()); p.Close(); }
- 已标记为答案 valentine is me 2012年9月13日 0:56