Created
April 4, 2015 14:12
-
-
Save hymkor/679769f76f29abbbec11 to your computer and use it in GitHub Desktop.
Windows でデフォルトの %PATH% を変更する(JScript編)
This file contains 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
if( WScript.Arguments.length <= 0 ){ | |
var shellApp = new ActiveXObject("Shell.Application"); | |
shellApp.ShellExecute( "wscript.exe","\"" + WScript.ScriptFullName + "\" uac" , "" , "runas"); | |
shellApp = null; | |
WScript.Quit(); | |
} | |
var wshShell=new ActiveXObject("WScript.Shell"); | |
var objFSO = new ActiveXObject("Scripting.FileSystemObject"); | |
var sysEnv=wshShell.Environment; | |
var path = sysEnv.Item("PATH"); | |
var TempName = objFSO.GetTempName(); | |
var objWriter = objFSO.CreateTextFile(TempName,true,false); | |
objWriter.Write( path.replace(/;/g,"\r\n").replace("[\r\n]+$","") ); | |
objWriter.Close(); | |
var objWriter = null; | |
var objExec = wshShell.Exec("notepad " + TempName); | |
while(objExec.Status == 0 ){ | |
WScript.Sleep(100); | |
} | |
var output = objExec.StdOut.ReadAll(); | |
if( output != "" ){ | |
WScript.Echo( output ); | |
} | |
output = objExec.Stderr.ReadAll(); | |
if( output != "" ){ | |
WScript.Echo( output ); | |
} | |
var objReader = objFSO.OpenTextFile(TempName,1); | |
path = objReader.ReadAll(); | |
path = path.replace(/\r*\n/g,";"); | |
path = path.replace(/;;+/g,";"); | |
path = path.replace(/;+$/g,""); | |
objReader.Close(); | |
objReader = null; | |
objFSO.DeleteFile(TempName); | |
sysEnv.Item("PATH") = path; | |
objFSO = null; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment