Solved

Program Launching Options

Posted on 2004-09-26
5
221 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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
Video Player 12 28
Jquery/JSON passing value from one function to another 12 60
Object Oriented Programming, C#, referencing, scoping. 13 69
Why use this lambda? 12 39
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

830 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