Skip to content

Instantly share code, notes, and snippets.

@hymkor
Last active August 29, 2015 14:08
Show Gist options
  • Save hymkor/b4ee5c957e45cd7c114d to your computer and use it in GitHub Desktop.
Save hymkor/b4ee5c957e45cd7c114d to your computer and use it in GitHub Desktop.
Windows で vipw っぽく、システムのデフォルト%PATH%を変更する ref: http://qiita.com/zetamatta/items/2919f0a794e6373eb964
Option Explicit
If WScript.Arguments.Count <= 0 Then
Dim shellApp : Set shellApp = CreateObject("Shell.Application")
shellApp.ShellExecute "wscript.exe","""" & WScript.ScriptFullName & """ uac" , "" , "runas"
Set shellApp = Nothing
WScript.Quit
End If
Dim wshShell : Set wshShell=CreateObject("WScript.Shell")
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim sysEnv : Set sysEnv=wshShell.Environment
Dim path : Path = sysEnv.Item("Path")
Dim TempName : TempName = objFSO.GetTempName()
Dim objWriter : Set objWriter = objFSO.CreateTextFile(TempName,True,False)
objWriter.WriteLine( Replace(Path,";",vbcrlf) )
objWriter.Close()
Set objWriter = Nothing
Dim objExec : Set objExec = wshShell.Exec("notepad " & TempName)
Do While objExec.Status = 0
WScript.Sleep 100
Loop
Dim output : output = objExec.StdOut.ReadAll
If len(output) > 0 Then
WScript.Echo output
End If
output = objExec.Stderr.ReadAll
If len(output) > 0 Then
WScript.Echo output
End If
Dim objReader : Set objReader = objFSO.OpenTextFile(TempName,1)
Path = objReader.ReadAll
Path = Replace(Path,vbcrlf,";")
Path = Replace(Path,vbcr,";")
Path = Replace(Path,vblf,";")
Path = Replace(Path,";;",";")
If Right(Path,1) = ";" Then
Path = Left(path,len(path)-1)
End If
objReader.Close()
Set objReader = Nothing
rem WScript.Echo Path
objFSO.DeleteFile(TempName)
sysEnv.Item("Path") = Path
Set objFSO = Nothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment