WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Environment

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

EnvironmentSet UDF

 Keywords: EnvironmentSet EnvironSet User System Environment Set Settings Variable

; ----------------------------------------------------------------------------------------------
; Set a user or system environment variable.
; The first parameter is the environment variable's name.
; The second parameter is the environment variable's value.
; Set the third parameter to @FALSE for a user variable, @TRUE for a system variable.
; Les Ferch, July 2008

#DefineFunction EnvironmentSet(Name,Value,SystemEnv)
If Name=="" Then Return @FALSE
Hive = @REGCURRENT
KeyVal = StrCat("Environment[",Name,"]")
If SystemEnv
   Hive = @REGMACHINE
   KeyVal = StrCat("System\CurrentControlSet\Control\Session Manager\Environment[",Name,"]")
EndIf
Result = RegSetExpSz(Hive,KeyVal,Value)
IntControl(59,-1,"Environment",0,0) ; Make the change immediate
Return Result
#EndFunction

; Set a user environment variable
EnvironmentSet("TestU","I'm a user variable",@FALSE)

; Set a system environment variable
EnvironmentSet("TestS","I'm a system variable",@TRUE)

Article ID:   W17861
Filename:   EnvironmentSet UDF.txt
File Created: 2010:04:15:13:55:30
Last Updated: 2010:04:15:13:55:30