?
Solved

Automatically run an application as another user

Posted on 2010-01-08
3
Medium Priority
?
284 Views
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?

Thanks!
0
Comment
Question by:odddball
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
flyingsky earned 2000 total points
ID: 26210592
try run the application as service
http://www.tacktech.com/display.cfm?ttid=197
0
 
LVL 33

Expert Comment

by:Todd Gerbert
ID: 26210697
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.
0
 
LVL 33

Expert Comment

by:Todd Gerbert
ID: 26210937
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>
		[STAThread]
		static int Main(string[] args)
		{
			if (args.Length < 3)
			{
				Usage();
				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];
			}
			else
				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.Password.AppendChar(c);

			proc.StartInfo.UseShellExecute = false;
			proc.StartInfo.WindowStyle = ProcessWindowStyle.Normal;

			try
			{
				proc.Start();
			}
			catch (Exception ex)
			{
				MessageBox.Show("Error:\r\n" + ex.Message);
				return 2;
			}

			return 0;
		}

		private static void Usage()
		{
			MessageBox.Show(String.Format(@"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

0

Featured Post

 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

Question has a verified solution.

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

This is a guide to the following problem (not exclusive but here) on Windows: Users need our support and we supporters often use global administrative accounts to do this. Using these accounts safely is a real challenge. Any admin who takes se…
OfficeMate Freezes on login or does not load after login credentials are input.
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…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

864 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