使用命令行从 PHP 创建 Windows 2019 用户
我需要从PHP Web应用程序中将用户添加到Windows 2019 Web服务器 我正在使用命令行命令:
NET USER sbarker mypassword /ADD /FULLNAME:"Sue Barker" /PASSWORDCHG:NO /PASSWORDREQ:YES /LOGONPASSWORDCHG:NO /EXPIRES:NEVER
当在服务器上登录为管理员时,从标准命令行(如您期望),这可以正常工作。
要从PHP实现此功能,我正在使用以下内容,我认为这是正确的语法/格式:
<?php
$username = "sbarker";
$userpass = "secure1";
$fullname = "Sue Barker";
echo exec("start cmd /C:\Users\Administrator NET USER $username $userpass /ADD /FULLNAME:$fullname /PASSWORDCHG:NO /PASSWORDREQ:YES /LOGONPASSWORDCHG:NO /EXPIRES:NEVER");
?>
这可能不会产生新用户,这可能是由于权限。 我需要设置哪些权限以允许用户创建? 从安全的角度来看,我的负债是什么? 是否有更好的方法可以从PHP Web应用程序创建Windows用户。
编辑:
尝试以下方面没有成功:
<?php
$test = shell_exec('C:\\WINDOWS\\system32\\cmd.exe /c 2>&1 "NET USER test test /ADD"');
echo "<pre>$test</pre>";
?>
结果是系统错误5发生了。访问被拒绝。
错误
I have a requirement to add a user to my windows 2019 web server from a PHP web application
I am using a command line command:
NET USER sbarker mypassword /ADD /FULLNAME:"Sue Barker" /PASSWORDCHG:NO /PASSWORDREQ:YES /LOGONPASSWORDCHG:NO /EXPIRES:NEVER
This works fine from a standard command line when logged on as administrator on the server (as you would expect).
To implement this from PHP I am using the following, which I believe to be the correct syntax/format:
<?php
$username = "sbarker";
$userpass = "secure1";
$fullname = "Sue Barker";
echo exec("start cmd /C:\Users\Administrator NET USER $username $userpass /ADD /FULLNAME:$fullname /PASSWORDCHG:NO /PASSWORDREQ:YES /LOGONPASSWORDCHG:NO /EXPIRES:NEVER");
?>
This produces no new user, probably because of permissions.
What permissions do I need to set to allow user creation?
What are my liabilities from a security point of view?
Is there a better way of creating a windows user from a PHP web application.
EDIT:
Tried the following with no success:
<?php
$test = shell_exec('C:\\WINDOWS\\system32\\cmd.exe /c 2>&1 "NET USER test test /ADD"');
echo "<pre>$test</pre>";
?>
The result was a System error 5 has occurred. Access is denied.
error
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过广泛的研究和死胡同,微软似乎已经将其锁定到无法以编程方式添加用户的程度。就我个人而言,我希望他们能让开发人员选择以提升的权限执行批处理脚本,而不是“只是说不”。
基本的答案是,看起来这是不可能的。
After extensive research and dead ends, it looks like Microsoft has locked this down to such an extent that programmatically adding users is not possible. Personally I wish they would give developers the choice to execute batch scripts with elevated privileges rather than 'just saying no'.
The basic answer is that it looks like this is not possible.
这仍然是有可能的,而且我刚刚做到了。
您需要将应用程序池身份设置为管理员,然后它才能工作。
This is very much still possible, and i just did it.
You need to set the Application Pool identity as administrator, then it shall work.