无法使用WshShell使用热键创建快捷键是特殊键

时间:2019-02-21 07:18:14

标签: c# desktop shortcut

我正在尝试将{Num *}分配给快捷方式,但显示错误 “值不在预期范围内

请帮助!

我的代码:

  public static string CreateDesktopShortcut(string appPath)
        {
            object shDesktop = (object)"Desktop";
            WshShell shell = new WshShell();
            string shortcutAddress = (string)shell.SpecialFolders.Item(ref shDesktop) + @"\notepad.lnk";

//delete before creating a new one
            if (System.IO.File.Exists(shortcutAddress))
                System.IO.File.Delete(shortcutAddress);


            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
            shortcut.Description = "New shortcut for a Notepad";
            shortcut.Hotkey = @"*";
            shortcut.TargetPath = appPath + @"\notepad.exe";
            shortcut.Save();
            return shortcutAddress;
        }

0 个答案:

没有答案