Starting program with a command line parameter
-
I've googled, searched CodeProject, etc, and I hope I'm overlooking something, but here is what I want to do: I want to call a Windows Form application from another Windows Form application. The program being called, may be called from different form based applications and needs to know who is calling. I've found in testing, that with this code, I can accept a parameter:
Public Shared Sub Main() If Command$() = "/CR" Then strAppStartedFrom = "CR" 'Started from Check Recon Application Else strAppStartedFrom = "--" End If MsgBox(strAppStartedFrom & Command$()) frmFTP.ShowDialog() End Sub
I've published it, and from what I can find it puts the exe in this location? C:\Users\username\AppData\Local\Apps\2.0\0BTCBQ53.QL1\OMCV071R.O93\carr..tion_c302ad764aefaa28_0001.0001_bcaadc20b696e727\CarrollFlexFTP.exe /CR This path seems like it might change and not be consistent when installing it for different users. The above link works if it is executed with a /CR parameter, but I need a more stable way of doing this. In the past I've pointed shortcuts to the setup.exe file in the location we publish the application to, but if I run the app using the setup.exe /CR parameter, it doesn't work. Suggestions?Lost in the vast sea of .NET
-
I've googled, searched CodeProject, etc, and I hope I'm overlooking something, but here is what I want to do: I want to call a Windows Form application from another Windows Form application. The program being called, may be called from different form based applications and needs to know who is calling. I've found in testing, that with this code, I can accept a parameter:
Public Shared Sub Main() If Command$() = "/CR" Then strAppStartedFrom = "CR" 'Started from Check Recon Application Else strAppStartedFrom = "--" End If MsgBox(strAppStartedFrom & Command$()) frmFTP.ShowDialog() End Sub
I've published it, and from what I can find it puts the exe in this location? C:\Users\username\AppData\Local\Apps\2.0\0BTCBQ53.QL1\OMCV071R.O93\carr..tion_c302ad764aefaa28_0001.0001_bcaadc20b696e727\CarrollFlexFTP.exe /CR This path seems like it might change and not be consistent when installing it for different users. The above link works if it is executed with a /CR parameter, but I need a more stable way of doing this. In the past I've pointed shortcuts to the setup.exe file in the location we publish the application to, but if I run the app using the setup.exe /CR parameter, it doesn't work. Suggestions?Lost in the vast sea of .NET
It appears that you're using ClickOnce deployment. If you want a more stable path, then you can't use ClickOnce Deployment. You have no control over the path that the app is installed to.
KreativeKai wrote:
The above link works if it is executed with a /CR parameter, but I need a more stable way of doing this.
What do you mean by this? Your code is just looking for a command line switch. It shouldn't care about the path that the thing was launched from.
KreativeKai wrote:
In the past I've pointed shortcuts to the setup.exe file in the location we publish the application to, but if I run the app using the setup.exe /CR parameter, it doesn't work.
Why are you putting the /CR on the Setup.exe command line?? You didn't write Setup.exe and it won't pass on parameters, so what's the point here??
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
It appears that you're using ClickOnce deployment. If you want a more stable path, then you can't use ClickOnce Deployment. You have no control over the path that the app is installed to.
KreativeKai wrote:
The above link works if it is executed with a /CR parameter, but I need a more stable way of doing this.
What do you mean by this? Your code is just looking for a command line switch. It shouldn't care about the path that the thing was launched from.
KreativeKai wrote:
In the past I've pointed shortcuts to the setup.exe file in the location we publish the application to, but if I run the app using the setup.exe /CR parameter, it doesn't work.
Why are you putting the /CR on the Setup.exe command line?? You didn't write Setup.exe and it won't pass on parameters, so what's the point here??
A guide to posting questions on CodeProject[^]
Dave KreskowiakWe are using clickonce deployment and yes, I agree this limits control. Setup.exe is not passing the parms, and like you said it basically shouldn't. The only exe that I have found to read the parms passed is when I use the random address they create on the fly. Frustrating... The clickonce deployment gives you so many advantages but in turn takes the flexibility out of the process. Oh well, I've already started coding the first app to call the second app, and I'll have to write and read a file to pass the information between the two and also keep the clickonce setup intact. Thanks as always for your input...
Lost in the vast sea of .NET
-
We are using clickonce deployment and yes, I agree this limits control. Setup.exe is not passing the parms, and like you said it basically shouldn't. The only exe that I have found to read the parms passed is when I use the random address they create on the fly. Frustrating... The clickonce deployment gives you so many advantages but in turn takes the flexibility out of the process. Oh well, I've already started coding the first app to call the second app, and I'll have to write and read a file to pass the information between the two and also keep the clickonce setup intact. Thanks as always for your input...
Lost in the vast sea of .NET
KreativeKai wrote:
The only exe that I have found to read the parms passed is when I use the random address they create on the fly.
Why are you even concerned about the path ClickOnce uses at all?? Are you saying that you have two applications where one launches the second and passes command line args?? ClickOnce was not designed for that at all. It was designed for simpler, single applications only. I suggest you don't use it at all because your requirements have outgrown the capabilities of ClickOnce. If you package your applications using traditional MSI installers, your apps get installed under Program Files and you control the names of the folders used under that. BTW, Command$ is the old VB6 way of doing it. VB.NET uses something more standardized:
Public Sub Main(ByVal args() As String)
You get the command line arguments already parsed for you in an array of strings.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
KreativeKai wrote:
The only exe that I have found to read the parms passed is when I use the random address they create on the fly.
Why are you even concerned about the path ClickOnce uses at all?? Are you saying that you have two applications where one launches the second and passes command line args?? ClickOnce was not designed for that at all. It was designed for simpler, single applications only. I suggest you don't use it at all because your requirements have outgrown the capabilities of ClickOnce. If you package your applications using traditional MSI installers, your apps get installed under Program Files and you control the names of the folders used under that. BTW, Command$ is the old VB6 way of doing it. VB.NET uses something more standardized:
Public Sub Main(ByVal args() As String)
You get the command line arguments already parsed for you in an array of strings.
A guide to posting questions on CodeProject[^]
Dave KreskowiakThanks for the BTW about the VB6 code... I found it on google and didn't realize. I agree, my requirements have outgrown the capabilities of ClickOnce... You asked:
Why are you even concerned about the path ClickOnce uses at all??
Basically what I found was if I pass the /CR parm into the app using: 1) The long random ClickOnce path - It works 2) The shortcut ...appref-ms /CR - It doesn't work 3) Published path setup.exe /CR - It doesn't work, and you explained this earlier, which makes sense why it does not... 4) Published path appname.application /CR - It doesn't work, and is probably for the same reason that setup.exe doesn't work. All four ways start the program, but only #1 recognizes the parm? This is where my confusion is. I'm just confused as to if I get the command line code working, which way can I execute the application.... or maybe command line parameters are best used when the application is not click once, which is sort of what you mentioned in an earlier thread. Thanks for all your help so far, and hopefully this will clarify my confusion. :)Lost in the vast sea of .NET
-
Thanks for the BTW about the VB6 code... I found it on google and didn't realize. I agree, my requirements have outgrown the capabilities of ClickOnce... You asked:
Why are you even concerned about the path ClickOnce uses at all??
Basically what I found was if I pass the /CR parm into the app using: 1) The long random ClickOnce path - It works 2) The shortcut ...appref-ms /CR - It doesn't work 3) Published path setup.exe /CR - It doesn't work, and you explained this earlier, which makes sense why it does not... 4) Published path appname.application /CR - It doesn't work, and is probably for the same reason that setup.exe doesn't work. All four ways start the program, but only #1 recognizes the parm? This is where my confusion is. I'm just confused as to if I get the command line code working, which way can I execute the application.... or maybe command line parameters are best used when the application is not click once, which is sort of what you mentioned in an earlier thread. Thanks for all your help so far, and hopefully this will clarify my confusion. :)Lost in the vast sea of .NET
You have to learn why things work in Windows as well as how. 1) It works because you told Windows where to find the .exe you want to launch. 2) Shortcuts do not pass parameters to the command lines they launch. In order for you to just click Start -> Run and type your app name, hit Enter and it launches, you have to include the path to your .EXE file in the PATH environment variable. (This is something inherited from the old DOS days.) You can't do that from ClickOnce AFAIK. You have to do it using a traditional MSI installer. Good Luck!
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
You have to learn why things work in Windows as well as how. 1) It works because you told Windows where to find the .exe you want to launch. 2) Shortcuts do not pass parameters to the command lines they launch. In order for you to just click Start -> Run and type your app name, hit Enter and it launches, you have to include the path to your .EXE file in the PATH environment variable. (This is something inherited from the old DOS days.) You can't do that from ClickOnce AFAIK. You have to do it using a traditional MSI installer. Good Luck!
A guide to posting questions on CodeProject[^]
Dave KreskowiakI enjoyed the "old DOS days" and still have several DOS manuals on my bookshelf that come in handy once in a while. My problem is that my job responsibilities are 90% COBOL code and mainframe programming and only 10% of the time I can code in Visual Studio. When I do get a chance to work in VB, it sometimes becomes more trial and error. Thanks for your help and enjoy your weekend! :)
Lost in the vast sea of .NET
-
I've googled, searched CodeProject, etc, and I hope I'm overlooking something, but here is what I want to do: I want to call a Windows Form application from another Windows Form application. The program being called, may be called from different form based applications and needs to know who is calling. I've found in testing, that with this code, I can accept a parameter:
Public Shared Sub Main() If Command$() = "/CR" Then strAppStartedFrom = "CR" 'Started from Check Recon Application Else strAppStartedFrom = "--" End If MsgBox(strAppStartedFrom & Command$()) frmFTP.ShowDialog() End Sub
I've published it, and from what I can find it puts the exe in this location? C:\Users\username\AppData\Local\Apps\2.0\0BTCBQ53.QL1\OMCV071R.O93\carr..tion_c302ad764aefaa28_0001.0001_bcaadc20b696e727\CarrollFlexFTP.exe /CR This path seems like it might change and not be consistent when installing it for different users. The above link works if it is executed with a /CR parameter, but I need a more stable way of doing this. In the past I've pointed shortcuts to the setup.exe file in the location we publish the application to, but if I run the app using the setup.exe /CR parameter, it doesn't work. Suggestions?Lost in the vast sea of .NET
I am not sure if this helps you, but I did find a way to accept parameters when launching a clickonce application. I activated the app by creating a new process using the uri to to the *.application file appending my arguments in the query string. I am using VB10, I don't know if it will be the same for you if you are using something different. From My Project -> Publish (tab) -> Options (button) -> Manifests "Block application from being activated via a URL" should be UNchecked "Allow URL parameters to be passed to application" should be checked After you publish like that you can launch the other app by url including a query string (http://MyDomain.com/MyFolder/MyApp.application?MyParamValueA=1&MyParamValueB=2): When the application is launched this way the query string arguments will not appear with the regular command line arguments, but instead need to be pulled from .Net like this (make sure you add null checks):
System.AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData(0)
-
I've googled, searched CodeProject, etc, and I hope I'm overlooking something, but here is what I want to do: I want to call a Windows Form application from another Windows Form application. The program being called, may be called from different form based applications and needs to know who is calling. I've found in testing, that with this code, I can accept a parameter:
Public Shared Sub Main() If Command$() = "/CR" Then strAppStartedFrom = "CR" 'Started from Check Recon Application Else strAppStartedFrom = "--" End If MsgBox(strAppStartedFrom & Command$()) frmFTP.ShowDialog() End Sub
I've published it, and from what I can find it puts the exe in this location? C:\Users\username\AppData\Local\Apps\2.0\0BTCBQ53.QL1\OMCV071R.O93\carr..tion_c302ad764aefaa28_0001.0001_bcaadc20b696e727\CarrollFlexFTP.exe /CR This path seems like it might change and not be consistent when installing it for different users. The above link works if it is executed with a /CR parameter, but I need a more stable way of doing this. In the past I've pointed shortcuts to the setup.exe file in the location we publish the application to, but if I run the app using the setup.exe /CR parameter, it doesn't work. Suggestions?Lost in the vast sea of .NET
I have made a program that calls itself. I must pass the command line to it, but the program must know in with state it is. (first call or the second on) I think i found the ideal solution for this problem. The global atom database!
Private sub main()
Nta = FndAtom("AdminRunStatus")
If Nta = 0 Then
Nta = SetAtom("AdminRunStatus")
'set the status for the second run
'do something for the first run (shell to myself)
call shell (App.Path & "\" & App.EXEName & " " & Command)End If Exit Sub Else Call DelAtom(Nta) 'second program and the command line call shell(Second program & " " & Command) 'do something for the second run.
End sub
This my created wrapper for the atom database:
'---------------------------------------------------------------------------------------
' Module : AtomDataBase Wrapper
' Author : Pcuser80
' Date : 03-06-2012
' Purpose : Atom Wrapper
'---------------------------------------------------------------------------------------Option Explicit
Private Declare Function InitAtomTable Lib "kernel32" (ByVal nSize As Long) As Long
Private Declare Function AddAtom Lib "kernel32" Alias "AddAtomA" (ByVal lpString As String) As Integer
Private Declare Function DeleteAtom Lib "kernel32" (ByVal nAtom As Integer) As Integer
Private Declare Function FindAtom Lib "kernel32" Alias "FindAtomA" (ByVal lpString As String) As Integer
Private Declare Function GetAtomName Lib "kernel32" Alias "GetAtomNameA" (ByVal nAtom As Integer, ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Declare Function GlobalAddAtom Lib "kernel32" Alias "GlobalAddAtomA" (ByVal lpString As String) As Integer
Private Declare Function GlobalDeleteAtom Lib "kernel32" (ByVal nAtom As Integer) As Integer
Private Declare Function GlobalFindAtom Lib "kernel32" Alias "GlobalFindAtomA" (ByVal lpString As String) As Integer
Private Declare Function GlobalGetAtomName Lib "kernel32" Alias "GlobalGetAtomNameA" (ByVal nAtom As Integer, ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Function SetAtom(ByVal AtomStr As String) As Integer
SetAtom = GlobalAddAtom(AtomStr)
End Function
Public Function GetAtom(ByVal Atom As Integer) As String
Dim buFfer As String
Dim lRet As Long
buFfer = String(255, 0)
lRet = GlobalGetAtomName(Atom, buFfer, Len(buFfer))
If lRet > 0 Then
buFfer = Left$(buFfer, lRe