Solved

Program Launching Options

Posted on 2004-09-26
5
218 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Nevermind, got it!  Thanks for the help!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now