我想用net user用户用C#如何使用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 STA如下
rtInfo)在GetUserFromAD.Form1.GetInformation(String id) D:\ GetUserFromAD \ GetUserFromAD \ Form1.cs:第25行 GetUserFromAD.Form1.button_Click(Object sender,EventArgs e) D:\ Ram \ MyC# \ GetUserFromAD \ GetUserFromAD \ Form1.cs:第35行 System.Windows.Forms.Control.OnClick(EventArgs e)at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)at System.Windows.Forms.Control .WmMouseUp(消息&米,MouseButtons 按钮,点击的Int32)在 System.Windows.Forms.Control.WndProc(消息& m)上 System.Windows.Forms.ButtonBase.WndProc(消息& m)上 系统。 Windows.Forms.Button.WndProc(消息& m)上 System.Windows.Forms.Control.ControlNativeWindow.WndProc(消息&米)
在System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr的的HWND, 的Int32味精,IntPtr的WPARAM,IntPtr的LPARAM)在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG & MSG)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(的Int32 dwComponentID,的Int32原因,的Int32 pvLoopData)在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason,ApplicationContext conte xt) D:\ Ram \ MyC#\ GetUserFromAD \ GetUserFromAD \ Program.cs中的GetUserFromAD.Program.Main() System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,ApplicationContext上下文):line 18在 System.AppDomain._nExecuteAssembly(大会组件,字串[] args)
在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在System.Threading.ExecutionContext.Run(的ExecutionContext 的ExecutionContext,ContextCallback回调,对象状态)在 System.Threading.ThreadHelper.ThreadStart()
我不知道确切的原因,我可以说解决方法是将该语句放在批处理脚本中,并将该批处理作为参数传递给ProcessStartInfo API。 – Zenwalker 2012-03-28 10:39:01
网络使用的更好实践:http://stackoverflow.com/questions/8919/looking-for-best-practice-for-doing-a-net-use-in-c-sharp – Kiquenet 2013-05-13 06:34:45