How can I tell if my program was run from other program (Shell command)?

I have a vb6 program that calls another program vb5.  I want the vb5 program to only execute if it was called from the first one.  How can I test if it was called from the first vb6 program?.  If another command is better than the Shell I will use it.
If the user tries to execute the vb5 program I do not want it to work, Thank You
GarySBAsked:
Who is Participating?
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
That is what the first link was for, though I'm not actually sure it's available in VB5.

Try this in the VB5 program:
    (Startup Procedure)
    MyVariable = Command
    MsgBox MyVariable ' <--- what do you get here?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Pass in a "secret" command line parameter when you launch VB5 from VB6.  If the command line parameter is not present then exit out...

See Command: http://msdn.microsoft.com/en-us/library/aa262696.aspx
0
 
GarySBAuthor Commented:
Can I also end the vb6 program somehow? or will that just happen?  One other question. How can I stop the vb6 from executing the line following the Shell command.  It keeps going forward so now two programs are running and i may need to wait for a result to decide if I want to keep going with the vb6 program, Thank You.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Mike TomlinsonMiddle School Assistant TeacherCommented:
"...and i may need to wait for a result to decide if I want to keep going with the vb6 program"

You need a "shell and wait" function.:
(there are LOTS of different ways to do this)
Option Explicit
 
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
 
Private Function ShellAndWait(ByVal fileName As String) As Long
    If Dir(fileName) <> "" Then
        Dim WShell As Object
        Dim oProcess As Object
        
        Set WShell = CreateObject("WScript.Shell")
        Set oProcess = WShell.Exec(fileName)
 
        Do While oProcess.Status = 0
            Sleep 50 ' keep CPU usage from ramping to 100%
            DoEvents ' keep app responsive
        Loop
 
        ShellAndWait = oProcess.ExitCode
 
        Set WShell = Nothing
        Set oProcess = Nothing
    Else
        MsgBox fileName, vbCritical, "File Not Found"
        ShellAndWait = 1 ' a non-zero value usually means something went wrong
    End If
End Function

Open in new window

0
 
GarySBAuthor Commented:
Looks very good.  Cannot try until tomorrow night. Will let you know, Thank You
0
 
GarySBAuthor Commented:
This is the last section that I need in order for my code to work.  Can you please correct my code.  I am unable to get the right syntax between the two programs.  I've increased the points to 500 and will issue them today for you,  I appreciate your help, Thank You

VB6 Program:
     (not sure if this is correct because I am unable to see the MyVariable value in the VB5Prog program)
     Shell (App.Path & "\" & "VB5Prog.exe cmd/MyVariable")

VB5 Program:
(not sure how MyVariable is received)
StartUp Procedure
     If MyVariable = "" then End ?
0
 
GarySBAuthor Commented:
Idle_Mind, Thank you so much.
It gives exactly what you put there.
If you place myprogram.exe cmd/MyVariable
it prints cmd/MyVariable  It does not print the contents of the variable.
You do not even seem to need cmd. If I place Gary after the .exe it prints Gary in the VB5 program.  Again this is just what I needed, Thank you for getting back to me on the weekend.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.