【发布时间】:2012-03-28 10:34:42
【问题描述】:
我正在尝试将 net user 与 c# 一起使用
System.Diagnostics.ProcessStartInfo proccessStartInfo = new System.Diagnostics.ProcessStartInfo("net user " + id + " /domain");
proccessStartInfo.CreateNoWindow = true;
System.Diagnostics.Process proc = new System.Diagnostics.Process {StartInfo = proccessStartInfo};
proc.Start();
string result = proc.StandardOutput.ReadToEnd();
textBoxOp.Text = result;
当我执行代码时出现Win32异常并显示消息系统找不到指定的文件
异常详情如下
在 System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) 在 GetUserFromAD.Form1.GetInformation(String id) 中 D:\GetUserFromAD\GetUserFromAD\Form1.cs:第 25 行 GetUserFromAD.Form1.button_Click(Object sender, EventArgs e) in D:\Ram\MyC#\GetUserFromAD\GetUserFromAD\Form1.cs:第 35 行 System.Windows.Forms.Control.OnClick(EventArgs e) 在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs 事件) 在 System.Windows.Forms.Control.WmMouseUp(消息和 m,鼠标按钮 按钮,Int32 点击)在 System.Windows.Forms.Control.WndProc(Message& m) 在 System.Windows.Forms.ButtonBase.WndProc(Message& m) 在 System.Windows.Forms.Button.WndProc(Message& m) 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg,IntPtr wparam,IntPtr lparam)在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(味精和味精)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID,Int32 原因,Int32 pvLoopData)在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 原因,ApplicationContext 上下文)在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 原因,ApplicationContext 上下文)在 GetUserFromAD.Program.Main() 在 D:\Ram\MyC#\GetUserFromAD\GetUserFromAD\Program.cs:第 18 行 System.AppDomain._nExecuteAssembly(Assembly 程序集,String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext、ContextCallback 回调、对象状态)在 System.Threading.ThreadHelper.ThreadStart()
【问题讨论】:
-
我不知道确切的原因,我可以说的解决方法是将该语句放在批处理脚本中并将该批处理脚本作为参数传递给 ProcessStartInfo API。
-
网络使用的更好做法:stackoverflow.com/questions/8919/…