Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I have 2 windows applications developed in C# one can be termed as master and other as child.

Now, I want to restrict user to launch the child application from exe directly and it should only be launched from the master application by giving the path of exe of the child application.

Please help me to achieve this.

Thanks
Posted
Updated 8-Feb-12 5:56am
v3
Comments
Sergey Alexandrovich Kryukov 8-Feb-12 11:53am    
Bad idea in general. Better integrate them in one process, without child processes. Don't torture yourself.
--SA
NeptuneHACK! 9-Feb-12 0:20am    
agree

Use Command-Line Arguments[^]. Based on the arguments you decide to start the other application.
 
Share this answer
 
Comments
Espen Harlinn 8-Feb-12 14:31pm    
5'ed!
Use Command-Line Arguments
C#
[STAThread]
       static void Main(string[] args)
       {
if(args=="meet your requirement")
{
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new frmMain());
}
}
 
Share this answer
 
But as per .NET frame work guide lines the child application is to be created as a class library.
It is always better to follow the standard conventions.
 
Share this answer
 
in the Program.cs file,give the master application's reference as
this seems similar to the following code:

C#
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MasterApp());


and in master application you can open other child application on any event

for example

C#
private void btnOpen_click()
{
chileApp c=new chileApp();
this.hide();
c.show();
}


good luck...
 
Share this answer
 
Looks like you are looking for this work flow:
For the child exe, when the exe is launched, check for the presence of a GUID as its argument in the Main(...) method, if not found, just shut down the application. This will make sure that the child app is only launched by a process which knows the GUID. That effectively rules out direct launch (e.g., by double clicking).

Now from the master app launch the child app by providing the GUID as an argument. You can use Process class to do it.

Hope that helps.
 
Share this answer
 
Comments
[no name] 8-Feb-12 12:05pm    
what is GUID...???
rawwool (Rahul Kumar) 9-Feb-12 4:45am    
GUID = Globally Unique Identifier (System.Guid class in mscorlib.dll assembly)
Example string id = Guid.NewGuid().ToString();
Your language here is unclear:

You are using the word "application" to describe your two "whatevers:" to me that implies two compiled .exe files.

SAK, and others, interpret your question as meaning the second application is a "child process" of the first, where "child process" has a specific technical meaning.

I would interpret your statement as meaning that the user launches the first, primary, or main, application, and then the user, when they choose to, launches the second application:

The statement : "givingen the path of exe of the child application:" implies to me you need to launch the second application from within the first, and does not imply automatic launch when the first, primary application launches.

You can clarify this question by telling us exactly what the two applications are (both WinForms ?), and if they have any need to communicate (pass objects, or data, between them), or "interact" with each other.

And, clarify when, and how, exactly, the second application is launched.

Hint: to launch a process from within a .NET application consider the Process.Start facility:

Process.Start(SomeProgramFilePath);

This should open your second application, and give it focus: but note, if your first application has its Form 'TopMost property set to 'true; the second application may not appear in front of it.
 
Share this answer
 

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