problem uninstalling an add-in

F

filo666

yesterday I asked:

Hi, I'm trying to figure out how to accomplish somehting:

I have an add-in and I would like it to chek the computer's name when
installed, if the computer's name does not match the default registered
computer's name (Leon1 in this case) then the add-in is uninstalled
(uninstall itself).
The code works fine until the AddIns("Periodical Table").Install=false is
called:


Private Sub Workbook_AddinInstall()
strComputer = "."
Set objWMIService = GetObject("winmgmts:" &
"{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery("Select * from
Win32_ComputerSystem")
With Workbooks("periodical Table.xla").Sheets(2)
For Each objComputer In colSettings
If LCase(objComputer.Name) <> "leon1" Then
MsgBox "The program has detected that you coppied the add-in, please contact
your program provider", vbOKOnly, "Illegal copy detection"
AddIns("Periodical Table").Installed=false
Else: GoTo nx
End If
Next
End With
nx:
End Sub


It does not appear any error, the msgbox works well but it nevers uninstall
the add-in.

TIA
 
F

filo666

please note that I add the AddIns("Periodical Table").Installed=false
correctly, yesterdays post suggested that I wrot wrongly the command,
however, the command was well written obtaining the same results

How to uninstall the add-in???
 
P

papou

Hello

You should consider using the API function GetComputerName instead, it would
prevent you from using a loop.
Place this in the top declaration in your module:

And then amend your code as follows:
Private Sub Workbook_AddinInstall()
Dim sTempString As String, sCompName As String
Dim lBuffer As Long
sTempString = Space(250)
lBuffer = 251
GetComputerName sTempString, lBuffer
sCompName = Split(sTempString, Chr(0))(0)
If Lcase(sCompName) <> "leon1" Then
AddIns("Periodical Table").Installed = False: Exit Sub
End If
End Sub

HTH
Cordially
Pascal
 
P

papou

Oops, sorry, forgot to paste the declaration part, so here it is:

Private Declare Function GetComputerName Lib "kernel32" Alias
"GetComputerNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long

Cordially
Pascal
 
F

filo666

Thanks for answering, it does not work, it necers uninstall the add in, any
idea why??
 
C

Charles Williams

Try using Workbook_Open instead of AddinInstall,
and add a Thisworkbook.Close if its illegal
and you may also need On Error Resume Next for the .Installed=false


Charles
__________________________________________________
Outlines for my Sessions at the Australia Excel Users Group
http://www.decisionmodels.com/OZEUC.htm
 
P

papou

Is the Add-In already shown int the tools addins list?
In which case you will need to uncheck it and try again.

HTH
Cordially
Pascal
 
D

Dave Hart

AddIns("Periodical Table").Install=false does not remove the Addin,
it simply unticks it in the list of addins.
You will also have to delete the addin file.

Dave Hart
 
F

filo666

It worked fine charles the only thing is that the add-in is still selected
even do that it is not open any more; however I accomplish what I wanted to.

I'm just a little courious why it did not worked well with the
..installed=false command

Thanks both of you for your help.

Gratings from Israel
 
C

Charles Williams

Without doing some tests I am not sure, but it probably has something to do
with the sequence of the events, and the fact that the registry entries for
addins are only written when excel closes.


regards
Charles
__________________________________________________
Outlines for my Sessions at the Australia Excel Users Group
http://www.decisionmodels.com/OZEUC.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

uninstall an add-in 1
uninstall-add in 1
uninstall add in 1
Get CPU Priority of a ProcessID 2
Cell variable 0
Need Help 0
Close one mdb open another 2
VBA WMI Intermittent Error 0

Top