Automatically run an application as another user

Posted on 2010-01-08
Last Modified: 2013-12-04
Specific users need to run a particular application.  However, the user can only be a "User" on the local workstation.  This application that needs to be run needs to run with an account that has "Administrator" privledges on the local workstation.  The "Run As" feature works, but we would like to not have the user know the administrator account.  Is there a way to automatically have an application (or shortcut, whatever) run with a specific account so that users do not need to know the account info?  So that when the User clicks the icon, it automatically runs with a Administrator (or different) account?

Question by:odddball
    LVL 18

    Accepted Solution

    try run the application as service
    LVL 33

    Expert Comment

    by:Todd Gerbert
    I use a small .Net program, that I wrote in C#, to start programs as another user without requiring the user to know the credentials.  In my case I store the the username and password in a plain text config file, which is a huge security no-no.  Encrypting it would help, but I think most security-concsious admins would still frown upon it.
    LVL 33

    Expert Comment

    by:Todd Gerbert
    I would imagine there's something like this out there already, but here's a simple "runas" program that will accept a password on the command line.
    using System;
    using System.Windows.Forms;
    using System.Diagnostics;
    namespace MyRunAs
    	static class Program
    		/// <summary>
    		/// The main entry point for the application.
    		/// </summary>
    		static int Main(string[] args)
    			if (args.Length < 3)
    				return 1;
    			Process proc = new Process();
    			for (int i = 3; i < args.Length; i++)
    				proc.StartInfo.Arguments += args[i] + " ";
    			proc.StartInfo.CreateNoWindow = false;
    			string[] domainAndUser = args[1].Split('\\');
    			if (domainAndUser.Length > 1)
    				proc.StartInfo.Domain = domainAndUser[0];
    				proc.StartInfo.UserName = domainAndUser[1];
    				proc.StartInfo.UserName = domainAndUser[0];
    			proc.StartInfo.ErrorDialog = true;
    			proc.StartInfo.FileName = args[0];
    			proc.StartInfo.Password = new System.Security.SecureString();
    			foreach (char c in args[2])
    			proc.StartInfo.UseShellExecute = false;
    			proc.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
    			catch (Exception ex)
    				MessageBox.Show("Error:\r\n" + ex.Message);
    				return 2;
    			return 0;
    		private static void Usage()
    {0} <command> <username> <password> [parameters]
    Paramenters in <> brackets required, in [] brackets optional.
    command: The command to run with alternate credentials.
    username: The user to run command as, use DOMAIN\User format if necessary.
    password: The password for username.", System.IO.Path.GetFileName(Application.ExecutablePath)));

    Open in new window


    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    In today's information driven age, entrepreneurs have so many great tools and options at their disposal to help turn good ideas into a thriving business. With cloud-based online services, such as Amazon's Web Services (AWS) or Microsoft's Azure, bus…
    No security measures warrant 100% as a "silver bullet". The truth is we also cannot assume anything but a defensive and vigilance posture. Adopt no trust by default and reveal in assumption. Only assume anonymity or invisibility in the reverse. Safe…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    729 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

    15 Experts available now in Live!

    Get 1:1 Help Now