First VBS script - any suggestions? (1 Viewer)

JMongi

Active member
Local time
Today, 10:23
Joined
Jan 6, 2021
Messages
802
@arnelgp - I didn't think about changing the splash screen from being browser based. That's a good idea.

I'm back to working on this script and have some questions about what some the code is doing but more about the necessity of some of it. Here is the first one....

Code:
Public Function MakeFEShortcut()
'Purpose : Creates/overwrites shortcut to launch front end.
Dim Shortcut, DesktopPath, StartupPath
Dim MSAccPath 'Possible Not needed JM 06-09-2021

On Error Resume Next

'Kill shortcut so icon will be default Access icon.
If fs.FileExists(cLOCPATH & "\" & cSCName & ".lnk") Then
    fs.DeleteFile cLOCPATH & "\" & cSCName & ".lnk", True
End If

'Create shortcut in same folder as FE.
Set Shortcut = WSHShell.CreateShortcut(cLOCPATH & "\" & cSCName & ".lnk")

'Access Path Code possibly not applicable due to Access Runtime JM 06-09-2021
'Get msaccess path
'MSAccPath = WSHShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\" _
'& "CurrentVersion\App Paths\MSACCESS.EXE\Path")

'If Err <> 0 Then
'    MsgBox "MS Access is not installed. Installation aborted."
'    Set Shortcut = Nothing
'    Err = 0
'    Exit Function
'End If

Shortcut.TargetPath = """" & MSAccPath & "\msaccess.exe" & """"        '??
Shortcut.arguments = """" & cLOCPATH & "\" & cFE & """"                '??

StartupPath = MSAccPath
If fs.FolderExists(StartupPath) Then
    Shortcut.WorkingDirectory = StartupPath
End If
Shortcut.Description = "Application"
'Commented out. Use default Access Icon for this shortcut.
'Shortcut.IconLocation = cLOCPATH & "\" & cICON
Shortcut.Save

Set Shortcut = Nothing
MakeFEShortcut = True

End Function

A couple of questions:
1. This seems to do a lot with the actual msaccess.exe executable. In our environment, everyone will be using the runtime, only I have an access license. So, I presume, in general, the access key check isn't necessary or will be different for checking the runtime installation.

2. This "MakeFEShortcut" function creates a shortcut within the msaccess folder, is there any reason this is necessary? For reference, another section of this scrip creates a desktop shortcut.

At this point it occurs to me that I was creating an application launcher script and the script referenced is an FE updater. I can certainly decide for myself what is needed for my particular DB deployment, but I'm curious as to what purpose these shortcuts serve and what purpose a separate FE updater (that appears to need to be run by the local user) would serve?

Here is the later desktop shortcut code for reference:
Code:
Public Function MakeDesktopShortcut(sName, target)
'Purpose : Create new desktop shortcut in case something has changed.

Dim Shortcut, DesktopPath, StartupPath

DesktopPath = WSHShell.SpecialFolders("Desktop")
Set Shortcut = WSHShell.CreateShortcut(DesktopPath & "\" & sName & ".lnk")
Shortcut.TargetPath = target
StartupPath = fs.GetParentFolderName(target)

If fs.FolderExists(StartupPath) Then
    Shortcut.WorkingDirectory = StartupPath
End If

Shortcut.IconLocation = cLOCPATH & "\" & cICON
Shortcut.Save

End Function
 

Isaac

Lifelong Learner
Local time
Today, 07:23
Joined
Mar 14, 2017
Messages
8,738
If the size of your FE is small, and Copy operations (of it) from network to local require fairly minimal time, then here is an approach I often enjoy:

  1. one VBScript, saved as a .vbs file on a network folder, which deletes the user's appdata\database folder, creates their appdata\database folder, copies the most current FE master file into their appdata\database folder, and Shells it open (you don't worry about specifying an exe to use...it just works)
  2. create a custom Shortcut (.lnk file) - create it manually and save it also in the same network folder - the shortcut should be to the vbs file referenced in #1. give it your icon and everything.
  3. second VBScript file, saved as .vbs file on network folder. All this does is COPY the Shortcut file (.lnk) from the network folder where it lives, to the user's desktop. this .vbs file is the Install link that you give new users. After 2 seconds it says "Shortcut installed to desktop"
  4. from then on they use their desktop shortcut, which really just runs #1 vbscript, every time.
Saves you from various things, like having to decide which Access exe to use, and from trying to 'create' shortcuts in code.
 
Last edited:

JMongi

Active member
Local time
Today, 10:23
Joined
Jan 6, 2021
Messages
802
@Isaac - That makes total sense to me, I just wanted to make sure I wasn't missing something useful that would bite me down the road.

So, explain to me a little bit about the appdata\database folder. Is that anything special or can I just generate a top level C:\DBNAME directory and drop everything in there? Since this will just be with the runtime installed (we use O365/exchange)? Also, why does everyone delete everything and recopy, is that to avoid the Windows dialog box prompt?
 

Isaac

Lifelong Learner
Local time
Today, 07:23
Joined
Mar 14, 2017
Messages
8,738
Is that anything special or can I just generate a top level C:\DBNAME directory and drop everything in there?
If your users actually have permissions to top level C:\, I have no particular objection. I've gotten into the habit of using AppData as something that seems to universally work pretty well on Windows 10, in all types of environments (restrictive/corporate, open/small business, etc).

Also, why does everyone delete everything and recopy, is that to avoid the Windows dialog box prompt?
Honestly, just because it was faster to code
Code:
delete entire local database folder
create entire local database folder
copy latest server version of db into it
Than it was
Code:
See if local db folder already exists, if not create it
If it exists, see if there is a db already in there, if so, delete it
Possibly double check if there is additional crap/leftovers in there, if so, delete them
Copy latest server version of db into it

...and I am lazy.

Of course it makes no speed difference, because 99.99999% of the time the script takes to run will solely be attributed to the Copy of the server FE over to the local folder, which has to take place either way.
 

Users who are viewing this thread

Top Bottom