I am using procrun to run a java application as a service.
I used following to set path:
set PATH="dir1;dir2;%PATH%"
procrun.exe //US//%SERVICE_NAME% ++Environment PATH=%PATH%
which updates environment value in registry as:
But, in my Java application when I try to get the value of PATH:
System.getenv("PATH")
I get only the first value ( i.e. dir1 in above case. If I set the path to dir2;dir1;%PATH%, I get only dir2)
Am I retrieving in a wrong way or setting in a wrong way?

Your problem is caused by the lack of quoting in the
--Environmentoption:(cf. Procrun documentation).
Since Windows expands
%PATH%to a list of;-separated paths, you need to use:or
PATH='%PATH'if you prefer. The single quote character is stripped from the parameter string after breaking it into a;-separated list of parameters (cf. source code). Hence there might be a problem if you have single quotes in the name of a folder.Edit: procrun also accepts quoting through double quotes (which are not stripped) and your
PATHvariable contains quotes, but the magic of cmd.exe strips them away.