Last active
August 5, 2020 00:51
-
-
Save am9417/a10e11605b932723f153cdb83d91639f to your computer and use it in GitHub Desktop.
SourceTree post install script to create the start menu shortcut
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now working