在 Windows 7 盒子(64 位)上从 vb.net 创建快捷方式
我正在尝试在 Windows 7 机器(64 位)上从 vb.net 代码创建桌面快捷方式。以下代码适用于 XP,但在 Win7 上运行时,我只是收到一条消息,指出该应用程序已停止工作:
Imports IWshRuntimeLibrary
Dim WshShell As WshShellClass = New WshShellClass
Dim MyShortcut As IWshRuntimeLibrary.IWshShortcut
' The shortcut will be created on the desktop
'Win 7
MyShortcut = CType(WshShell.CreateShortcut("C:\Users\Public\Desktop\iexplore.lnk"), IWshRuntimeLibrary.IWshShortcut)
'MyShortcut = CType(WshShell.CreateShortcut("C:\Documents and Settings\All Users\Desktop\iexplore.lnk"), IWshRuntimeLibrary.IWshShortcut)
MyShortcut.TargetPath = "C:\Program Files\Internet Explorer\iexplore.exe" 'Specify target app full path
MyShortcut.Description = "IE"
MyShortcut.Save()
有任何想法或更好的方法在 Win7 盒子上从代码创建快捷方式吗?
I am trying to create a desktop shortcut from vb.net code on a Windows 7 box (64 bit). The following code works on XP, but when run on Win7 I just get a message stating the App has stopped working:
Imports IWshRuntimeLibrary
Dim WshShell As WshShellClass = New WshShellClass
Dim MyShortcut As IWshRuntimeLibrary.IWshShortcut
' The shortcut will be created on the desktop
'Win 7
MyShortcut = CType(WshShell.CreateShortcut("C:\Users\Public\Desktop\iexplore.lnk"), IWshRuntimeLibrary.IWshShortcut)
'MyShortcut = CType(WshShell.CreateShortcut("C:\Documents and Settings\All Users\Desktop\iexplore.lnk"), IWshRuntimeLibrary.IWshShortcut)
MyShortcut.TargetPath = "C:\Program Files\Internet Explorer\iexplore.exe" 'Specify target app full path
MyShortcut.Description = "IE"
MyShortcut.Save()
Any thoughts or better ways to create a shorcut from code on a Win7 box?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里是 Windows 7 64 位。将其编译为 32 位并且它有效:
注意:我以管理员身份运行并关闭了 UAC。
另请注意,我将 WshShellClass 更改为 WshShell
Windows 7 64-bit here. Compiled this as 32-bit and it worked:
Note: I am running as admin with UAC turned off.
Also notice I changed WshShellClass to WshShell
您的应用程序在什么权限下运行?我相信它将需要管理员凭据才能执行您正在寻找的操作。
What privileges is your app running under? I believe it will need admin credentials to do what you are looking for.