if environment variables exist remove while installation
Hi
how can remove environment variable if exist , while installation ?
0 Comments
[ + ] Show comments
Answers (2)
Please log in to answer
Posted by:
mattski
11 years ago
Posted by:
egiberne
11 years ago
Hi,
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 }