Creating a Windows user account with java

天大地大妈咪最大 提交于 2019-12-04 04:53:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!