2010-06-14 69 views
2

我想在Windows 7盒子(64位)上从vb.net代码创建桌面快捷方式。下面的代码适用于XP,但是在Win7上运行我刚刚得到一个消息,说明该应用程序已停止工作:在Windows 7盒子(64位)创建vb.net的快捷方式

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的框shorcut?

回答

2

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

+0

哦,而且我多年来都没有做过VB。感谢您的心理锻炼。 :) – 2010-06-14 15:08:12

+0

我只是试过,我仍然得到相同的结果不知道为什么... – Matt 2010-06-14 15:31:27

+0

其实我得到它的感谢! – Matt 2010-06-14 15:36:42

0

您的应用程序在什么特权下运行?我相信它将需要管理员凭据来执行您正在查找的内容。

+0

该帐户是管理员 – Matt 2010-06-14 12:55:13

+0

不是为运行高架相同。除非它是一项服务,否则将受UAC约束。如果它是一个安装程序,它可能会提升,如果它是一个普通的应用程序,它可能不是。 – 2010-06-14 13:10:17

+0

UAC已关闭,因此不应该成为问题 – Matt 2010-06-14 13:33:44