Batch Script for New Versions and Shortcuts

CPGDeveloper

Board Regular
I administer an MS Access DB with approximately 20 end users. Each user has a copy of the FE on their desktop. When I need to make changes, the Form_Load Event of the initial form identifies that a new version is available and runs a batch script to copy down the new version of the front end to the users' desktop (I found this batch script on this forum I believe). It works great.

I have a request to change the generic MS Access Logo of the Application that sits on the users' desktop. The only way I believe to do this (without altering the registry) is to simply have a shortcut on the users' desktop that points to their copy of the FE. I'm able to alter the batch script to put the application in a different folder, but am having issues creating the shortcut and using the specific image that I want. Any ideas of how I would go about doing that? Can I add to this current batch script -- or perhaps I need to create a separate one? Thanks in advance!

' sets the file name of the batch file to create
TestFile = CurrentProject.Path & "\UpdateDbFE.cmd"
' sets the restart file name
strRestart = """" & strKillFile & """"
' creates the batch file -- The 10 after the ping -n is the delay for it to copy needs to be this for large front ends
Open TestFile For Output As #1
Print #1 , "Echo Off"
Print #1 , "ECHO Deleting old file"
Print #1 , ""
Print #1 , "if exist """ & strBackUp & """ del """ & strBackUp & """"
Print #1 , ""
Print #1 , "ECHO Copying backup file"
Print #1 , "Echo Off"
Print #1 , "ping -n 14 127.0.0.1 > nul"
Print #1 , ""
Print #1 , ":Fileready1"
Print #1 , "Ren """ & strKillFile & """ """ & strTarget & """"
Print #1 , "ECHO Copying New file"
Print #1 , "Echo Off"
Print #1 , "Copy /Y """ & strReplFile & """ """ & strKillFile & """"
Print #1 , ""
Print #1 , ":checkfilecreation"
Print #1 , "REM Now that a .mov file has been added to the folder check to see if the file has "
Print #1 , "REM completed the conversion or copying to the folder before starting "
Print #1 , ""
Print #1 , "CLS"
Print #1 , ""
Print #1 , "for %%I in (""" & strKillFile & """) do ( (call ) >>%%I ) 2>nul && (cls && set b=%%I && @Echo !b! is completed and transfer is ready && GOTO :fileready"
Print #1 , ") || (cls && echo %%I is still being created"
Print #1 , ")"
Print #1 , ""
Print #1 , ":ContinueCheck"
Print #1 , "REM Go back to checkfilecreation module"
Print #1 , "GOTO :checkfilecreation"
Print #1 , ""
Print #1 , ""
Print #1 , "if exist """ & strBackUp & """ del """ & strBackUp & """"
Print #1 , ""
Print #1 , ":Fileready"
Print #1 , "Echo CLICK ANY KEY TO RESTART THE ACCESS PROGRAM"
Print #1 , "START /I " & """MSAccess.exe"" " & strRestart
Close #1
 

welshgasman

Well-known Member
The way I did it, was the create the shortcut with the correct info in it, and place it with the master DB copy.
Then copy that to the user's desktop.

I do not have access to the computer that did that at the moment, but if you google 'copy shortcut' that should get you started.?
I always placed the FE DBs into a commonly named folder on each user PC. The batch file also created the folder if the first time used.

I would probably do it in the same file. Increase the version of the FE, and then they will get the updated shortcut with the fancy icon. :)

HTH
 
Last edited:

CPGDeveloper

Board Regular
Thanks for the advice guys -- I ended up using that template and created a batch script that puts the application in a separate folder on their c drive and puts a shortcut on their desktop. I'm posting it here if it's useful to anyone:

Public Sub ShortCut()

Dim objWshShell As Object
Dim objWshShortcut As Object
Dim strProgLocn As String
Dim strDBLocn As String
Dim strDBPath As String
Dim strDesktop As String
Dim strIconLoc As String
Dim strIconLocSo As String
Dim g_strFilePath As String
Dim p_strFilePath As String

strIconLocSo = " " 'This would be where the location of your shortcut image would be
strIconLoc = " " 'This would be the folder on the end user's c drive where you want the image to live
g_strFilePath = CurrentProject.Path

If Right(g_strFilePath, 7) = "Desktop" Then 'If their current version is on the desktop, define new location of where application should live
p_strFilePath = " " 'Location where you want the end users application to live
If FolderExists(p_strFilePath) = False Then
MkDir p_strFilePath
End If
Else
p_strFilePath = g_strFilePath
End If

If FileExists(strIconLoc) = False Then
Dim fso As Object
Set fso = VBA.CreateObject("Scripting.FileSystemObject")
Call fso.CopyFile(strIconLocSo, strIconLoc)
Set fso = Nothing
End If

Set objWshShell = CreateObject("WScript.Shell")

strDesktop = objWshShell.SpecialFolders("Desktop")
strProgLocn = SysCmd(acSysCmdAccessDir) & "msaccess.exe"
If Right(g_strFilePath, 7) = "Desktop" Then
strDBLocn = " " 'Full Path & Name of Where You want application to live on users c drive
Else
strDBLocn = CurrentDb.Name
End If
strDBPath = Left$(strDBLocn, Len(strDBLocn) - Len(Dir$(strDBLocn)))

If FileExists(strDesktop & "\my app.lnk") Then 'my app.lnk is name of short cut -- of course call it whatever you want
GoTo EndThis
End If

Set objWshShortcut = objWshShell.CreateShortcut(strDesktop & "\my app.lnk")

With objWshShortcut
.TargetPath = strProgLocn
.Arguments = Chr$(34) & strDBLocn & Chr$(34)
.WorkingDirectory = strDBPath
.WindowStyle = 4
.IconLocation = strIconLoc
.Save
End With

EndThis:
Set objWshShortcut = Nothing
Set objWshShell = Nothing

End Sub
 
Last edited:

Some videos you may like

This Week's Hot Topics

  • Get External Data (long shot question!)
    This is likely a long shot but I am wondering if it is at all possible for Excel to somehow 'change' the contents of a URL that is being linked to...
  • Importing multiple excel files into one spreadsheet
    Hi, I'm trying to import multiple excel files (with the same format into a single spreadsheet) so that each day's file is listed underneath the...
  • Cell Formatting
    Good Morning, I need to format a few different cells in the following manners: A1 has to always add a colon (:) after whatever is typed in by a...
  • How to copy multiple rows using If
    Hi all, I'm very new to VBA and have written this simple code to copy certain cells if a certain cell within that row contains any data. I need...
  • Workbook_Change stopped working !
    I am working on an app to speed up & automate processing of Credit Cards statements. After data is input from a CSV file, it is presented to the...
  • VBA If statement
    Dear All, I have two dates, where I'd like a message box to pop, if the dates are between this criteria. [CODE] sDate1 = #10/1/2019#...
Top