Solved

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

Posted on 2009-04-01
7
142 Views
Last Modified: 2012-05-06
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
0
Comment
Question by:GarySB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 24041781
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
 

Author Comment

by:GarySB
ID: 24041850
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 24043370
"...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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:GarySB
ID: 24046173
Looks very good.  Cannot try until tomorrow night. Will let you know, Thank You
0
 

Author Comment

by:GarySB
ID: 24071340
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
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 24071707
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
 

Author Closing Comment

by:GarySB
ID: 31565394
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
vb6 connector to SQL Server 2 42
Convert VB6 MSXML2.ServerXMLHTTP process to C# 2 79
IF ELSE Statement in Excel Macro VBA 16 98
Error with a code discussed on this page 5 48
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question