【发布时间】:2018-02-22 19:15:43
【问题描述】:
我尝试使用 Powershell 重命名映射的网络驱动器。 在 Powershell Script 中运行命令就可以了。但是当我在 c# 中尝试使用 Powershell 进程时出现错误:参数不能为 NULL。 有人知道我的代码出了什么问题吗?
Process p2 = new Process();
p2.StartInfo.FileName = "powershell.exe";
p2.StartInfo.Verb = "runas";
p2.StartInfo.RedirectStandardOutput = true;
p2.StartInfo.RedirectStandardError = true;
p2.StartInfo.UseShellExecute = false;
p2.StartInfo.CreateNoWindow = true;
p2.StartInfo.Arguments = "$sh=New-Object -com Shell.Application" + " sh.NameSpace('" + webDrive + "').Self.Name = '" + newLabel + "'";
p2.Start();
string errors = p2.StandardError.ReadToEnd();
MessageBox.Show(errors);
【问题讨论】:
-
错误在哪一行? 真的知道这一点很有帮助
-
您是否尝试调试它以确保
webDrive和newLabel具有正确的值?
标签: c# powershell process.start