问题
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 ?
回答1:
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>
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();
}
}
}
in my case i used the launch4j tool to wrap the manifest with the .jar file and get the program working :)
来源:https://stackoverflow.com/questions/22735444/creating-a-windows-user-account-with-java