Let me back up and give the situation. I have a simple clickonce application call AlphaWave that allows users to select from a couple of drop down lists, and enter some information into a text box and maybe add an image to provide feedback to me. Pretty simple stuff. What I wanted to do is to pre-populate one of the dropdowns based on the application that was calling the AlphaWave app so the user wouldn't have to. Again, pretty simple stuff. Or so I thought. Searching through the morass of blogs, MSDN articles, and other assorted goop, I found a couple of good articles that discuss it. The discussion was in-depth and complex. But I am lazy; I don't want to work that hard. So I bypassed all the passing parameter stuff in the usual way. What I did, is I create a text file with the parameters in it before calling AlphaWave through a Process.Start method in my Visual Studio 2010 VB application. In this particular case, the call was on a button click event. The WriteAllText line is what creates a text file and populates it with a string (the second parameter). In this particular case, the string "Sisyphus" indicating the application that is calling AlphaWave.
Const cAlphaApp As String = "C:\ProgramData\Microsoft\Windows\Start Menu\LCB Applications\AlphaWave.appref-ms"
'What we are writing is the parameter string to be read later. In this case, it's a single line
My.Computer.FileSystem.WriteAllText(cAlphaFile, "Sisyphus", True)
Try
In AlphaWave, I needed to set the startup object to be Sub Main and have that look for the text file with the parameters in it before displaying the form itself. If the parameter text file exists, I read its contents as the equivalent of a passed parameter, kill the file, then continue processing the AlphaWave form startup. If the text file doesn't exist, the code bypasses it all and I just don't have the parameters loaded into strParameters for launching AlphaWave. Simple and fast enough.
The additional code dealing with the cAppVersion is how I display the version number of the app. If it's deployed as a ClickOnce, it reads the data from the Deployment object. If it isn't, I am working in my own dev environment, and I display that.
Dim cAlphaCall as string = "C:\alphacall.txt"
Try
End Try
' Identify the version in the app
If Deployment.Application.ApplicationDeployment.IsNetworkDeployed Then
theForm.lblVersion.Text = cAppVersion
Application.Run(theForm)
The "Process.Start" method is not available in VBA, and the Shell command only works against .com, .bat or .exe files. A conundrum in that it appears there isn't a way to launch a clickOnce application from within a MS Office application. Why? A ClickOnce application is a completely different animal with an extension of appref.ms. Another search across the web pretty much resulted in nothing.
After thinking a bit, I cleverly (I think) came up with a clickOnce Application Launcher... application. It is a console app, taking as a passed argument the path to the clickOnce application I want to start. Since it can easily take in an argument, AND it can also launch appref.ms files, the problem was solved. Below is the ENTIRE contents of the clickLauncher application:
Sub Main()
Private Sub Main(ByVal args() As String)
If UBound(args) = 0 Then
" RetVal = ShellExecute(0, ""open"", chr(34) &
"Double clicking it without passing an argument of the clickonce app path will do nothing other than get you this message box.")
Exit Sub
End If
Try
Catch ex As Exception
"Please ensure it has been installed locally, and the shortcut properly located in the LCB Applications folder.", MsgBoxStyle.Information)
End Try
End Sub
End Module
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Sub VBACallToLaunchClickOnceApp()
Dim strAppPath as string
Dim RetValue as Long
strLauncherPath = ""'this is the path to the clickOnceLauncher Application
strAppPath = ""'this is the path to the appref.ms shortcut you want to start up
RetVal = ShellExecute(0, ""open"", chr(34) & strLauncherPath & chr(34), Chr(34) & strAppPath & Chr(34), """", 0)