Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Program Launching Options

Posted on 2004-09-26
5
Medium Priority
?
224 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 2000 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

715 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