gpt4 book ai didi

c# - 从 C# 执行网络用户命令

转载 作者:太空狗 更新时间:2023-10-29 23:44:49 28 4
gpt4 key购买 nike

我想从 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();

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

这条命令的语法是:

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


C:\Windows\system32>

当我运行诸如 cd/、 dir 等简单命令时它运行良好。

最佳答案

我猜 Arguments 字符串末尾的转义反斜杠会杀死命令的/add 参数

"cmd /K \"net user ABC Admin123# /add\\\""

将是字符串

cmd /K "net user ABC Admin123# /add\"

所以尽量去掉末尾的\\。

关于c# - 从 C# 执行网络用户命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30803280/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com