WinForm launching a console application
-
Pass a mystery parm to the console app that only the Windows Form knows about. No parm, no run.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food
You can easily get the command line parameter from Task Manager, so the passed value should be changed every time it needs to be launched. I was thinking the parameter could be randomized or something else, then verified over a named pipe, or other IPC, with the WinForms app.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
I have a C# console application that is launched from a WinForm application.
The output of the console application is well-formatted; however, user can run the console application directly. Is there a way to restrict/force the console application to be only run from the main application (WinForm)?Just to add to what the others have said, If it's never to be run by the user, why create a console app at all? Why not just run it as a separate thread within the existing WinForms process?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
-
Just to add to what the others have said, If it's never to be run by the user, why create a console app at all? Why not just run it as a separate thread within the existing WinForms process?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
-
May I suggest a possible answer? The shell actually performs some quite useful tasks. If you make extensive use of shell facilities, it may take quite a few code lines to duplicate the functionality in your WinForms code.
Attaching a Console to a WinForms application[^] :-D
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
-
You can easily get the command line parameter from Task Manager, so the passed value should be changed every time it needs to be launched. I was thinking the parameter could be randomized or something else, then verified over a named pipe, or other IPC, with the WinForms app.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave KreskowiakI was counting on the "user" being "typical" ... Task Manager? Wazzat? This looked like an "inhouse" solution ... Anybody trying to bypass this simple solution is obviously asking for trouble.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food
-
I was counting on the "user" being "typical" ... Task Manager? Wazzat? This looked like an "inhouse" solution ... Anybody trying to bypass this simple solution is obviously asking for trouble.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food
The thing about your "typcial" user is that some of them stumble across how to do things they shouldn't normally know how to do. NEVER assume users stay uninformed. Security is only secure in an environment that never changes or is touched from the outside, and that's never the case.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
The thing about your "typcial" user is that some of them stumble across how to do things they shouldn't normally know how to do. NEVER assume users stay uninformed. Security is only secure in an environment that never changes or is touched from the outside, and that's never the case.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave KreskowiakThere's a difference between "accidently" running a console app versus defeating a method intended to prevent "accidents". Yes, there is a chance someone will type: ConsoleApp.exe supercalifragilisticexpialidocious. There is also such a thing as overkill based on what the console app actually does.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food
-
There's a difference between "accidently" running a console app versus defeating a method intended to prevent "accidents". Yes, there is a chance someone will type: ConsoleApp.exe supercalifragilisticexpialidocious. There is also such a thing as overkill based on what the console app actually does.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food
Oh I get it, I've been here before. I speak from experience I cannot talk about.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
Oh I get it, I've been here before. I speak from experience I cannot talk about.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
I have a C# console application that is launched from a WinForm application.
The output of the console application is well-formatted; however, user can run the console application directly. Is there a way to restrict/force the console application to be only run from the main application (WinForm)?As OriginalGriff suggested, you should probably just run it as a thread in the process. But if you insist launching a console app, have your WinForms app create shared memory that your console app will look for when launched. If not found, terminate the console app.