WMIC Envirornment - How to activate?

Microsoft Windows xp professional w/serv...
June 12, 2010 at 12:38:21
Specs: Windows Server 2003 SP2
OK, I've created a batch file to add a folder to
the System %path%. Works great in XP:
updates System %path%, new command
window reflects the addition when I echo
%path%. When I run the same code on Server
2003, the System %path% does indeed get
updated (when viewed with WMIC), but not activated. Am I missing a
step? Is there a way to "force" the activation?



	ECHO Source path not found: %1
	ECHO Exiting...
SET path_to_add=%~1

SET path_var=
FOR /F "usebackq tokens=2 delims==" %%a IN (`WMIC Environment WHERE ^(Name^='PATH' AND SystemVariable^='True'^) GET VariableValue /FORMAT:LIST`) DO (
	FOR /F "tokens=* delims=" %%b IN ("%%a") DO (
		SET path_var=!path_var!%%b

SET test_var=!path_var:%%=%%%%!
SET test_var="!test_var!"
SET test_var=!test_var:;=","!
CALL :test_path !test_var!

IF "!dupe!" EQU "no" (
	ECHO !path_msg!
	SET path_var=!path_var!;%path_to_add%
	WMIC Environment WHERE ^(Name^='PATH' AND SystemVariable^='True'^) SET VariableValue='!path_var!'
) ELSE (
	ECHO !path_msg!


SET dupe=no
SET path_msg=Adding to %%path%%: "%path_to_add%"
SET var=%1
	SET var=!var:"=!
	IF "!var!" EQU "%path_to_add%" (
		SET dupe=yes
		SET path_msg=Already found in %%path%%: "%path_to_add%"
	GOTO loop


And can be found here: Tools/Add.to.System.Path.bat">Add.to.System.Path.bat

Edit: Post edited a half dozen times to show correct alignment and formatting. Anyway to avoid wrapping on this forum?

See More: WMIC Envirornment - How to activate?

Report •

June 12, 2010 at 12:54:18
I also would like to add that once I went into:
System Properties > Advanced > Environment Variables,
"Path" reflected my additions. Clicking OK activated the %path%
statement when I opened a new command window. I'd like to
avoid drilling down that much just to click OK. Hence the batch. I
am not aware if SETX exhibits the same behavior in Server 2003.

Report •

June 13, 2010 at 14:13:46
I don't use wmic(xp home :/ ) but my guess would be that you need to send a "WM_SETTINGCHANGE" to all windows(or at least explorer). It should be doing this on it's own......

I doubt you would be able to send such a message using wmic, but that's just a guess.

Report •

June 13, 2010 at 19:54:28
Thanks Judago!
That looks to be pretty close to what I need :-)

Report •

Related Solutions

Ask Question