0

我试图通过 C# 代码在桌面上创建一个快捷方式,即

  1. 打开 PowerShell,
  2. 进口myModule.dll
  3. 清屏,
  4. 显示我所有的myModule.dll.

执行 C# 后,快捷方式出现在 dektop 上,但由于某种原因,整个shortcut.TargetPath. 手动删除这些引号后,一切都很好。

如何防止设置这些引号?

我的代码:

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();
4

1 回答 1

2

正如PetSerAl 所评论的,使用该Arguments属性将参数传递给可执行文件:

shortcut.TargetPath = @"%Windir%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe";
shortcut.Arguments = @"-noexit -command &{ import-module \\srv\PS\MyModule.dll;clear; get-command -Module MyModule}";
于 2016-11-13T12:22:11.733 回答