private void button4_Click(object sender, EventArgs e)
        {
            string desktopPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonDesktopDirectory);
            string luhExePath = @"D:\Program Files\TTPlayer\TTPlayer.exe";
            WshShell shell = new WshShell();
            IWshShortcut luhDesktopCut = (IWshShortcut)shell.CreateShortcut(string.Format("{0}/{1}.lnk", desktopPath, "HRM"));
            luhDesktopCut.TargetPath = luhExePath;
            luhDesktopCut.Description = "HRM系统";
            luhDesktopCut.WorkingDirectory = luhExePath;//程序所在文件夹,在快捷方式图标点击右键可以看到此属性           
            luhDesktopCut.Hotkey = "CTRL+SHIFT+H";//热键
            luhDesktopCut.WindowStyle = 1;
            FileInfo file = new FileInfo(string.Format("{0}/{1}.lnk", desktopPath, "HRM"));
            if (file.Exists) {
                file.Delete();
            }
            try {
                MessageBox.Show(file.FullName);
                luhDesktopCut.Save();
            }
            catch (Exception ew) {
                MessageBox.Show(ew.Message);
            }        }这是我的一个Button控件的点击事件,主要就是在桌面创建一个快捷方式,问题是:如果直接F5运行,可以创建,一切OK,但如果运行生成好的exe文件,就不能创建???Why? 应该是权限问题,怎么解决呢?

解决方案 »

  1.   

    MessageBox.Show(file.FullName);非调试模式执行了么
      

  2.   

    MessageBox.Show(file.FullName);两次都执行了
    luhDesktopCut.Save();这句可能是关键………………
      

  3.   

    IWshShortcut luhDesktopCut = (IWshShortcut)shell.CreateShortcut(string.Format("{0}//{1}.lnk", desktopPath, "HRM"));句中使用双斜杠看下。
     另外 luhDesktopCut.WorkingDirectory = luhExePath.substring(luhExePath.lastindexof(@"\")-1);其他没问题了