c# - Create Shortcut on desktop that calls PowerShell cmdlet -


i' trying create shortcut on desktop c# code, that

  1. opens powershell,
  2. imports mymodule.dll,
  3. clears screen,
  4. 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

Popular posts from this blog

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

laravel - Undefined property: Illuminate\Pagination\LengthAwarePaginator::$id (View: F:\project\resources\views\admin\carousels\index.blade.php) -