VS调试模式和直接运行exe的结果不同

「已注销」 2012-08-21 03:26:18
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? 应该是权限问题,怎么解决呢?
...全文
610 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Anod 2012-08-21
  • 打赏
  • 举报
回复
IWshShortcut luhDesktopCut = (IWshShortcut)shell.CreateShortcut(string.Format("{0}//{1}.lnk", desktopPath, "HRM"));句中使用双斜杠看下。
另外 luhDesktopCut.WorkingDirectory = luhExePath.substring(luhExePath.lastindexof(@"\")-1);

其他没问题了
「已注销」 2012-08-21
  • 打赏
  • 举报
回复
MessageBox.Show(file.FullName);两次都执行了
luhDesktopCut.Save();这句可能是关键………………
Anod 2012-08-21
  • 打赏
  • 举报
回复
MessageBox.Show(file.FullName);非调试模式执行了么

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧