0

I am trying to share a folder from within java using the following windows command: net share shareName=C:\folderName /grant:everyone,FULL

This command needs to be run as admin. Running it in the default cmd window gives a permissions error, but running it in cmd as admin works.

I am aware that you can run a command from within java using Runtime.getRuntime().exec("commandHere");. However, this does not execute it as admin. I've looked around, but everything either pertains to running a file as admin, or opening cmd as admin, neither of which I want to do. I just want to execute that one command.

Blaine
  • 332
  • 1
  • 4
  • 18
  • I would argue that this is not a duplicate. The linked answer shows only how to run a file as admin, which i do not want to do. The runas command also does not work – Blaine Mar 25 '17 at 11:45

1 Answers1

0

I believe you can run the program as Admin.

either create batch file with admin privs or launch command/powershell in admin mode and then launch java program.

I don't think windows will allow you to run program in admin mode without admin access. [of course for security reasons]

Also, I am not sure if java allows automatic elevating privileges with users permission like those allow, deny prompts with admin icon.

Amit
  • 155
  • 2
  • 8
  • won't be able to run the program as admin for various reasons unfortunately. And I don't need to run it as admin without admin rights: I'm fine with the user needing to enter their credentials at that point in the program. An acceptable solution would also be to launch cmd as admin and have it displayed for the .5 seconds necessary to execute the command – Blaine Mar 25 '17 at 11:35