c# - Create Shortcut on desktop that calls PowerShell cmdlet -
i' trying create shortcut on desktop c# code, that
- opens powershell,
- imports
mymodule.dll
, - clears screen,
- shows cmdlets of
mymodule.dll
.
after executing c#, shortcut appears on dektop, reason quotes set around whole shortcut.targetpath
. after removing quotes manually, fine.
how prevent these quotes set?
my code:
object shdesktop = (object)"desktop"; wshshell shell = new wshshell(); string shortcutaddress = (string)shell.specialfolders.item(ref shdesktop) + @"\´mymodule.lnk"; iwshshortcut shortcut = (iwshshortcut)shell.createshortcut(shortcutaddress); shortcut.description = "mymodule"; shortcut.targetpath = @"%windir%\\system32\\windowspowershell\\v1.0\\powershell.exe -noexit -command &{ import-module \\srv\ps\mymodule.dll;clear; get-command -module mymodule}"; shortcut.save();
as commented petseral, use arguments
property pass arguments executable:
shortcut.targetpath = @"%windir%\\system32\\windowspowershell\\v1.0\\powershell.exe"; shortcut.arguments = @"-noexit -command &{ import-module \\srv\ps\mymodule.dll;clear; get-command -module mymodule}";
Comments
Post a Comment