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
filo666 - 23 Jan 2008 08:21 GMT
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???
> yesterday I asked:
>
[quoted text clipped - 31 lines]
>
> TIA
papou - 23 Jan 2008 09:25 GMT
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
> please note that I add the AddIns("Periodical Table").Installed=false
> correctly, yesterdays post suggested that I wrot wrongly the command,
[quoted text clipped - 40 lines]
>>
>> TIA
papou - 23 Jan 2008 09:28 GMT
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
> Hello
>
[quoted text clipped - 63 lines]
>>>
>>> TIA
filo666 - 23 Jan 2008 10:02 GMT
Thanks for answering, it does not work, it necers uninstall the add in, any
idea why??
> Oops, sorry, forgot to paste the declaration part, so here it is:
>
[quoted text clipped - 72 lines]
> >>>
> >>> TIA
papou - 23 Jan 2008 10:09 GMT
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
> Thanks for answering, it does not work, it necers uninstall the add in,
> any
[quoted text clipped - 78 lines]
>> >>>
>> >>> TIA
papou - 23 Jan 2008 10:13 GMT
Also consider Charles'suggestion.
Cordially
Pascal
> Is the Add-In already shown int the tools addins list?
> In which case you will need to uncheck it and try again.
[quoted text clipped - 86 lines]
>>> >>>
>>> >>> TIA
Charles Williams - 23 Jan 2008 10:07 GMT
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
> yesterday I asked:
>
[quoted text clipped - 33 lines]
>
> TIA
filo666 - 23 Jan 2008 12:27 GMT
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
> Try using Workbook_Open instead of AddinInstall,
> and add a Thisworkbook.Close if its illegal
[quoted text clipped - 42 lines]
> >
> > TIA
Charles Williams - 23 Jan 2008 13:47 GMT
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
> 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
[quoted text clipped - 54 lines]
>> >
>> > TIA
Dave Hart - 23 Jan 2008 12:19 GMT
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
> yesterday I asked:
>
[quoted text clipped - 31 lines]
>
> TIA