Results 1 to 8 of 8
  1. #1
    .paul. is offline Member
    Join Date
    Jun 2012
    Posts
    73
    Blog Entries
    1
    Rep Power
    0

    Question java runas admin

    there must be a simple way to run a process as administrator in my java app.

    can anyone help?

  2. #2
    .paul. is offline Member
    Join Date
    Jun 2012
    Posts
    73
    Blog Entries
    1
    Rep Power
    0

    Default Re: java runas admin

    bump...

  3. #3
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default Re: java runas admin

    Um... I am a bit confused on what you are doing. My assumption though, is that you cannot use:
    Java Code:
     java MyClass
    because the program was installed on your computer as administrator (you are using Windows, no?). Usually this is not a problem. Are you trying to run this on the Command-Line and running into a problem?

    My other assumption is that you are trying to execute a program or command from your java application (hate the word app >:( ) that you want to run as admin. If that is the case, you would have to run your program as admin so it has the privilege and right to use admin level commands. I am not too sure if there is any other way to do this. I am using linux and it has been a while since I have used Windows, and running has another user might be a bit different or even a hack to get to work.
    My API:
    Java Code:
    cat > a.out || cat > main.class

  4. #4
    .paul. is offline Member
    Join Date
    Jun 2012
    Posts
    73
    Blog Entries
    1
    Rep Power
    0

    Default Re: java runas admin

    sorry i should've explained it better.

    this is the code i'm trying to run:

    Java Code:
    String[] cmd = { "mmc.exe","diskmgmt.msc" };
    Process exec = Runtime.getRuntime().exec(cmd);
    this is the error message i'm getting:

    Cannot run program "mmc.exe": CreateProcess error=740, The requested operation requires elevation

  5. #5
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Lightbulb Re: java runas admin

    From what I researched, it cannot be done in Java, by it's self. I took a 2 minute Google search to find out this issue. Try using Google to figure out your problems when they arise, it could be very beneficial, and your answers could come much quicker than depending on the folk who roam these forums.

    In linux, I would create a program shell, python etc program that would do this task for me, then return to the Java Program. It seems the same with Windows... except in your case, you will need to do some Visual C++ in order to achieve your goal.

    UAC Prompt From Java: CreateProcess error=740, The requested operation requires elevation (ShellExecuteEx Runas Example) - Mark S. Kolich

    This is a link to a guy who had the same problem as you. It will tell you everything he learned and why java will not do the job for you because of the UAC prompt in win-vista and win7...

    So you have 2 options:
    1. run the java program in a user that has higher privilages then you (admin perhaps). doing "runas /user:admin java MyClass" or something like that should be what you are looking for.
    2. otherwise, you can write the Visual C++ program to help with getting the runas prompt up for you.


    I hope this helps!
    My API:
    Java Code:
    cat > a.out || cat > main.class

  6. #6
    .paul. is offline Member
    Join Date
    Jun 2012
    Posts
    73
    Blog Entries
    1
    Rep Power
    0

    Default Re: java runas admin

    @kammce.

    i always do use google + most often, find a working answer. but not this time, so i took your advice + wrote a windowless c++ program...
    thanks for the help.

  7. #7
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default Re: java runas admin

    @.paul.

    Sweet! I am happy to have helped... if this is all solved for you, put [SOLVED] in the title of this forum thread. I think the actual solve button is still disabled, and that might be the only way to say that this thread is solved.
    My API:
    Java Code:
    cat > a.out || cat > main.class

  8. #8
    .paul. is offline Member
    Join Date
    Jun 2012
    Posts
    73
    Blog Entries
    1
    Rep Power
    0

    Default Re: java runas admin

    i won't mark this as RESOLVED just yet, in case anyone has a pure Java solution.

Similar Threads

  1. Admin Help Please
    By Ciwan in forum Forum Lobby
    Replies: 0
    Last Post: 06-27-2011, 04:52 PM
  2. Replies: 1
    Last Post: 12-20-2008, 09:28 PM
  3. Java SQL Admin Tool 2.4.2
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 11-12-2007, 06:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •