ich net user mit C#Wie net user mit C# verwenden
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;
Wenn dem ich den Code ausführen Win32-Ausnahme tritt mit der Meldung Das System kann die Datei angegeben nicht finden kann, verwenden versuchen
Details von Ausnahmen sind wie folgt
bei System.Diagnostics.Process.StartWithShellExecuteEx (Process sta rtInfo) bei GetUserFromAD.Form1.GetInformation (String-ID) in D: \ GetUserFromAD \ GetUserFromAD \ Form1.cs: Zeile 25 um GetUserFromAD.Form1.button_Click (Objekt Absender, EventArgs e) in D: \ Ram \ MyC# \ GetUserFromAD \ GetUserFromAD \ Form1.cs: Linie 35 bei System.Windows.Forms.Control.OnClick (EventArgse) bei System.Windows.Forms.Button.OnMouseUp (MouseEventArgs mevent) bei System.Windows.Forms.Control .WmMouseUp (Message & m, Maustasten Schaltfläche klickt Int32) bei System.Windows.Forms.Control.WndProc (Message & m) bei System.Windows.Forms.ButtonBase.WndProc (Message & m) bei -System. Windows.Forms.Button.WndProc (Nachricht & m) bei System.Windows.Forms.Control.ControlNativeWindow.WndProc (Message & m)
bei System.Windows.Forms.NativeWindow.DebuggableCallback (IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW (MSG & msg)
bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop (Int32 DwComponentID, Int32 Grund, Int32 pvLoopData) um System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner (Int32 Grund, ApplicationContext conte xt) um System.Windows.Forms.Application.ThreadContext.RunMessageLoop (Int32 Grund, ApplicationContext-Kontext) bei GetUserFromAD.Program.Main() in D: \ Ram \ MyC# \ GetUserFromAD \ GetUserFromAD \ Program.cs: Zeile 18 bei System.AppDomain._nExecuteAssembly (Montagebaugruppe, String [] args)
bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
bei System.Threading.ExecutionContext.Run (ExecutionContext ExecutionContext, Context Rückruf, Object Zustand) um System.Threading.ThreadHelper.ThreadStart()
Ich kenne nicht die genaue Ursache, umgehen kann ich sagen, ist diese Anweisung in einem Batch-Skript und übergeben Sie diese Batch-Skript als Argument an ProcessStartInfo API. – Zenwalker
Bessere Praktiken für den Nettoeinsatz: http://StackOverflow.com/Questions/8919/looking-for-best-practice-for-doing-a-net-use-in-c-sharp – Kiquenet