Hi Guru's please help

I posted this in the other forum couple of days ago but nobody responded and
I need some answer so posting again here. Please help
----------------------------------
I have a vbscript intended to uninstall Autocad Lite 2002 versions on the
network using Machine based Group policy. The script works perfect if I run
it on the PC and uninstall works perfect. When I put the script into the
Machine based GP, the last line
"objSoftware.Uninstall()" does not seem to work. I can prove that by puting
echo commands and pause along the way. I turned on GPO logging on the test
PCs but does not give me any clue. Can anyone help please?

I am using windows 2000 servers and windows XP SP2 clients.

thanks
Eric

Here is the script:
----------------
strComputer = "."
Const HKEY_LOCAL_MACHINE = &H80000002
Set WSHShell=WScript.CreateObject("WScript.Shell")
Set fs=CreateObject("Scripting.FileSystemObject")
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_
strComputer & "\root\default:StdRegProv")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'AutoCAD Lite 2002'")

strKeyPath = _
"Software\Microsoft\Windows\CurrentVersion\Uninstall\{91E05F90-168E-43C0-BB48-39CD0F3F2678}"
strValueName = "DisplayName"
Return = objReg.GetExpandedStringValue(HKEY_LOCAL_MACHINE,_
strKeyPath,strValueName,strValue)
' If key does exist and display name is "AutoCAD Lite 2002" then run
uninstall command
If (Return = 0) And (strValue="AutoCAD Lite 2002") And (Err.Number = 0)
Then
For Each objSoftware in colSoftware
objSoftware.Uninstall()
Next
end if

----------------------------
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

0
Why bother testing for 'DisplayName'? If the ProductCode key exists, the product is installed, so just uninstall it.

Also, I've never had any success using WMI to uninstall. Instead, I'd recommend using the Windows Installer object. Radical, huh? :)
Const msiUILevelNone = 2
Set objInstaller = CreateObject("WindowsInstaller.Installer")
With objInstaller
.UILevel = msiUILevelNone
.InstallProduct( "foo.msi", "REMOVE=ALL")
End With
Set objInstaller = Nothing

or, using the Product Code instead of the MSI name:
Const msiUILevelNone = 2
Const myProductCode = "{432DB9E4-6388-432F-9ADB-61E8782F4593}"
Const msiInstallStateAbsent = 2
Set objInstaller = CreateObject("WindowsInstaller.Installer")
With objInstaller
.UILevel = msiUILevelNone
.ConfigureProduct myProductCode , 0 , msiInstallStateAbsent
End With
Set objInstaller = Nothing

Lastly, I'm puzzled by what you mean when you say "When I put the script into the Machine based GP". How are you doing that? Surely GP deployment is by MSI only...?
Answered 03/13/2008 by: VBScab
Red Belt

Please log in to comment
0
when deploying using AD and using WMI with impersonation I am guessing that you code would be running in local system context. As such you script would need to be at minimum copied local for it to work which I am guessing its not.

when using WMI you need to be aware of which user context you are running you script in.

a double click would inherit the clicking users context

i expect AD would switch to local system account, not that I have tested but I think this is the case.

Ian's script is a better option for AD based deployment.
Answered 03/13/2008 by: jmcfadyen
Fifth Degree Black Belt

Please log in to comment
0
ORIGINAL: jmcfadyen
Ian's script is a better option for AD based deployment.
I'm *still* wondering how the script is being run via AD... :(
Answered 03/14/2008 by: VBScab
Red Belt

Please log in to comment
0
Thank you VBscab for the fast response. In fact I am not a vbscript fellow and just learning. I thank you for what you have provided for.
I copied your script into my test computer based GP in the computer startup script. Im getting the following error:

Line: 7
Char: 3

Error: ConfigureProduct,Product,InstallLevel,InstallState
Code: 80004005
Source:MSI API error

Again this works perfect if I run it from my command line. Please advise out whats missing.

Eric
Answered 03/16/2008 by: eric_haiara
Senior Yellow Belt

Please log in to comment
0
thanks Jmcfadyen,

I am using computer based GP. I insert the script in the computer startup script section for the policy. In this case I believe the script is supposed to use computer account to run the script.

thanks
eric
Answered 03/16/2008 by: eric_haiara
Senior Yellow Belt

Please log in to comment
0
ORIGINAL: eric_haiara
I copied your script into my test computer based GP in the computer startup script.
Eric, since you don't state *which* of my examples you're using, I have assumed the second one, since line 7 of the first is the last line. It always helps to provide too much informatiobn, rather than too little. Anyway, line 7 is:

.ConfigureProduct myProductCode , 0 , msiInstallStateAbsent

I presume you have used the actual product's ProductCode and not the one from my example?

Also, you should be aware that the script sample is just that - a sample. There is no error-trapping, for example, and one of the first things to add would be a check to see if the product is actually installed. Add these additional constant s and add a test for the last:


Const msiInstallStateLocal = 3
Const msiInstallStateSource = 4
Const msiInstallStateDefault = 5
Answered 03/17/2008 by: VBScab
Red Belt

Please log in to comment
0
VBScab,
Thank you for be very helpful once again and I believe I am getting closure with your help. I am sorry for not providing enough information. Now i will provide more details. With your help, I modified the script and it looks like the one below. Again it works well when I test from command line. When I put it in the group policy, it doesn't work. I insert echo at different locations to step through the script when the PC boots and applies the policy. When it comes to the "For each" statement it seems jump out without stepping through all the installed products. I can see that by stepping through as the echo pops up. I can see it step through but does not complete instead jumps out and displays "Finished Script". Could this be anything to do with how group policy handles the script? Attached is the script. I am running this in windows XP SP2 under windows 2000 Domain.

script
----------------

Const RemoveProCode = "{91E05F90-168E-43C0-BB48-39CD0F3F2678}"
Const msiINSTALLSTATEABSENT = 2
Const msiInstallStateLocal = 3
Const msiInstallStateSource = 4
Const msiInstallStateDefault = 5
Const MsiRemoveSilent = 2
Set oInstaller = Wscript.CreateObject("WindowsInstaller.Installer")
Set oProducts = oInstaller.Products
WScript.Echo "starting soon"
For Each sProdCode in oProducts
WScript.Echo SProdCode
If (sProdCode = RemoveProCode) then
WScript.Echo "Found and removing now"
OInstaller.UIlevel = MsiRemoveSilent
oInstaller.ConfigureProduct sProdCode, 0, msiINSTALLSTATEABSENT
WScript.Echo "successfully removed"
Exit For
End If
Next
WScript.Echo "Finished script"
Set oProducts = Nothing
Set oInstaller = Nothing
-------------

Thanks once again for your generosity

Eric
Answered 03/17/2008 by: eric_haiara
Senior Yellow Belt

Please log in to comment
0
If the script is jumping straight out of the loop, it evidently thinks there is no such product installed. Is the product installed per-user or per-machine? I'm just thinking out loud...
Answered 03/18/2008 by: VBScab
Red Belt

Please log in to comment
0
I am installing the product mannually for the test. I believe when its installed anyone can use it so it seems like per computer install.

In the real production some have been installed per user policy and some have been installed by manual process by users.

Eric
Answered 03/18/2008 by: eric_haiara
Senior Yellow Belt

Please log in to comment
0
Having run the script on my test VM, it seems it doesn't matter whether it's per-machine or per-user: it finds all installed products. So, the answer's the same as post #9 - if the script jumps out of the loop it thinks the product isn't installed.
Answered 03/19/2008 by: VBScab
Red Belt

Please log in to comment
0
Thanks VBScab,

I have finally unlocked the mistry as to why uninstall by policy would to work. This is an issue with Autocad Licensing- it is licensed per user and on computer. Therefore, when one installs the software on a PC the software is available only to that user only. If another user wants to use Autocad on the same machine he has to install it again for his profile. I am able to prove that by logging in as different users and testing the script with different test softwares using different cases. Other software uninstall cases work perfect as I expect(uninstall by script regardless of who installed it) but Autocad doesn't. Interestly as well, if the software is installed by machine-based AD policy - it is avaiable to everyone regardless of who logs on and uninstall by script works perfect as well.

Now I am caught in the dilema what how to automat the uninstall process. Any ideas at the moment...
Answered 03/24/2008 by: eric_haiara
Senior Yellow Belt

Please log in to comment
0
Eric, I'm now wondering why you're using script to uninstall. Wasn't AC installed by MSI to begin with? If so, deleting users from the group associated with the Group Policy will cause an uninstall, won't it? Unless for some reason that option (Uninstall this application when it falls out of the scope of management') wasn't selected when the package was added, of course...

If you're persisting with script, I think your best option is to simply call MSIExec with an appropriate command line and then call MSIZap (available as part of the free d/l Windows Installer SDK), both as an admin-level user.
Answered 03/25/2008 by: VBScab
Red Belt

Please log in to comment
0
VBScab, good question - the answer is a long story. The software was installed by two methods. Some were pushed out by per-user GP and others were installed manually. The per-user installation is terrible as when users roam from PC to PC the Software got installed on all PCs they logged on. We have huge numbers of unathorised copies installed now. we don't blame them though. We blame ourselves and the consultants who advised us this process though sometimes ago. to put a stop to that we had to put a stop to further installations. To do that we remove the software installation settings in GP and allowed the already installed ones to keep on running. Our plan is to deply the software by computer-based policy after removing the current installations.

I will try the other options including the one you advised and I the progress posted here again.

Thanks once again for all your help
Eric
Answered 03/25/2008 by: eric_haiara
Senior Yellow Belt

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