Created
May 11, 2012 09:08
-
-
Save rukeba/2658550 to your computer and use it in GitHub Desktop.
cscript: add path in system %PATH%, no reboot required
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var shell = WScript.CreateObject('WScript.Shell'); | |
var envs = shell.Environment('SYSTEM'); | |
var systemPath = envs('PATH'); | |
var paths = systemPath.split(';'); | |
if (WScript.Arguments.Count() != 1){ | |
WScript.StdErr.WriteLine('Error: one argument expected'); | |
WScript.StdErr.WriteLine('Paths in %PATH% :'); | |
for (i in paths){ | |
WScript.StdOut.WriteLine(paths[i]); | |
} | |
WScript.Quit(1); | |
} | |
var pathAdd = WScript.Arguments(0); | |
var found = false; | |
for (i in paths){ | |
//WScript.StdOut.WriteLine(paths[i]); | |
if (pathAdd.toLowerCase() == paths[i].toLowerCase()){ | |
found = true; | |
break; | |
} | |
} | |
if (found) { | |
WScript.StdOut.WriteLine('"' + pathAdd+'" already in %PATH%'); | |
} | |
else { | |
envs("PATH") = envs("PATH") + ";" + pathAdd; | |
WScript.StdOut.WriteLine('"' + pathAdd+'" added to %PATH%'); | |
WScript.StdOut.WriteLine(envs("PATH")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: