Skip to content

Instantly share code, notes, and snippets.

@rukeba
Created May 11, 2012 09:08
Show Gist options
  • Save rukeba/2658550 to your computer and use it in GitHub Desktop.
Save rukeba/2658550 to your computer and use it in GitHub Desktop.
cscript: add path in system %PATH%, no reboot required
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"));
}
@rukeba
Copy link
Author

rukeba commented May 11, 2012

Usage:

cscript add_to_system_path.js C:\strawberry\perl\bin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment