Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法使用WshShell创建热键为特殊键的快捷方式_C#_Desktop_Shortcut - Fatal编程技术网

C# 无法使用WshShell创建热键为特殊键的快捷方式

C# 无法使用WshShell创建热键为特殊键的快捷方式,c#,desktop,shortcut,C#,Desktop,Shortcut,我试图将{Num*}分配给快捷方式,但显示错误 “值不在预期范围内” 请帮忙 我的代码: public static string CreateDesktopShortcut(string appPath) { object shDesktop = (object)"Desktop"; WshShell shell = new WshShell(); string shortcutAddress = (s

我试图将{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;
        }