Creating Shortcuts via Powershell with ZCM

Creating Shortcuts via Powershell with ZCM

ZCM contains a very limited interface for creating windows shortcut files.

Furthermore, uploading pre-created LNK files can be difficult.

See - https://support.microfocus.com/kb/doc.php?id=3093343

Using a Powershell script to create LNK files avoids the issues of trying to upload a pre-created LNK file as well as removes the limitations imposed by the GUI for creating shortcuts.

Since writing a Powershell script from scratch can be tricky, I've create a sample script and sample bundle that will allow for the easy creation of any shortcut with a wide array of customizable settings.

The script contains 2 section.

The top section has an array of variables that need to be set to match the requirements of the shortcut.  This is the only section of the script that should need to be updated.

The bottom section peforms the actual work and should not need to be modified.

A fully functional bundle has been attached that can be imported into the ZCC.

A copy of the script is pasted below....

#########################################
# Update the Variables Below as Desired #
#########################################

$LNKFile="c:\temp\Readme.lnk" #Name and Path of LNK to Create/Edit
$LNKExe="c:\windows\notepad.exe" #Name of Executable/Script to Run in Shortcut
$LNKParm="c:\windows\readme.txt" #Command line Parameter to Pass to Executable
$LNKWorkDir="c:\windows" #Working Directory if Desired
$LNKIcon="$LNKExe,0" #Setting Icon Example
#$LNKIcon="C:\windows\system32\shell32.dll,99" #Setting Icon Example 2
$LNKDescription="A Sample Description" #LNK Description Field.
$LNKWinStart=1 #Window Start Size 1=Norm, 3=Maximized, 7=Minimized
#$LNKHotKey="CTRL+SHIFT+F" # Enter HotKey Value and Uncomment Next Line if Desired.
$LNKRunAsAdmin=0 # Set LNKRunAsAdmin to 1 to enable "Run As Administrator CheckBox"

 

#######################################
### Main Code Only Edit Lines Above ###
#######################################

$Shell = New-Object -ComObject ("WScript.Shell")
$ShortCut = $Shell.CreateShortcut("$LNKFile")
$ShortCut.TargetPath="$LNKExe"
$ShortCut.Arguments="$LNKParm"
$ShortCut.WorkingDirectory = "$LNKWorkDir";
$ShortCut.WindowStyle = $LNKwinStart;
$ShortCut.Hotkey = $LNKHotKey
$ShortCut.IconLocation = "$LNKIcon";
$ShortCut.Description = $LNKDescription;
$ShortCut.Save()

### Lines below are to set shortcut to "Run As Administrator"
### May never be used but here is the code just in case…

If ($LNKRunAsAdmin -ne 1)
{
exit
}
else
{$bytes = [System.IO.File]::ReadAllBytes("$LNKFile")
$bytes[0x15] = $bytes[0x15] -bor 0x20 #set byte 21 (0x15) bit 6 (0x20) ON
[System.IO.File]::WriteAllBytes("$LNKFile", $bytes)
}

Labels (1)
Attachments

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Comments

Thank you very much for this!!!

Top Contributors
Version history
Revision #:
3 of 3
Last update:
‎2019-02-12 23:11
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.