An exception occurred in the OnBeforeInstall event handler of <name> Access to the path <path> is d

A

Andrzej Lipski

Hello I am developing a Windows Ce 5.0 mobile application. I followed the
example shown at :

Creating Self-Updating Applications With the .NET Compact Framework
http://msdn2.microsoft.com/en-us/library/aa446487.aspx

I was able to build the Cab file installer and Setup for the application
just fine and I created the CustomInstaller in VB rather than C# in the
example.

However on running of the Setup.exe file I receive the error:

"An exception occurred in the OnBeforeInstall event handler of
<application name>InstallDLL.CustomInstaller. --> Access to the path
'C:\Windows\system32\TEMP\<application name>\InstallDLL.dll' is denied."

Here is the CustomInstaller class for reference

Imports System.ComponentModel
Imports System.Configuration.Install
Imports System.IO
Imports Microsoft.Win32
Public Class CustomInstaller

Private Const CEAPPMGR_PATH As String =
"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\CEAPPMGR.EXE"
Private Const ACTIVESYNC_INSTALL_PATH As String =
"SOFTWARE\Microsoft\Windows CE Services"
Private Const INSTALLED_DIR As String = "InstalledDir"
Private Const CEAPPMGR_EXE_FILE As String = "CEAPPMGR.EXE"
Private Const CEAPPMGR_INI_FILE As String = "<application name>.ini"
Private Const APP_SUBDIR As String = "\<application name>"
Private TEMP_PATH As String = Environment.SystemDirectory &
"\TEMP\<application name>"

Public Sub New()
MyBase.New()
AddHandler BeforeInstall, AddressOf
CustomInstaller_BeforeInstall
AddHandler AfterInstall, AddressOf
CustomInstaller_AfterInstall
AddHandler BeforeUninstall, AddressOf
CustomInstaller_BeforeUninstall
End Sub

Private Function GetAppInstallDirectory() As String
' Get the ActiveSync install directory
Dim keyActiveSync As RegistryKey =
Registry.LocalMachine.OpenSubKey(ACTIVESYNC_INSTALL_PATH)
If keyActiveSync Is Nothing Then
` Throw New Exception("ActiveSync is not installed.")
End If
' Build the target directory path under the ActiveSync
folder
Dim activeSyncPath As String =
CType(keyActiveSync.GetValue(INSTALLED_DIR), String)
Dim installPath As String = activeSyncPath & APP_SUBDIR
keyActiveSync.Close()
Return installPath
End Function

Private Sub CustomInstaller_BeforeInstall(ByVal sender As Object,
ByVal e As InstallEventArgs)
' Find the location where the application will be installed
Dim installPath As String = GetAppInstallDirectory()
' Create the target directory
Directory.CreateDirectory(installPath)
' Copy your application files to the directory
Dim installFile As String
For Each installFile In Directory.GetFiles(TEMP_PATH)
File.Copy(installFile, Path.Combine(installPath,
Path.GetFileName(installFile)), True)
Next
' Get the path to ceappmgr.exe
Dim keyAppMgr As RegistryKey =
Registry.LocalMachine.OpenSubKey(CEAPPMGR_PATH)
Dim appMgrPath As String =
CType(keyAppMgr.GetValue(Nothing), String)
keyAppMgr.Close()
' Run CeAppMgr.exe to install the files to the device
System.Diagnostics.Process.Start(appMgrPath, "\" &
"Path.Combine(installPath, CEAPPMGR_INI_FILE)" & "\")
End Sub

Private Sub CustomInstaller_AfterInstall(ByVal sender As Object,
ByVal e As InstallEventArgs)
'Delete the temp files
Dim tempFile As String
For Each tempFile In Directory.GetFiles(TEMP_PATH)
File.Delete(tempFile)
Next
End Sub

Private Sub CustomInstaller_BeforeUninstall(ByVal sender As Object,
ByVal e As InstallEventArgs)
' Find where the application is installed
Dim installPath As String = GetAppInstallDirectory()
' Delete the files
Dim appFile As String
For Each appFile In Directory.GetFiles(installPath)
File.Delete(appFile)
Next
' Delete the folder
Directory.Delete(installPath)
End Sub

End Class
 

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

Top