Click here to Skip to main content
15,884,667 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I have two .exe files coded in VB6. The first called ServerFood and the second ClientFood. I want the ClientFood run only from Shell function of ServerFood and show error message when users click it directly. How to solve my problem?? Help please.
Posted
Comments
Sergey Alexandrovich Kryukov 10-Jul-11 13:54pm    
What are those? What's "run only from Shell function"? What's "Shell function"? What's "click it directly"? How to click indirectly?
--SA
derodevil 12-Jul-11 13:34pm    
ClientFood doesn't start if it's doubledclicked. And only starts when it's called from ServerFood using ShellExecute or Shell function (built in VB function)

1 solution

There are 2 ways I can think of, but I haven't tried them. The simple way is to start the program from the Shell with a commandline parameter, then check the parameter in your program. If the program was started by double clicking, the parameter should not be set.

The other way is to do some more low level stuff and try to get the process ID of your program, then get its parent. If it was started from the Shell, the parent should likely be cmd.exe, otherwise it should be explorer.exe.

Of course neither of those is foolproof, but perhaps one will work.
 
Share this answer
 
Comments
Dr.Walt Fair, PE 10-Jul-11 18:17pm    
Wow, a 1 vote with no reason. If it wasn't a good answer, someone could at least point the OP in the right direction.
derodevil 12-Jul-11 13:32pm    
can you give me the code?
Dr.Walt Fair, PE 12-Jul-11 13:48pm    
No, I'm not going to write your program for you, but what I would do unless there's an overriding reason not to, is in your Shell command call the program with a parameter, like "myprogram.exe myparameter". Then in "myprogram", examine the commandline parameters to see if "myparameter" was specified by examining the "Command" string in your code. The VB documentation should help you find information on the "Command" string.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900