我试图通过 C# 代码在桌面上创建一个快捷方式,即
- 打开 PowerShell,
- 进口
myModule.dll
, - 清屏,
- 显示我所有的
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();