c# - 在 Windows 7 框(64 位)上从 vb.net 创建快捷方式

标签 c# .net vb.net windows-7 shortcut

我正在尝试从 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/

相关文章:

.net - 何时以及何时不安装到 GAC 中?

javascript - .net MVC 中的 AJAX 请求适用于 Chrome,不适用于 Firefox 或 IE

java - WCF 身份验证服务

c# - 将 VB 转换为 C#

vb.net - 将 XNA + VB.Net 游戏转换为 MonoGame

c# linq 生成的查询长度超过限制。有什么办法可以提高这个限制吗?

c# - WPF MVVM 带参数的数据绑定(bind)?

c# - 为什么 nuget 安装一堆系统命名空间引用?

c# - 异步 - 等待直到有人尝试连接

asp.net - 将 QueryString 转发到另一台服务器