2010-06-14 4 views
2

J'essaie de créer un raccourci sur le bureau à partir du code vb.net sur un boîtier Windows 7 (64 bits). Le code suivant fonctionne sur XP, mais lorsqu'il est exécuté sur Win7-je obtenir un message indiquant l'App a cessé de fonctionner:Créer un raccourci à partir de vb.net sur Windows 7 (64 bits)

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() 

Toute pensée ou de meilleures façons de créer un raccourci à partir du code sur une boîte Win7?

Répondre

2

Windows 7 64 bits ici. Compilé cela comme 32 bits et cela a fonctionné:

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 

Remarque: Je cours en tant qu'administrateur avec UAC désactivé.

Notez également que j'ai changé WshShellClass à WshShell

+0

Oh, et je n'ai pas fait VB depuis des années. Merci pour l'exercice mental. :) –

+0

J'ai juste essayé et je reçois toujours le même résultat pas sûr pourquoi ... – Matt

+0

En fait je l'ai eu merci !! – Matt

0

De quels privilèges votre application est-elle équipée? Je crois qu'il aura besoin d'informations d'identification pour faire ce que vous cherchez.

+0

Le compte est un administrateur – Matt

+0

qui n'est pas la même que celle en cours d'exécution élevée. À moins que ce soit un service, il est soumis à l'UAC. Si c'est un installateur, c'est probablement élevé, et si c'est une application ordinaire, ce n'est probablement pas le cas. –

+0

Le contrôle de compte d'utilisateur est désactivé, ce qui ne devrait pas poser problème – Matt

Questions connexes