Zum 23.08.2023 ist die NWC Services GmbH zur CANCOM GmbH geworden. Besuchen Sie uns gerne auf www.cancom.de
Toggle Bar

BLOG

BLOGGING CONSULTANTS

NWC Services Blog

Blogs von Consultants der NWC Services GmbH

Pin Icon to Superbar mit Flex+

Wird Flex+ genutzt um die Windows Profile zu konfigurieren, soll einem User u.U. die eine oder andere Anwendung schon gleich in die Superbar (Taskbar) oder das Startmenü gelegt werden. Leider liefert Flex+ keinen vorgefertigten Befehl aus, aber mit einem kleinen Powershell Script lässt sich diese Anforderung schnell erledigen. Zu allererst muss überlegt werden, wie das Powershell Script auf jeden Zielclient verfügbar gemacht werden kann. Steht eine DSM Umgebung zur Vefügung, bietet es sich an, das Paket zur Verteilung des Flex+ Clients um das kopieren von definierten Scripts zu erweitern oder ein eigenes Paket für die Aufgabe zur Verfügung zu stellen.

Ich nutze auch gerne ein (Job-)Paket, dass bei jedem Start des installers den Inhalt des Verzeichnisses "%NiDir%\extern$\Flex\Scripts" in das Verzeichnis "%ProgramFilesDir%\Immidio\Flex Profiles\Scripts" kopiert. Dieses Vorgehen ist aber nur dann zu empfehlen, wenn sich die Menge der Daten in einem überschaubaren Rahmen bewegt. 

Die Basis für das Powershell-Script zum "anpinnen" der Icons wurde der folgenden Adresse entnommen:
http://blog.crayon.no/blogs/janegil/archive/2010/02/26/pin-and-unpin-applications-from-the-taskbar-and-start-menu-using-windows-powershell.aspx.

Nun muss das Powershell Script so modifiziert werden, dass mit Hilfe von Parametern von außen aufgerufen werden kann.

###########################################################################"
#
# NAME: PinIconToTaskbar.ps1
# AUTHOR: Jan Egil Ring, Crayon
# DATE : 06.08.2010
# COMMENT: Module with the ability to pin and unpin programs from the taskbar and the Start-menu in Windows 7 and Windows Server 2008 R2.
#
# This module are based on the Add-PinnedApplication script created by Ragnar Harper and Kristian Svantorp:
# http://blogs.technet.com/kristian/archive/2009/04/24/nytt-script-pin-to-taskbar.aspx
# http://blog.crayon.no/blogs/ragnar/archive/2009/04/17/pin-applications-to-windows-7-taskbar.aspx
#
# Johan Akerstrom`s blog: http://cosmoskey.blogspot.com
#
# For more information, see the following blog post:
# http://blog.crayon.no/blogs/janegil/archive/2010/02/26/pin-and-unpin-applications-from-the-taskbar-and-start-menu-using-windows-powershell.aspx
#
# VERSION HISTORY:
# 1.0 17.04.2009 - Initial release by Ragnar Harper and Kristian Svantorp
# 1.1 26.02.2010 - Update by Jan Egil Ring. Added the capability to unpin applications.
# 1.2 06.08.2010 - Update by Johan Akerstrom. Added full MUI support.
# 1.3 14.04.2014 - Integrated parameters to call script from exernal.
#
###########################################################################"

param (
[Parameter(Mandatory=$true)][string]$Action,
[Parameter(Mandatory=$true)][string]$FilePath
)

function Set-PinnedApplication
{
<#
.SYNOPSIS
This function are used to pin and unpin programs from the taskbar and Start-menu in Windows 7 and Windows Server 2008 R2
.DESCRIPTION
The function have to parameteres which are mandatory:
Action: PinToTaskbar, PinToStartMenu, UnPinFromTaskbar, UnPinFromStartMenu
FilePath: The path to the program to perform the action on
.EXAMPLE
Set-PinnedApplication -Action PinToTaskbar -FilePath "C:\WINDOWS\system32\notepad.exe"
.EXAMPLE
Set-PinnedApplication -Action UnPinFromTaskbar -FilePath "C:\WINDOWS\system32\notepad.exe"
.EXAMPLE
Set-PinnedApplication -Action PinToStartMenu -FilePath "C:\WINDOWS\system32\notepad.exe"
.EXAMPLE
Set-PinnedApplication -Action UnPinFromStartMenu -FilePath "C:\WINDOWS\system32\notepad.exe"
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)][string]$Action,
[Parameter(Mandatory=$true)][string]$FilePath
)
if(-not (test-path $FilePath)) {
throw "FilePath does not exist."
}

function InvokeVerb {
param([string]$FilePath,$verb)
$verb = $verb.Replace("&","")
$path= split-path $FilePath
$shell=new-object -com "Shell.Application"
$folder=$shell.Namespace($path)
$item = $folder.Parsename((split-path $FilePath -leaf))
$itemVerb = $item.Verbs() | ? {$_.Name.Replace("&","") -eq $verb}
if($itemVerb -eq $null){
throw "Verb $verb not found."
} else {
$itemVerb.DoIt()
}

}
function GetVerb {
param([int]$verbId)
try {
$t = [type]"CosmosKey.Util.MuiHelper"
} catch {
$def = [Text.StringBuilder]""
[void]$def.AppendLine('[DllImport("user32.dll")]')
[void]$def.AppendLine('public static extern int LoadString(IntPtr h,uint id, System.Text.StringBuilder sb,int maxBuffer);')
[void]$def.AppendLine('[DllImport("kernel32.dll")]')
[void]$def.AppendLine('public static extern IntPtr LoadLibrary(string s);')
add-type -MemberDefinition $def.ToString() -name MuiHelper -namespace CosmosKey.Util
}
if($global:CosmosKey_Utils_MuiHelper_Shell32 -eq $null){
$global:CosmosKey_Utils_MuiHelper_Shell32 = [CosmosKey.Util.MuiHelper]::LoadLibrary("shell32.dll")
}
$maxVerbLength=255
$verbBuilder = new-object Text.StringBuilder "",$maxVerbLength
[void][CosmosKey.Util.MuiHelper]::LoadString($CosmosKey_Utils_MuiHelper_Shell32,$verbId,$verbBuilder,$maxVerbLength)
return $verbBuilder.ToString()
}

$verbs = @{
"PintoStartMenu"=5381
"UnpinfromStartMenu"=5382
"PintoTaskbar"=5386
"UnpinfromTaskbar"=5387
}

if($verbs.$Action -eq $null){
Throw "Action $action not supported`nSupported actions are:`n`tPintoStartMenu`n`tUnpinfromStartMenu`n`tPintoTaskbar`n`tUnpinfromTaskbar"
}
InvokeVerb -FilePath $FilePath -Verb $(GetVerb -VerbId $verbs.$action)
}

Set-PinnedApplication -Action $Action -FilePath $FilePath

Steht das Script nun auf jedem Client zur Verfügung, wird pro Icon ein LogonTask in der Flex+ UE Management Console erstellt. Folgend ist ein LogonTask beschrieben, der Outlook an die Superbar "pinned":

Name: PintoTaskbar Outlook
Label: PintoTaskbar Outlook
Tag: Office
Command: %windir%\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -File "%ProgramFiles%\Immidio\Flex Profiles\Scripts\PinIconToTaskbar.ps1" -Action
PinToTaskbar -FilePath "%ProgramFiles(x86)%\Microsoft Office\Office15\outlook.exe"
Run task after profile archive import
Run once: false
Run async: true
Condition: FileOrFolderExists(%ProgramFiles%\Microsoft Office\Office15\outlook.exe) AND FileOrFolderExists(%ProgramFiles%\Immidio\Flex Profiles\Scripts\PinIconToTaskbar.ps1)

Durch die Conditions ist sichergestellt, dass der UEM task nur läuft wenn sowohl Outlook als auch das Script verfügbar ist, existiert das Icon schon, wird dies durch das Script selber festgestellt und kein zweites Icon erstellt. Natürlcih kann bei Bedarf auch die Option "Run once" auf "true" gestellt werden.

×
Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

Enterprise Deployment von Internet Explorer 11
Fehlermeldung "Die Antwort ist kein wohlgeformter ...

Ähnliche Beiträge

 

Kommentare

Derzeit gibt es keine Kommentare. Schreibe den ersten Kommentar!
Bereits registriert? Hier einloggen
Samstag, 27. April 2024

Sicherheitscode (Captcha)