Last active
March 9, 2023 11:03
-
-
Save adojos/414c0f611ea4ae8410227c9b119caf93 to your computer and use it in GitHub Desktop.
VBS: Write Windows Env Variables #vbs
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
Sub WriteEnvVar(strEnvVarType, strEnvVarName, strEnvVarValue, strWriteType) | |
Dim strOldVarValue, strNewVarValue | |
Dim strVarType | |
Set objShell = CreateObject("WScript.Shell") | |
Set objEnv = objShell.Environment(strEnvVarType) ' envVarType= System or User | |
Select Case strWriteType | |
Case strWriteTypeReplace | |
strOldVarValue = objEnv(strEnvVarName) | |
strNewVarValue = strEnvVarValue | |
objEnv(strEnvVarName) = strNewVarValue | |
WScript.StdOut.WriteBlankLines(1) | |
WScript.StdOut.WriteLine "SETTING " & strEnvVarName & " TO " & strNewVarValue & " ... DONE!" | |
WScript.StdOut.WriteBlankLines(1) | |
Case strWriteTypeAddNew | |
objEnv(strEnvVarName) = strEnvVarValue | |
WScript.StdOut.WriteBlankLines(1) | |
WScript.StdOut.WriteLine "CREATING " & strEnvVarName & " AND SETTING TO " & strEnvVarValue & " ... DONE!" | |
WScript.StdOut.WriteBlankLines(1) | |
End Select | |
Set objEnv = Nothing | |
Set objShell = Nothing | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment