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.

Edit of an Environment Variable

Keywords: 	   Edit of an Environment Variable

 ; PUT a  ; on the end of the string to find !!!!
getridof="C:\TEMP;"  
getlen=StrLen(getridof)


syseve="SYSTEM\CurrentControlSet\Control\Session Manager\Environment[path]"
valtype=RegEntryType(@regmachine,syseve)   ;Could be RG_SZ or RG_SZ_EXP
; we need to preserve the type and other contents

;Get the system environement variable. 
value=RegQueryEx(@RegMachine,syseve,@tab,valtype)
;put an extra ; on the end
value=strcat(value,";")
;search for the string; to remove

x=StrIndexNC(value,getridof,0,@FWDSCAN)
If x==0           ; c:\temp; not found
   newvalue=oldvalue
Else
   ;get important parts
   front=StrSub(value,1,x-1)
   back=StrSub(value,x+getlen,-1)
   newvalue=StrCat(front,back)
   ;fix multiple ;; if any
   newvalue=StrReplace(newvalue,";;",";")
   ;if first char is a ; fix it
   If StrSub(newvalue,1,1)==";" Then newvalue=StrSub(newvalue,2,-1)
   ;if last char is a ; fix it
   If StrSub(newvalue,StrLen(newvalue),1)==";" Then newvalue=StrSub(newvalue,1,StrLen(newvalue)-1)
EndIf


RegSetEx(@regmachine,syseve,newvalue,@tab,valtype)

Message(value,newvalue)     ; Debug Only





Article ID:   W15490
File Created: 2003:05:13:11:28:10
Last Updated: 2003:05:13:11:28:10