473,385 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Get how my ConsoleApp is started

Hello I have an Console application wroten in C#. Now I like to know how (from where) the application has startet. I have already classes that can show windowsform and/or interact as an service.

So IF CheckStartMethod will work so that I know if I have start my App from windows, command prompt or as an service, everything will work.
Have anyone any idea how to get this information ? Please.
Lets say that i forse CheckStartMethode to return any string (cmd, win or service), everything work as well. But I can't figure how to know from where the application as been started....
Expand|Select|Wrap|Line Numbers
  1.  
  2. [STAThread]
  3. static int Main(string[] args)
  4. {
  5.    startmethod = CheckStartMethod();
  6.  
  7.    if (startmethod == "cmd")
  8.    {
  9.      Scan scan = new Scan();
  10.      scan.Run();
  11.    }
  12.  
  13.    if (startmethod == "win")
  14.    {
  15.      ShowWindowsForm();
  16.    }
  17.  
  18.    if (startmethod == "service")
  19.    {
  20.       ServiceBase[] ServicesToRun;
  21.       ServicesToRun = new ServiceBase[] { new MainService() };
  22.       ServiceBase.Run(ServicesToRun);
  23.    }
  24.  
  25.    return 0;
  26. }
Aug 13 '08 #1
4 880
Plater
7,872 Expert 4TB
Do you mean the working directory?
Directory.GetCurrentDirectory()
Aug 13 '08 #2
Curtis Rutland
3,256 Expert 2GB
I think that he wants to know how his app was started...by a service, through cmd.exe, or double clicking, am I right?

I think you might have to pass arguments to your program and get them from args[].
Aug 13 '08 #3
Plater
7,872 Expert 4TB
Ohhhh.
You might be able to find the "parent process id" of your program, which might be of some help?
Aug 13 '08 #4
I think that he wants to know how his app was started...by a service, through cmd.exe, or double clicking, am I right?

I think you might have to pass arguments to your program and get them from args[].
You right. But I will not use any arguments. I so, I only know which arguments I get, not how the program was started.

I have already get help. Thanks every one!
Aug 14 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Mark Fisher | last post by:
I have a Java desktop GUI application that the user can run multiple times. In order to keep one instance of the application distinct from another, I'd like to put the instance number of the...
13
by: Deepak Sarda | last post by:
Hello everyone. I have run into something which I believe is a bug or a shortcoming of the threading.Thread module. My program spawns 15 threads. For this I've creating a new class with...
80
by: Bibby | last post by:
Hi, I'm interested in getting started in the programming world. I've dabbled in C, C++ and VB6. Which would be the best language to focus my attention to regarding the following considerations: ...
0
by: Bob | last post by:
We have an ivr outcall application that starts calling customers at a certain time every day automatically at a predetermined time to advise those expected to receive delivery next day that their...
2
by: bz | last post by:
Hi, I need to detect at runtime if the application was started from VS 2005. Is it possible? Also, how can I know at runtime of app is built for Debug or Release? Thanks
4
by: Benjamin Hell | last post by:
Hi! I wonder whether there might be a way to find out how a Python program was started (in my case in Windows): By double clicking the file or by calling it on the "DOS" command line prompt. ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.