Reputation: 2088
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?
Upvotes: 2
Views: 3068
Reputation: 3813
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
Upvotes: 2
Reputation: 2560
What privileges is your app running under? I believe it will need admin credentials to do what you are looking for.
Upvotes: 0