我正在尝试从 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 机器上从代码创建快捷方式有什么想法或更好的方法吗?
最佳答案
此处为 Windows 7 64 位。将其编译为 32 位并且有效:
Imports IWshRuntimeLibrary
Module Module1
Sub Main()
Dim WshShell As WshShell = New WshShell
Dim MyShortcut As IWshRuntimeLibrary.IWshShortcut
MyShortcut = CType(WshShell.CreateShortcut("C:\Users\Public\Desktop\Dah Browser.lnk"), IWshRuntimeLibrary.IWshShortcut)
MyShortcut.TargetPath = "C:\Program Files\Internet Explorer\iexplore.exe" 'Specify target app full path
MyShortcut.Description = "IE"
MyShortcut.Save()
End Sub
End Module
注意:我在关闭 UAC 的情况下以管理员身份运行。
另请注意,我将 WshShellClass 更改为 WshShell
关于c# - 在 Windows 7 框(64 位)上从 vb.net 创建快捷方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3037294/