Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving Unicode support and local icon storage #13

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified IntuneShortcut/CreateDesktopIcon.intunewin
Binary file not shown.
48 changes: 42 additions & 6 deletions IntuneShortcut/CreateDesktopIcon.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Param (

[Parameter(Mandatory=$false)]
[String]$IconFile=$null,

[Parameter(Mandatory=$false)]
[Switch]$IconFileIsIncluded=$false,

[Parameter(Mandatory=$false)]
[String]$ShortcutArguments=$null,
Expand All @@ -26,22 +29,32 @@ function Add-Shortcut {
[String]$ShortcutTargetPath,
[Parameter(Mandatory)]
[String] $DestinationPath,
[Parameter(Mandatory)]
[String]$DestinationName,
[Parameter()]
[String] $WorkingDirectory
[String] $WorkingDirectory,
[Parameter()]
[String] $IconFilePath
)

process{
# due to WScript supporting only ANSI had to pull a rename here
$tempDestinationPath = Join-Path -Path $DestinationPath -ChildPath "updatingshortcut.lnk"
$finalDestinationPath = Join-Path -Path $DestinationPath -ChildPath "$DestinationName.lnk"

$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($destinationPath)
$Shortcut = $WshShell.CreateShortcut($tempDestinationPath)
$Shortcut.TargetPath = $ShortcutTargetPath
$Shortcut.Arguments = $ShortcutArguments
$Shortcut.WorkingDirectory = $WorkingDirectory

if ($IconFile){
$Shortcut.IconLocation = $IconFile
$Shortcut.IconLocation = $IconFilePath
}
# Create the shortcut
$Shortcut.Save()
# rename shortcut - WScript can only handle ANSI. This allows unicode:
Move-Item -Path $tempDestinationPath -Destination $finalDestinationPath -Force
#cleanup
[Runtime.InteropServices.Marshal]::ReleaseComObject($WshShell) | Out-Null
}
Expand Down Expand Up @@ -82,12 +95,35 @@ function Get-StartDir {
}
}

function Copy-IconToLocalPC {
param (
[Parameter(Mandatory)]
[String]$IconFileName
)
process{
# create a directory to store the icon if it does not exist
if (-not (Test-Path "C:\ProgramData\AutoPilotConfig\")){
New-Item -Path "C:\ProgramData\AutoPilotConfig\" -ItemType Directory
}
# copy the icon file if it does not exist
if (-not (Test-Path "C:\ProgramData\AutoPilotConfig\$IconFileName")){
Copy-Item -Path "$IconFileName" -Destination "C:\ProgramData\AutoPilotConfig"
}
return "C:\ProgramData\AutoPilotConfig\$IconFileName"
}
}

#### Desktop Shortcut
$destinationPath= Join-Path -Path $(Get-DesktopDir) -ChildPath "$shortcutDisplayName.lnk"
Add-Shortcut -DestinationPath $destinationPath -ShortcutTargetPath $ShortcutTargetPath -WorkingDirectory $WorkingDirectory
# check if we need to copy the icon file locally
if($IconFileIsIncluded){
$IconFilePath = Copy-IconToLocalPC -IconFileName $IconFile
} else{
$IconFilePath = $IconFile
}
Add-Shortcut -DestinationPath $(Get-DesktopDir) -DestinationName $shortcutDisplayName -ShortcutTargetPath $ShortcutTargetPath -WorkingDirectory $WorkingDirectory -IconFilePath $IconFilePath

#### Start menu entry
if ($PinToStart.IsPresent -eq $true){
$destinationPath = Join-Path -Path $(Get-StartDir) -ChildPath "$shortcutDisplayName.lnk"
Add-Shortcut -DestinationPath $destinationPath -ShortcutTargetPath $ShortcutTargetPath -WorkingDirectory $WorkingDirectory
}
}
2 changes: 1 addition & 1 deletion IntuneShortcut/Detect-CreateDesktopIcon.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Replace with the name of your shortcut (without *.lnk)
# Replace with the name of your shortcut (without *.lnk)
$shortcutName="cmd"

if ($(whoami -user) -match "S-1-5-18"){
Expand Down