Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SourceTree post install script to create the start menu shortcut
<#
Atlassian SourceTree installer does not create any shortcuts.
EXE is located somewhere, and it's not easily accessible.
Testing PowerShell scripts to create a shortcut under Start Menu / Programs...
Copyright 2020 Antti Konsta Kustaa
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#>
# Gets the path of AppData\Local folder, e.g. C:\Users\MyUser\AppData\Local
$LocalAppData = (Get-ChildItem Env:LOCALAPPDATA).Value
# The SourceTree should be installed here...
$Target = $LocalAppData + "\SourceTree\SourceTree.exe"
# Path to e.g. C:\Users\MyUser\AppData\Roaming, that contains the Program menu folder
$Roaming = (Get-ChildItem Env:APPDATA).Value
$Programs = $Roaming + "\Microsoft\Windows\Start Menu\Programs"
$Folder = $Programs + "\Atlassian"
# Check that Atlassian subdirectory folder is in Programs menu, otherwise create it
# If the directory doesn't exist, creating the shortcut will fail
if (!(Test-Path -Path $Folder)) {
New-Item -ItemType Directory -Path $Folder
}
$Shortcut = $Folder + "\SourceTree.lnk"
# The magic happens here...
$Ws = New-Object -ComObject WScript.Shell
$S = $Ws.CreateShortcut($Shortcut)
$S.TargetPath = $Target
$S.Save()
@DimoNline

This comment has been minimized.

Copy link

@DimoNline DimoNline commented Aug 5, 2020

Now working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.