Create Shortcuts with PowerShell

%3CLINGO-SUB%20id%3D%22lingo-sub-276230%22%20slang%3D%22en-US%22%3ECreate%20Shortcuts%20with%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-276230%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%20bonjour%2C%20bom%20dia%2C%20guten%20Tag%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20i%20write%20more%20and%20more%20unit%20tests%20for%20my%20functions%20i%20use%2C%20there%20are%20a%20few%20things%20making%20me%20wonder%20as%20my%20unittests%20fail%20and%20i%20first%20did%20not%20now%20why.%3CBR%20%2F%3EAs%20a%20result%20i%20got%202%20questions%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CUL%3E%3CLI%3EIs%20it%20wanted%20that%20it%20is%20possible%20to%20create%20a%20Shortcut%20without%20a%20name%3F%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20182px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F57909i24654B8E1EAB219B%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22ShortcutWithoutName.PNG%22%20title%3D%22ShortcutWithoutName.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CUL%3E%3CLI%3EI%20am%20not%20able%20to%20set%20a%20hotkey%20at%20an%20url%20shortcut%20while%20it%20is%20possible%20via%20the%20GUI.%3CBR%20%2F%3EIs%20it%20kinda%20bug%20or%20wanted%3F%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3BIf%20the%20code%20is%20needed%20i%20could%20paste%20it.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20in%20advance.%3C%2FP%3E%3CP%3EMichael%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-276230%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-848310%22%20slang%3D%22en-US%22%3ERe%3A%20Create%20Shortcuts%20with%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-848310%22%20slang%3D%22en-US%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F231640%22%20target%3D%22_blank%22%3E%40Michael%20Habermann%3C%2FA%3E%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENot%20sure%20if%20I%20understood%20correctly%20what%20were%20you%20trying%20to%20ask%2C%20but%20if%20you're%20trying%20to%20ask%20how%20to%20make%20a%20shortcut%20without%20a%20written%20name%20but%20with%20an%20extension%20you%20can%20try%20to%20use%20this%2C%20I%20tried%20this%20code%20and%20it%20was%20working%20for%20me.%20This%20is%20the%20example%20of%20making%20the%20shortcut%20for%20notepad%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CEM%3E%3CSTRONG%3E%24TargetFile%20%3D%20%22%24env%3ASystemRoot%5CSystem32%5Cnotepad.exe%22%3C%2FSTRONG%3E%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E%3CSTRONG%3E%24FileName%20%3D%20%22%22%3C%2FSTRONG%3E%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E%3CSTRONG%3E%24ShortcutFile%20%3D%20%22C%3A%5CUsers%5Cmbocak1%5CDesktop%5C%24(%24FileName).lnk%22%3C%2FSTRONG%3E%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E%3CSTRONG%3E%24WScriptShell%20%3D%20New-Object%20-ComObject%20WScript.Shell%3C%2FSTRONG%3E%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E%3CSTRONG%3E%24Shortcut%20%3D%20%24WScriptShell.CreateShortcut(%24ShortcutFile)%3C%2FSTRONG%3E%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E%3CSTRONG%3E%24Shortcut.TargetPath%20%3D%20%24TargetFile%3C%2FSTRONG%3E%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E%3CSTRONG%3E%24Shortcut.Save()%3C%2FSTRONG%3E%3C%2FEM%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESorry%20if%20this%20is%20not%20what%20you%20were%20looking%20for%2C%20but%20if%20not%2C%20can%20you%20try%20explaining%20again%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20this%20will%20help!%3C%2FP%3E%3CP%3ECheers!%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Visitor

Hello, bonjour, bom dia, guten Tag,

 

As i write more and more unit tests for my functions i use, there are a few things making me wonder as my unittests fail and i first did not now why.
As a result i got 2 questions:

 

  • Is it wanted that it is possible to create a Shortcut without a name?

         ShortcutWithoutName.PNG

  • I am not able to set a hotkey at an url shortcut while it is possible via the GUI.
    Is it kinda bug or wanted?

 

 If the code is needed i could paste it.

 

Thanks in advance.

Michael

1 Reply

Hello @Michael Habermann,

 

Not sure if I understood correctly what were you trying to ask, but if you're trying to ask how to make a shortcut without a written name but with an extension you can try to use this, I tried this code and it was working for me. This is the example of making the shortcut for notepad:

 

$TargetFile = "$env:SystemRoot\System32\notepad.exe"
$FileName = ""
$ShortcutFile = "C:\Users\mbocak1\Desktop\$($FileName).lnk"
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
$Shortcut.TargetPath = $TargetFile
$Shortcut.Save()

 

Sorry if this is not what you were looking for, but if not, can you try explaining again?

 

Hope this will help!

Cheers!