Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's some VBScript I use for this:</p> <pre><code>set args = WScript.Arguments Set objShell = WScript.CreateObject("WScript.Shell") Set colSystemEnvVars = objShell.Environment("System") Set colUserEnvVars = objShell.Environment("User") ' Parse args select case args.Count case 0, 1, 2 help case 3 sVariable = args(0) sValue = args(1) sScope = UCase(args(2)) sMode = "" case 4 sVariable = args(0) sValue = args(1) sScope = UCase(args(2)) sMode = UCase(args(3)) end select select case sScope case "S" if sMode = "A" then sValue = colSystemEnvVars(sVariable) &amp; sValue end if colSystemEnvVars(sVariable) = sValue case "U" if sMode = "A" then sValue = colUserEnvVars(sVariable) &amp; sValue end if colUserEnvVars(sVariable) = sValue case else help end select WScript.Quit '****************************************************************************** Sub help() WScript.Echo "" WScript.Echo "Create or update an environment variable." WScript.Echo "" WScript.Echo "usage:" WScript.Echo "======" WScript.Echo "cscript SetVar.vbs variable value {S|U} [A]" WScript.Echo "" WScript.Echo "eg:" WScript.Echo "===" WScript.Echo "cscript SetVar.vbs MYVAR 'Hello world' U" WScript.Echo "cscript SetVar.vbs PATH 'C:\MyPath' S A" WScript.Quit End Sub </code></pre> <p>The scope can be 'S'ystem or 'U'ser. The last argument, 'A', if present, appends the value to the existing value of the variable (useful for adding a directoy to the PATH system variable).</p> <p>The variables will presist, but you'll have to close then re-open a console to use them. I usually run this from the "Run..." dialog, then open a console.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload