www.jlion.com

Monday, September 17, 2007

I've been working for the past couple of days to create a setup for an ASP.NET application. Microsoft's setup wizard has come a long ways since the days of VB.6 and I'm finding it's now quite flexible.

I've managed to create a setup application that creates an ASP.NET website with the appropriate permissions (via a helper app) and that copies in a SQL Express database. My helper app also restarts IIS and configures and starts a windows service.

Since I want this web app to act like a desktop application, I needed shortcuts on the desktop and in the programs group so that the user could start it up. The setup wizard can create shortcuts, but it turns out that there are two types: One for traditional applications, and a separate type for internet URLs.

These internet shortcuts are managed using a COM interface and most of what I found on the subject of COM interfaces refers to either C++ or C#. Here's a VB.NET translation. The "CreateShortcut" method creates an internet shortcut (with an extension of ".URL") in the specified location with a link to the specified URL.

Imports System
Imports System.Runtime.InteropServices

Public Class CreateInternetShortcut
<ComImport(), _
Guid("CABB0DA0-DA57-11CF-9974-0020AFD79762"), _
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
Private Interface IUniformResourceLocatorW
Sub SetURL( _
<MarshalAs(UnmanagedType.LPWStr)> ByVal _
pcszURL As String, _
ByVal dwInFlags As Int16)

Sub GetURL( _
<Out(), MarshalAs(UnmanagedType.LPWStr)> ByVal ppszURL As String)

Sub InvokeCommand( _
ByVal purlici As IntPtr)
End Interface


<ComImport(), Guid("FBF23B40-E3F0-101B-8488-00AA003E56F8")> _
Private Class InternetShortcut
Implements IUniformResourceLocatorW

Public Sub GetURL(ByVal ppszURL As String) Implements IUniformResourceLocatorW.GetURL

End Sub

Public Sub InvokeCommand(ByVal purlici As System.IntPtr) Implements IUniformResourceLocatorW.InvokeCommand

End Sub

Public Sub SetURL(ByVal pcszURL As String, ByVal dwInFlags As Short) Implements IUniformResourceLocatorW.SetURL

End Sub
End Class

Public Sub CreateShortcut( _
ByVal sFilePath As String, _
ByVal sURL As String)

Dim oIS As New InternetShortcut
Dim oPF As System.Runtime.InteropServices.ComTypes.IPersistFile = oIS

oIS.SetURL(sURL, 0)
oPF.Save(sFilePath & ".url", True)

Marshal.ReleaseComObject(oPF)
End Sub
End Class

0 Comments:

Post a Comment

<< Home