【问题标题】:Create shortcut from vb.net on Windows 7 box (64 bit)在 Windows 7 框(64 位)上从 vb.net 创建快捷方式
【发布时间】:2011-03-03 12:16:47
【问题描述】:

我正在尝试在 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 机器上的代码创建快捷方式?

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

    • 哦,我已经好几年没做VB了。谢谢你的心理锻炼。 :)
    • 问题是如何在 64 位 Windows 上执行此操作。这不是 64 位解决方案。这是一个 32 位的解决方案。显示的代码无法在 64 位应用程序中编译。
    【解决方案2】:

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

    【讨论】:

    • 该帐户是管理员
    • 这与提升运行不同。除非它是一项服务,否则它受 UAC 约束。如果是安装程序,它可能会被提升,如果是普通应用程序,则可能不是。
    • UAC 已关闭,因此不应该成为问题
    • 那么当您以管理员身份运行时,您会看到相同的行为吗?
    • 是管理员帐户,UAC关闭,甚至右键单击应用程序并以管理员身份运行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-26
    • 1970-01-01
    • 2011-11-09
    • 2019-06-29
    • 2019-07-01
    • 1970-01-01
    • 2017-03-02
    相关资源
    最近更新 更多