使用java创建Windows用户帐户 [英] Creating a Windows user account with java

查看:468
本文介绍了使用java创建Windows用户帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以创建/删除Windows用户帐户并设置其权限以使用java代码将其设为管理员帐户,简单用户帐户或来宾帐户?

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>  

然后我们创建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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆