在Windows 7中创建一个从vb.net快捷方式(64位) [英] Create shortcut from vb.net on Windows 7 box (64 bit)

查看:337
本文介绍了在Windows 7中创建一个从vb.net快捷方式(64位)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Windows 7中(64位)创建vb.net code桌面快捷方式。下面code适用于XP,但在运行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()

任何想法或更好的方法来对一个Win7中创建code进行shorcut?

Any thoughts or better ways to create a shorcut from code on a Win7 box?

推荐答案

Windows 7的在这里的64位。编译这是32位的,它的工作:

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

注:我正在用admin UAC关闭

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

另请注意,我改变WshShellClass到的WshShell

Also notice I changed WshShellClass to WshShell

这篇关于在Windows 7中创建一个从vb.net快捷方式(64位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆