Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

# Exclude certificates from repository
*.pfx

# Exclude binary builds
/ClickOnce Installer/Launcher/bin/
/ClickOnce Installer/Launcher/obj/
125 changes: 125 additions & 0 deletions Application.vbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
'---------------------------------------------------------------------------------------
' Application : Script to launch Access Database (Installed via ClickOnce)
' Author : Adam Waller
' Date : 8/25/2017
'---------------------------------------------------------------------------------------

'=================================================
' ** SET THESE PARAMETERS **
'=================================================

Const strAppName = "Contacts CRM"
Const strAppFile = "Contacts CRM.accdb"

'=================================================


' Set application as trusted.
VerifyTrustedLocation strAppName

' Use Windows Shell to launch the application.
CreateObject("WScript.Shell").Run """msaccess.exe"" """ & ScriptPath & strAppFile & """ /cmd ""ojHYrvAwMudK8pezm7AR"""


'---------------------------------------------------------------------------------------
' Function : ScriptPath
' Author : Adam Waller
' Date : 2/8/2017
' Purpose : Get the path to the folder where this script is running.
'---------------------------------------------------------------------------------------
Function ScriptPath()

Dim oFSO
Dim oFile

Set oFSO = CreateObject("Scripting.FileSystemObject")
set oFile = oFSO.GetFile(Wscript.ScriptFullName)
ScriptPath = oFSO.GetParentFolderName(oFile) & "\"
Set oFSO = Nothing

End Function


'---------------------------------------------------------------------------------------
' Function : VerifyTrustedLocation
' Author : Adam Waller
' Date : 1/24/2017
' Purpose : Run this proceedure on startup to make sure the database is located
' : in a trusted location. (Adding an entry if needed.)
'---------------------------------------------------------------------------------------
'
Function VerifyTrustedLocation(strAppName)

Dim oShell
Dim oFSO
Dim oFile
Dim strVersion
Dim strPath
Dim strAppPath
Dim blnCreate
Dim strVal

Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")

' Get Access version
On Error Resume Next
strVal = oShell.RegRead("HKEY_CLASSES_ROOT\Access.Application\CurVer\")
If Err Then
Err.Clear
Else
' Parse the version number
strVal = Right(strVal, 2)
If IsNumeric(strVal) Then strVersion = strVal & ".0"
End If
On Error GoTo 0

' Make sure we actually found a version number
If Len(strVersion) <> 4 Then
MsgBox "Unable to determine Microsoft Access Version.", vbCritical
Exit Function
End If

' Get application name
'strAppName = Application.VBE.ActiveVBProject.Name

' Get registry path for trusted locations
strPath = "HKEY_CURRENT_USER\Software\Microsoft\Office\" & _
strVersion & "\Access\Security\Trusted Locations\" & strAppName & "\"

' Attempt to read the key
On Error Resume Next
strVal = oShell.RegRead(strPath & "Path")
If Err Then
Err.Clear
blnCreate = True
End If
On Error GoTo 0

' Get script location, to find application path
strAppPath = WScript.ScriptFullName
'strAppPath = CodeProject.Path & "\" & CodeProject.Name
Set oFile = oFSO.GetFile(strAppPath)
strAppPath = oFSO.GetParentFolderName(oFile)

If blnCreate = True Then
' Create values
oShell.RegWrite strPath & "Path", strAppPath
oShell.RegWrite strPath & "Date", Now()
oShell.RegWrite strPath & "Description", strAppName
oShell.RegWrite strPath & "AllowSubfolders", 1, "REG_DWORD"
Else
' Verify path location
strVal = oShell.RegRead(strPath & "Path")
If strVal <> strAppPath Then
' Update value
oShell.RegWrite strPath & "Path", strAppPath
oShell.RegWrite strPath & "Date", Now()
End If
End If

' Release references
Set oShell = Nothing
Set oFSO = Nothing

End Function
102 changes: 102 additions & 0 deletions ClickOnce Installer/Deploy.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
@echo off

:: use parameters: %0
:: %~1 Name (and folder)
:: %~2 Version
:: %~3 Icon file name (optional)

:: =====================
:: NOTES
::
:: --- Referenced Assemblies ---
:: For this to run correctly without errors, you may need to copy the applicable referenced
:: assemblies from the development machine, where Visual Studio was originally used to compile
:: the launcher application. They would typically be in the following location:
:: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework
:: See the following links for more details:
:: http://stackoverflow.com/questions/17220615/where-can-i-download-the-net-4-5-multitargeting-pack-for-my-build-server
:: http://stackoverflow.com/questions/10006012/how-to-get-rid-of-msbuild-warning-msb3644
::
:: --- Certificate Installation ---
:: The cert.pfx file does not need to be installed under the current user in order to sign the
:: installation, but the user will encounter a security warning if they attempt to install
:: the application without the certificate installed as a CA.
::
:: =====================

:setvars

:: Change to parent of script directory
pushd %~dp0..

:: Get path for msbuild to rebuild launcher application using new name.
for /D %%D in (%SYSTEMROOT%\Microsoft.NET\Framework\v4*) do set msbuild.exe=%%D\MSBuild.exe
::echo %msbuild.exe%

:: Replace periods with underscores for publish path (1.2.3.4 becomes 1_2_3_4)
set verpath=%~2
set verpath=%verpath:.=_%
::echo %verpath%

:: Use default icon if none specified
set appicon=%~3
if "%appicon%"=="" goto :copydefaulticon
set iconpath=..\..\%~1\%~2\
copy "%~1\%~2\%appicon%" _Tools\Launcher\
goto :startbuild

:copydefaulticon
copy /y _Tools\Launcher\app.ico "%~1\%~2\"
set appicon=iblp-db.ico

:startbuild

:: Build the launcher application using the application name and version
call %msbuild.exe% /target:publish _Tools\Launcher\Launcher.sln /property:configuration=RELEASE;ApplicationVersion=%~2;AssemblyName="%~1";ApplicationIcon="%appicon%" /target:Build;Clean

:: Check for errors
IF %errorlevel% NEQ 0 GOTO :error

:: Remove custom icon from launcher project
if "%appicon%" NEQ "app.ico" del _Tools\Launcher\%appicon%

:: Copy manifest files
copy /y "_Tools\Launcher\bin\Release\app.publish\Application Files\%~1_%verpath%\%~1.exe" "%~1\%~2\"
copy /y "_Tools\Launcher\bin\Release\app.publish\Application Files\%~1_%verpath%\%~1.exe.manifest" "%~1\%~2\"
copy /y "_Tools\Launcher\bin\Release\app.publish\Application Files\%~1_%verpath%\%~1.exe.config" "%~1\%~2\"
copy /y "_Tools\Launcher\bin\Release\app.publish\Application Files\%~1_%verpath%\app.ico" "%~1\%~2\"

:: Create deployment manifest from template, if it does not exist.
echo n | copy /-y _Tools\Template.application "%~1.application"

:: goto :done
:updatemanifests

:: Add any new files and update version
echo.
echo Processing files...
echo.

:: Add project files to application manifest
_Tools\mage -Update "%~1\%~2\%~1.exe.manifest" -FromDirectory "%~1\%~2" -IconFile "%appicon%"

:: Sign with stored cert
_Tools\mage -Sign "%~1\%~2\%~1.exe.manifest" -CertFile _Tools\cert.pfx

:: Update and sign deployment
_Tools\mage -Update "%~1.application" -AppManifest "%~1\%~2\%~1.exe.manifest" -Publisher IBLP -Name "%~1" -Version %~2 -MinVersion %~2 -ProviderURL "file://\\server\share\Apps\Deploy\%~1.application"
_Tools\mage -Sign "%~1.application" -CertFile _Tools\cert.pfx

echo.
echo Process Complete.
echo.
goto :done

:error

echo.
echo Houston, we have a problem.

:done

pause
Binary file not shown.
6 changes: 6 additions & 0 deletions ClickOnce Installer/Launcher/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
22 changes: 22 additions & 0 deletions ClickOnce Installer/Launcher/Launcher.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Launcher", "Launcher.vbproj", "{00E1C744-044B-4AD1-9ED1-86EAC9AC01EC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{00E1C744-044B-4AD1-9ED1-86EAC9AC01EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{00E1C744-044B-4AD1-9ED1-86EAC9AC01EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00E1C744-044B-4AD1-9ED1-86EAC9AC01EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00E1C744-044B-4AD1-9ED1-86EAC9AC01EC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Loading