Results 1 to 7 of 7

Thread: [RESOLVED] Pass Values from one app to another

  1. #1

    Thread Starter
    Member adamj12b's Avatar
    Join Date
    Jan 2005
    Location
    Charlton Mass
    Posts
    51

    Resolved [RESOLVED] Pass Values from one app to another

    I am in the process of creating a program that needs to pass some information to another program. The program that needs to receive the data is meant as an update program to the first. I send a new copy of the host program over the sockets connection, then I need to pass the file name and location to the update program. After this information is sent the host program will quit so that the update can overwrite the host with the new version. The the update program restarts the host and everything goes on like normal. I have everything all-ready in place, except for passing the file information. I could just save the information in a text file and read form this, but it seems messy and illogical. Any advice?

    -Adam

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Pass Values from one app to another

    Does your main application launch the update application? I would suggest you use command line paramters to send the data you want to send, over to the updater app when it is launched. The updater app would then read in those values from its commandline param collection, and know what files it needs to work with.

  3. #3

    Thread Starter
    Member adamj12b's Avatar
    Join Date
    Jan 2005
    Location
    Charlton Mass
    Posts
    51

    Re: Pass Values from one app to another

    Yes, actually. Both application are command like apps. The host program launches the update program. So command line parameters? Could you recommend any articles so I may learn about them? Thanks for the advice.

    -Adam

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Pass Values from one app to another

    What do you mean by "command like apps"? Does that mean they are console applications and not Windows Forms applications? Or something else?

    You can use Environment.CommandLine to get any command line params that were passed to the given application. It gives you one big string of all of them though. As an alternative, you can use My.Application.CommandLineArgs to get a pre-parsed array (parsed at spaces) of the commandline args.

    The way you PASS command line args is simply by specifying them after the exe name.

    For example, in Windows, you can go to start -> run, and type

    iexplore.exe www.vbforums.com

    and it will launch internet explorer, and navigate to www.vbforums.com

    That is an example of a command line parameter. Of course it is up to the program to read in these params and take appropriate action as to what should happen.

    To launch your update exe, it is easy to use the process class, and pass the command line args with that.

    There are probably plenty of articles on how to use it, and I would suggest reading over the actual MSDN doc on the ProcessStartInfo, the sample code gives a decent example.

    http://msdn.microsoft.com/en-us/libr...startinfo.aspx

  5. #5

    Thread Starter
    Member adamj12b's Avatar
    Join Date
    Jan 2005
    Location
    Charlton Mass
    Posts
    51

    Re: Pass Values from one app to another

    Sorry. They both are console apps. I got my OS mixed up. LOL. Thanks for your help. I will try the command like args thing.

    -Adam

  6. #6

    Thread Starter
    Member adamj12b's Avatar
    Join Date
    Jan 2005
    Location
    Charlton Mass
    Posts
    51

    Re: Pass Values from one app to another

    Ive tried these 2 different ways I tried to call the program with the arguments. I am have not been able to receive anything in the other program.

    VB.NET Code:
    1. System.Diagnostics.Process.Start("C:\Documents and Settings\Adam\My Documents\My Dropbox\Work\Robot Updater\Robot Updater\bin\Debug\Robot Updater.exe, "Test Test Test Test")
    2.         Process.Start("C:\Documents and Settings\Adam\My Documents\My Dropbox\Work\Robot Updater\Robot Updater\bin\Debug\Robot Updater.exe", "Test Test Test Test")

    VB.NET Code:
    1. Dim inputArgument As String = "/input="
    2.         Dim inputName As String = ""
    3.  
    4.         For Each s As String In My.Application.CommandLineArgs
    5.             If s.ToLower.StartsWith(inputArgument) Then
    6.                 inputName = s.Remove(0, inputArgument.Length)
    7.             End If
    8.         Next
    9.  
    10.         If inputName = "" Then
    11.             Console.WriteLine("No input name")
    12.         Else
    13.             Console.WriteLine("Input name: " & inputName)
    14.         End If

    I tried that code on the recieving side. It is stright from msdn. It always displays "No Input Name".

    I have also been looking and could not fins anything that would pass information between 2 programs.

    -Adam
    Last edited by adamj12b; Feb 5th, 2009 at 06:46 AM.

  7. #7

    Thread Starter
    Member adamj12b's Avatar
    Join Date
    Jan 2005
    Location
    Charlton Mass
    Posts
    51

    Re: Pass Values from one app to another

    I was able to get it to work with the following code:

    On the host side :

    VB.NET Code:
    1. Process.Start("C:\Documents and Settings\Adam\My Documents\My Dropbox\Work\Robot Updater\Robot Updater\bin\Debug\Robot Updater.exe", TextBox1.Text.ToString)

    Which just for testing, It takes the value of textbox1 and passes it to Robot Updater.exe as an argument when it launches.

    On the updater side:

    VB.NET Code:
    1. Dim strAllArgs(My.Application.CommandLineArgs.Count - 1) As String
    2.         Dim x As Integer = 0
    3.  
    4.         For Each arg As String In My.Application.CommandLineArgs
    5.             Try
    6.                 strAllArgs(x) = arg
    7.                 Console.WriteLine(strAllArgs(x))
    8.             Catch ex As Exception
    9.                 strAllArgs(x) = "Could not write argument."
    10.                 Console.WriteLine(ex.Message)
    11.             End Try
    12.             x += 1
    13.         Next
    14.  
    15.         If My.Application.CommandLineArgs.Count = 0 Then
    16.             Console.WriteLine("No Arguments")
    17.         End If

    That code receives all the arguments and puts them on separate lines. It is using a space as a delimiter right now, so each word ends on its own line.

    Thanks Kleinma for pointing me in the right direction.

    -Adam

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width