在 Windows 7 盒子(64 位)上从 vb.net 创建快捷方式

发布于 2024-09-05 18:20:08 字数 857 浏览 4 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

信愁 2024-09-12 18:20:08

这里是 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

Windows 7 64-bit here. Compiled this as 32-bit and it worked:

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

Note: I am running as admin with UAC turned off.

Also notice I changed WshShellClass to WshShell

与风相奔跑 2024-09-12 18:20:08

您的应用程序在什么权限下运行?我相信它将需要管理员凭据才能执行您正在寻找的操作。

What privileges is your app running under? I believe it will need admin credentials to do what you are looking for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文