on 01-20-2005 5:12 PM
Hi
Do I need additional software besides VS.NET 2003?
Is there a sample around?
TIA
Phil
Hi Philipp,
I adapted the installer sample (UI..\14....) to implement the "uninstaller" functionality.
Here's the code that installs some Add-on (ConCom1.exe). When you specify "Uninstall" as an additional commandline parameter for the (Un)Installer, the sample runs in "uninstall mode".
HTH,
Frank
Private strDll As String ' The path of "AddOnInstallAPI.dll"
Private strDest As String ' Installation target path
Private bFileCreated As Boolean ' True if the file was created
*******************************************************
' This function extracts a file into the path specified
Private Sub ExtractFile(ByVal path As String, ByVal filename As String)
Dim AddonExeFile As IO.FileStream
Dim thisExe As System.Reflection.Assembly
thisExe = System.Reflection.Assembly.GetExecutingAssembly()
Dim file As System.IO.Stream
file = thisExe.GetManifestResourceStream("AddOnInstaller." & filename)
' Create a tmp file first, after file is extracted change to exe
AddonExeFile = IO.File.Create(path & "\" & filename & ".tmp")
Dim buffer() As Byte
ReDim buffer(file.Length)
file.Read(buffer, 0, file.Length)
AddonExeFile.Write(buffer, 0, file.Length)
AddonExeFile.Close()
' Change file extension to exe
IO.File.Move(path & "\" & filename & ".tmp", path & "\" & filename)
' After renaming the file name the
End Sub
*******************************************************
' Install..............
Private Sub Install()
Environment.CurrentDirectory = strDll ' For Dll function calls will work
If Not (IO.Directory.Exists(strDest)) Then
IO.Directory.CreateDirectory(strDest) ' Create installation folder
End If
FileWatcher.Path = strDest
FileWatcher.EnableRaisingEvents = True
DeleteFile(strDest, "AddOnInstaller.exe") ' Remove existing (old) installer...
ExtractFile(strDest, "ConCom1.exe") ' Extract add-on to installation folder
ExtractFile(strDest, "ConCom.bmp") ' Extract add-on to installation folder
ExtractFile(strDest, "Interop.Messenger.dll") ' Extract add-on to installation folder
ExtractFile(strDest, "Interop.SAPbouiCOM.dll") ' Extract add-on to installation folder
ExtractFile(strDest, "Interop.SHDocVw.dll") ' Extract add-on to installation folder
While bFileCreated = False
Application.DoEvents()
'Don't continue running until the file is copied...
End While
EndInstall() ' Inform SBO the installation ended
MessageBox.Show("Finished Installing", "Installation ended", MessageBoxButtons.OK, MessageBoxIcon.Information)
Windows.Forms.Application.Exit() ' Exit the installer
End Sub
*******************************************************
' This function deletes a file from the path specified
Private Sub DeleteFile(ByVal path As String, ByVal filename As String)
Dim file As System.IO.Stream
Try
IO.File.Delete(path & "\" & filename)
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
*******************************************************
' Delete existing files...
Private Sub UnInstall()
DeleteFile(strDest, "ConCom1.exe")
DeleteFile(strDest, "ConCom.bmp")
DeleteFile(strDest, "Interop.Messenger.dll")
DeleteFile(strDest, "Interop.SAPbouiCOM.dll")
DeleteFile(strDest, "Interop.SHDocVw.dll")
MessageBox.Show(Nothing, "Finished UnInstalling", "Deinstallation ended")
Windows.Forms.Application.Exit() ' Exit the installer
End Sub
*******************************************************
' the installer is a application that has a window... => ...Load gets called when it starts
Private Sub frmInstall_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' The command line parameters, separated by '|' will be broken to this array
Dim strCmdLineElements(2) As String
Dim strCmdLine As String ' The whole command line
Dim NumOfParams As Integer 'The number of parameters in the command line (should be 2)
Dim strInstOrUninst As String
NumOfParams = Environment.GetCommandLineArgs.Length
Try
strCmdLine = Environment.GetCommandLineArgs.GetValue(1)
strCmdLineElements = strCmdLine.Split("|")
strInstOrUninst = strCmdLineElements.GetValue(0)
If strInstOrUninst = "Uninstall" Then
strDest = Application.StartupPath
UnInstall()
Else
If NumOfParams = 2 Then
' Get Install destination Folder
strDest = strCmdLineElements.GetValue(0)
' Get the "AddOnInstallAPI.dll" path
strDll = strCmdLineElements.GetValue(1)
strDll = strDll.Remove((strDll.Length - 19), 19) ' Only the path is needed
Install()
Else
MessageBox.Show("This installer must be run from Sap Business One", _
"Incorrect installation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
Windows.Forms.Application.Exit()
End Sub
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok
Now everything works. I found a hint in another thread. I use the terminateserver - event now for exiting the addon.
With the runonce entry + .bat-file everything now gets uninstalled.
Thanks Frank
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Frank
It gets clearer now
I have some troubles with the aet_ShutDown - Event. It only get called when in debugging mode. Thats the reason why the thread keeps running after closing SBO...
any suggestions?
TIA
Phil
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Frank
Thanks for the snippet. But I cant't delete my main file (.exe) because it's still running??? (it shows up in the task bar).
And the installer file (it's in the same path as the other files) itself can't be deleted as well i think (i didn't get this far)
And i don't get a "Uninstall" Argument from the commandline. Have I to declare it with the Ard - tool?
TIA
Phil
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Philipp,
The uninstall process is started when you log on to a database of the SAP Business One "environment" the next time. The Add-On exe won't run at this time...
Right, currently you cannot delete the (un-)installer file from inside the (un-)installer! I cannot promise anything to you, but I hope we will get rid of this shortcoming. In the meantime you could help yourself the classical Windows way: Add some program or batch to Windows registry's "RunOnce" section - so that your Add-On will be 100% uninstalled at least after the next reboot.
AddOnRegDataGen.exe has an edittext field where the "Unistall" Argument has to be put into.
HTH,
Frank
User | Count |
---|---|
107 | |
12 | |
11 | |
6 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.