Manikandan
Manikandan

Reputation: 1519

Need to run the command without opening the dos prompt

I have used the following code to make a folder undeletable in my java project. It works fine. When I create an exe of my project the dos prompt doesn't get disappeared.

cmd.exe /c start  icacls "folder name" /e /c /d %username%

I also tried without opening the dos prompt. But it doesn't work.

icacls ONGX32/winkrl /e /c /d %username%

Upvotes: 0

Views: 462

Answers (4)

Manikandan
Manikandan

Reputation: 1519

I found a simple way. Created a .bat temporary file consists of that command. Used that .bat file. It didn't open the command prompt.

Upvotes: 0

Charles Goodwin
Charles Goodwin

Reputation: 6642

In a command prompt, the command exit closes it.

You can run multiple commands on one line using the && command separator.

It should be something like this:

cmd /c icacls "folder name" /e /c /d %username% && exit

Upvotes: 0

Sajid
Sajid

Reputation: 4421

Instead use:

cmd /c icacls "folder name" /e /c /d %username%

start is sort of the same as cmd /c, so you don't need both.

Upvotes: 1

alexisdm
alexisdm

Reputation: 29886

The variable %username% is replaced by its value by cmd.exe.

You need to get it with System.getenv("username"), and replace it yourself in the command string.

Edit. You may also need to use the fully qualified path to icacls.exe.

Upvotes: 0

Related Questions