Solved

Program Launching Options

Posted on 2004-09-26
5
222 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Input parameteres to DragOver 2 58
locate sql commands in C# visual studio Project 6 70
C# LINQ query question 11 33
How do I "share" on social sites? 2 40
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

710 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