0

現在、プログラムでショートカットを作成していますが、C# で同様の方法でグローバル ショートカットを作成できるかどうかを知りたいです。

以下は私のコードです:

WshShell shell = new WshShell();
string shortcutLocation = "pathToShortcut//Shortcut1.lnk"
IWshShortcut shortcut = shell.CreateShortcut(shortcutLocation);
shortcut.Arguments = "foo bar";
shortcut.Description = "Test Shortcut";
shortcut.TargetPath = "pathToShortcutExe";
shortcut.WorkingDirectory = "pathToWorkingDirectory"
shortcut.Save();

このコードは、ユーザーのショートカットを作成するのに最適ですが、システムでこれを行う方法があるかどうかを知りたいです。グローバルにインストールされたプログラムがすべてのユーザーにショートカットを配置するのを見たので、C# でこの効果を実現する方法に興味があります。

4

1 に答える 1

2

はい、できます..参照プロジェクトを追加する必要があります > 参照の追加 > COM > Windows スクリプト ホスト オブジェクト モデル。

    using IWshRuntimeLibrary;

    private void CreateShortcut()
    {
      object shDesktop = (object)"Desktop";
      WshShell shell = new WshShell();
      string shortcutAddress = (string)shell.SpecialFolders.Item(ref shDesktop) + @"\Notepad.lnk";
      IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
      shortcut.Description = "New shortcut for a Notepad";
      shortcut.Hotkey = "Ctrl+Shift+N";
      shortcut.TargetPath = Environment.GetFolderPath(Environment.SpecialFolders.System) + @"\notepad.exe";
      shortcut.Save();
    }
于 2015-07-27T20:28:37.690 に答える