Delete System environment Variable

I'd like to delete active System environment Variable "TZ" which was set by other application. So, I made a vbscript as following
But this script works well in dos command but doesn't work inside package.
DIM objShell
set objShell = wscript.createObject("wscript.shell")
objShell.Run "%COMSPEC% /C ", 0, TRUE
objShell.Run "reg DELETE ""HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"" /v TZ /f", 0, TRUE

and I made another Vbscript as following. it works well in dos command but doesn't work either with MSI
On Error Resume Next

Comments

Answers

0

OK, a few points:

- The first script fails because you can't use the 'WScript' directive in Custom Actions that run 'inside' the WI engine (as opposed to being exracted and run as a normal script). The engine uses its own interpreter, whereas the 'WScript' directive is unique to Windows Scripting Host. Thus:set objShell = wscript.createObject("wscript.shell") should be changed to:set objShell = createObject("wscript.shell") Note that this only applies to the directive, not object names/Prog IDs (e.g. "WScript.Shell")
- The second script looks OK. You have error-trapping set to 'Resume Next' so add some code to check that a) objReg got created (using 'IsObject(objReg)') and whether the 'DeleteValue' method worked by checking the content of Err.Number
- Why not simply use the RemoveRegistry table?

In fact I tried environment variable table but it doesn't work. and I found strange sympthom.

I was deleting system environment variable in MSP (patch) using command
--> msiexec /p xyz.msp /qn and it never succeeded to remove variable set by original package.
However when I made a small package MSI and run command
--> msiexec /i abc.msi /qn and it seems to work well and I don't need any CA.