Solved

Program Launching Options

Posted on 2004-09-26
5
220 Views
Last Modified: 2010-04-15
Let's say I have a Windows Application called "Test".  Upon launching test.exe, the user can run the program in "restricted" mode.  I also want to be able to run it in "admin" mode.  Is there a way I can set this up to where "test.exe" will open the program in "restricted" and "test.exe -a" will open it in "admin" mode?  

As I re-read that...  I really hope it makes sense...  cause I think I'm confusing myself! :)

Thanks,
Tony
0
Comment
Question by:fattumsdad
5 Comments
 
LVL 15

Accepted Solution

by:
Timbo87 earned 500 total points
ID: 12157606
Yes, you can do that by looking at the args array in the Main method.

static void Main(string[] args)
{
     if(args.Length > 0)
     {
          // there is at least one argument, check if the first argument is '-a'
          if(args[0].ToLower() == "-a")
               // run in admin mode
     }
     else
     {
          // run in restrictive mode
          // since restrictive mode has no args, args.Length == 0.
     }
}
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12160165
If its a windows application, Why dont you make two separate main forms .. One for admin mode and the other for Application mode..
On the first /login screen ask the user in a combobox, which mode he needs to enter and then on that bases open the required forms/application
0
 
LVL 15

Expert Comment

by:SRigney
ID: 12160210
both methods work.  

You could use the command line and make two shortcuts where the Admin shortcut passes in -a to make it work as well.
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 12160423
In the following code:

static void Main(string[] args)
{
     if(args.Length > 0)
     {
          if(args[0].ToLower() == "-a")
          {
               Application.Run(new Form1());
          }
          else
          {
              Application.Run(new Form2());
          }
               
     }
}

I get no errors on Build.  When I try to run, I get "An exception 'System.IndexOutOfRangeException' has occurred in WindowsApplication2.exe"

Any ideas what I may be doing wrong?
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 12160468
Nevermind, got it!  Thanks for the help!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
I need help displaying 2 models in one view in my MVC.Net application with C# code behind 5 51
What namespace do I need to import? 2 29
Hey Audio! 3 30
Hey!! 5 33
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

803 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