Link to home
Start Free TrialLog in
Avatar of emi_sastra
emi_sastra

asked on

CALLING AN APPLICATION FROM WITHIN AN APPLICATION

Hi All,

I try to open an app from within an app.

Module mdlMain

    Public Sub Main(ByVal pArgs() As String)

        If pArgs.Length > 0 Then
            For intI As Int32 = 0 To pArgs.Length - 1
                pArgs(intI) = pArgs(intI).ToUpper

                Select Case intI
                    Case 0
                        ERV_Global.strLoginUserID = pArgs(intI)
                    Case 1
                        ERV_Global.strLoginUserName = pArgs(intI)
                End Select


            Next

        End If

        MsgBox(pArgs.Length) -----> return 0

        Application.Run(frmMain)
    End Sub

Caller :

  Dim p As New Process()

                p.EnableRaisingEvents = False
                p.StartInfo.UseShellExecute = False
                p.StartInfo.CreateNoWindow = True
                p.StartInfo.FileName = strApplicationName
                p.StartInfo.Arguments = ERV_Global.strLoginUserID & " " & ERV_Global.strLoginUserName.Trim
                p.Start()

What's wrong ?

Thank you.
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Are you sure you're actually passing valid arguments?

                p.StartInfo.Arguments = ERV_Global.strLoginUserID & " " & ERV_Global.strLoginUserName.Trim
               MessageBox.Show(p.StartInfo.Arguments, "Arguments")
                p.Start()
Avatar of emi_sastra
emi_sastra

ASKER

Hi  Idle_Mind,

- Are you sure you're actually passing valid arguments?
Yes, It is.

I have seen from a link said that below code make some problem for passing arguments,
I forget where is it and how to overcome this.

     p.StartInfo.UseShellExecute = False
                p.StartInfo.CreateNoWindow = True

First, I use this because I want to avoid cmd window still active after calling the batch file.

Thank you.
Not sure about that.

What are the values that ultimately end up in these?

    p.StartInfo.FileName = strApplicationName
    p.StartInfo.Arguments = ERV_Global.strLoginUserID & " " & ERV_Global.strLoginUserName.Trim
strApplicationName + "ERV_INVENTORY"
ERV_Global.strLoginUserID = "EMI"
ERV_Global.strLoginUserName.Trim = "ABCD123"

Thank you.
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Idle_Mind,

I am sorry,  my mistakes.

The  p.StartInfo.FileName  = batch file name., should be app name without ".exe".

Why I call the bacth file because it runs below code :

@ECHO OFF
CD D:\EMI NEW\COMPILED\MKE\
COPY D:\SERVER\ERV\ERV_INVENTORY.EXE>NULL
ERV_INVENTORY.EXE

What I suppose to do if without it ?

Thank you.
"should be app name without ".exe""

So you need?

    p.StartInfo.FileName = System.IO.Path.GetFileNameWithoutExtension(strApplicationName)
So you need?

    p.StartInfo.FileName = System.IO.Path.GetFileNameWithoutExtension(strApplicationName)

Yes, it works now. But I still need to copy exe file from server to caller computer that is done by the batch file.

Thank you.
Hi Idle_Mind,

Thank you very much for your help.