Worklet: Add Shortcut to Web Application Specifying Which Browser to Use

  • 15 October 2020
  • 0 replies
  • 53 views

Userlevel 5

This worklet as written adds a Chrome shortcut to the user’s desktop and start menu named “TSheets” which points to a web app. You can choose to only create the shortcut in one place or the other if you want. If you wish your app to be opened with a different browser, specify $BrowserPath to point to the installed browser you wish to use. The parameters in the remediation below describe how to set the variables.


Evaluation:


Exit 1

Remediation:


<#
.PARAMETER BrowserPath
Location of the Google Chrome browser executable. Google Chrome needs to already be installed for this script to work. If you wish for a different browser to execute the Web App, alter $BrowserPath
.PARAMETER ShortcutName
Display Name of the shortcut.
.PARAMETER ShortcutUrl
URL associated with the shortcut.
.PARAMETER ShortcutIconLocation
Optional: Path to an icon to associate with the shortcut.
.PARAMETER ShortcutOnDesktop
Set to $true if the Shortcut needs to be added to the assigned User Profile Desktop.
.PARAMETER ShortcutInStartMenu
Set to $true if the Shortcut needs to be added to the assigned User Start Menu.
#>

$BrowserPath = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
$ShortcutName = "TSheets"
$ShortcutUrl = "https://app.tsheets.com/signin"
$ShortcutIconLocation = ""
$ShortcutOnDesktop = $true
$ShortcutInStartMenu = $true

$WScriptShell = New-Object -ComObject WScript.Shell
$CurrentUser = (Get-WmiObject -class win32_process -ComputerName 'localhost' | Where-Object name -Match explorer).getowner().user

if ($ShortcutOnDesktop) {
$Shortcut = $WScriptShell.CreateShortcut("C:\Users\$CurrentUser\Desktop\$ShortcutName.lnk")
$Shortcut.TargetPath = $BrowserPath
$Shortcut.Arguments = $ShortcutUrl
if ($ShortcutIconLocation) {
$Shortcut.IconLocation = $ShortcutIconLocation
}
$Shortcut.Save()
}

if ($ShortCutInStartMenu) {
$Shortcut = $WScriptShell.CreateShortcut("C:\Users\$CurrentUser\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\$ShortcutName.lnk")
$Shortcut.TargetPath = $BrowserPath
$Shortcut.Arguments = $ShortcutUrl
if ($ShortcutIconLocation) {
$Shortcut.IconLocation = $ShortcutIconLocation
}
$Shortcut.Save()
}

0 replies

Be the first to reply!

Reply