我想用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