小编Vim*_*rma的帖子

从C#执行net user命令

我想从C#执行net user命令。

下面是我的代码:

         ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd.exe");
         procStartInfo.UseShellExecute = true;
         procStartInfo.CreateNoWindow = true;
         procStartInfo.Verb = "runas";
         procStartInfo.Arguments = "/env /user:" + "Administrator" +  "cmd /K \"net user ABC Admin123# /add\\\"";

         ///command contains the command to be executed in cmd
         System.Diagnostics.Process proc = new System.Diagnostics.Process();
         proc.StartInfo = procStartInfo;
         proc.Start();
Run Code Online (Sandbox Code Playgroud)

当我运行程序时,命令提示符窗口将以管理模式打开,并显示以下结果:

该命令的语法为:

NET USER
[username [password | *] [options]] [/DOMAIN]
         username {password | *} /ADD [options] [/DOMAIN]
         username [/DELETE] [/DOMAIN]
         username [/TIMES:{times | ALL}]


C:\Windows\system32>
Run Code Online (Sandbox Code Playgroud)

当我运行cd /等简单命令时,dire.tc。运行正常。

c# asp.net cmd window window-server

5
推荐指数
1
解决办法
1194
查看次数

标签 统计

asp.net ×1

c# ×1

cmd ×1

window ×1

window-server ×1