' Windows Script Host - Create Shortcuts for Show Secretary
'

Dim SpecialFolder


SpecialFolder = "Desktop"
MakeShortcut(SpecialFolder)

SpecialFolder = "StartMenu"
MakeShortcut(SpecialFolder)

SpecialFolder = "AllUsersPrograms"
MakeShortcut(SpecialFolder)

SpecialFolder = "AllUsersStartMenu"
MakeShortcut(SpecialFolder)

WScript.Echo "shortcuts Created"


Function MakeShortcut(Location)

Dim WSHShell
Dim AccessPath
Dim AppName
Dim UserID
Dim WorkGrp
Dim AppShortcut, ShortcutPath

Set WSHShell = WScript.CreateObject("WScript.Shell")

' Get the Path to the desired version 

AccessPath = FindMSAccess("10")

AppName = "C:\Program Files\Show Secretary\xpShowSecretary5.mde "
UserID = " /User Secretary /PWD "
WorkGrp = "C:\Program Files\Show Secretary\ShowSecWrkGrp.MDW"


' Read desktop path using WshSpecialFolders object
ShortcutPath = WSHShell.SpecialFolders(location)

' Create a shortcut object 
Set AppShortcut = WSHShell.CreateShortcut(ShortcutPath & "\Show Secretary.lnk")

' Set shortcut object properties and save it
AppShortcut.TargetPath = WSHShell.ExpandEnvironmentStrings(AccessPath)
AppShortcut.Arguments = chr(34) & AppName  & chr(34) & Userid & " /WrkGrp " & chr(34) & WorkGrp & chr(34) & " /Runtime"

AppShortcut.WindowStyle = 4
AppShortcut.IconLocation = WSHShell.ExpandEnvironmentStrings("C:\Program Files\Show Secretary\ShowSec2.ico, 0")
AppShortcut.Save

End Function

Function FindMSAccess(Arg)
'Returns the presumed location of Microsoft Access....retail or runtime
'Arg is a integer greater than 7 indicating the version of Access to locate

Dim varKeyData
Dim wsh

On Error Resume Next

    Set wsh = CreateObject("Wscript.Shell")
    
    varKeyData = wsh.RegRead("HKCR\Access.Application." & Arg & "\Shell\Open\Command\")
    
    FindMSAccess = StripIt(varKeyData)
    'MsgBox "FindMSAccess Exit: " & Arg & " - " & FindMSAccess	
End Function

Function StripIt(Arg)
'Removes any command line parameters from a Run string

    If InStr(Arg, "/") > 0 Then
      StripIt = Trim(Left(Arg, InStr(Arg, "/") - 1))
    Else
      StripIt = Arg
    End If

    If Left(StripIt, 1) = Chr(34) Then
        StripIt = Mid(StripIt, 2)
    End If
    
    If Right(StripIt, 1) = Chr(34) Then
        StripIt = Left(StripIt, Len(StripIt) - 1)
    End If


End Function

