使用 java 创建 Windows 用户帐户 [英] Creating a Windows user account with java
问题描述
是否可以使用java代码创建/删除Windows用户帐户并设置其权限以使其成为管理员帐户,简单用户帐户或访客帐户?
Is it possible to create/delete windows user account and set its privileges to make it admin account , simple user account or guest account using java code ?
推荐答案
当我问这个问题已经一年了,我忘记发布答案了.对不起:)
It's been already 1 year when i asked this question and i forgot to post the answer. I'm sorry :)
要创建用户帐户,我们需要通过用我们的程序包装清单文件来获得管理权限.清单文件必须与程序同名.这个文件应该是这样的:
to create a user account we need administrative privileges by wrapping a manifest file with our program. the manifest file must have the same name as the program. this how this file should look like:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="highestAvailable" uiAccess="False" />
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
然后我们创建我们的 userAccount 程序:
then we create our userAccount program :
import java.io.IOException;
public class UserAccount {
public static void main(String[] args){
String userName = "foo";
try {
Runtime.getRuntime().exec("net user " + userName + " /add");
} catch (IOException e){
e.printStackTrace();
}
}
}
就我而言,我使用 launch4j 工具用 .jar 文件包装清单并使程序正常工作:)
in my case i used the launch4j tool to wrap the manifest with the .jar file and get the program working :)
这篇关于使用 java 创建 Windows 用户帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!