how can remove environment variable if exist , while installation ?


0 Comments   [ + ] Show Comments


Please log in to comment

Community Chosen Answer


Assuming you mean this (you need to be more clearer in your question info), then:

Set oShell = CreateObject("WScript.Shell")
If oShell.ExpandEnvironmentStrings("%appdata%") = "%appdata%"
Then WScript.Echo "Does not exist"
Answered 08/23/2013 by: mattski
Second Degree Green Belt

Please log in to comment




I was thinking some thing like that :

vbs :

Set WshShell = WScript.CreateObject("WScript.Shell")

Set sysvarenv = WshShell.Environment("User") 'System|User
'Set environement variable 
sysvarenv("NINJA") = "itninja.com"
'Get the variable value
strvartest = WshShell.ExpandEnvironmentStrings("'%ITNINJA%'")
'Check it and remove it 
if strvartest  <>"" then sysvarenv.Remove "NINJA"
ps1 :
Set-Location env:
#Set environement variable 
New-Item ninja -Value 'itninja.com'
#Get environement variable value 
$vartest = Get-Content ninja -ErrorAction Stop
#Check it and remove it
if ($vartest -ne $null) { Remove-Item env:ninja }
Answered 08/23/2013 by: egiberne
Second Degree Brown Belt

Please log in to comment
Answer this question or Comment on this question for clarity