Run as a different user on a shortcut

15

1

How do I run as a different user on a shortcut in Windows 7?

On Windows XP, I had the ability to mark a shortcut as being run by a different user, so that every time I ran it it would prompt me for a username/password. This let me have two shortcuts for things like SQL Server Management Studio, one for my normal account and one for my domain administrator account which has access to production servers.

I can get to the 'Run as different user' option with Shift + right-click, but I can't see an option anywhere that would let me mark the shortcut as doing this every time.

PhilPursglove

Posted 2010-03-26T14:56:16.030

Reputation: 391

Answers

21

  1. Right-click > New > Shortcut
  2. For Target, type "runas /user:domain\user program.exe"

I think you can replace "domain" with the computer name if you want it to use a local account.

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/windows_security_runas_shortcut.mspx?mfr=true

The link above is for XP, but I was able to do this in Windows 7. When you double-click the shortcut, it will open a cmd that will prompt you for the user's password. What's interesting is that it doesn't display asterisks (or anything) as you type in the password. However, I did just test it and it is accepting the password you type.

Chris Dwyer

Posted 2010-03-26T14:56:16.030

Reputation: 2 185

Not as good as what was in XP IMO but a perfectly acceptable workaround - thanks! – PhilPursglove – 2010-03-26T15:46:05.533

This doesn't work on win 10: The requested operation requires elevation – Aaron – 2015-10-29T20:40:52.483

4

To add to what the above user said:

C:\Windows\System32\runas.exe /storecred /user:Domain\UserName "mmc %windir%\system32\dsa.msc"

(This "mmc %windir%\system32\dsa.msc" is for running active directory users and computers as an example)

Victor

Posted 2010-03-26T14:56:16.030

Reputation: 51

1Using the "/savecred" (or "/storecred"?) switch is a huge potential security hole. See my answer here: superuser.com/a/903881/229612 (and includes a working solution to the problem of running a program with elevated rights). – C. M. – 2015-04-20T17:37:30.267

0

#Create a Desktop Shortcut with Windows PowerShell
If(!$ShortcutFileName)
{
    $ShortcutFileName = (Get-Item $TargetFile).Basename
}
$ShortcutFile = "$env:Public\Desktop\$ShortcutFileName.lnk"
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
#Run as different user, saves the password  
$a="runas.exe /savecred /user:$RunAsUser ""$TargetFile"""
$Shortcut.TargetPath = "runas.exe"
$Shortcut.Arguments = "/savecred /user:$RunAsUser ""$TargetFile"""
$Shortcut.IconLocation = $TargetFile
$Shortcut.Save()  

You can download detail SQL script from how to create a shortcut to run an application as a different user(PowerShell)

frank tan

Posted 2010-03-26T14:56:16.030

Reputation: 41

Please don't copy and paste your answer across multiple questions. Preferably you should tailor your answer to suit the specific use case that OP needs, and if the questions need exactly the same answer then chances are they should be flagged as a duplicate. – Mokubai – 2016-12-13T07:40:15.547

Additionally you've left out the important information of just how to actually use this script and what it does. – Mokubai – 2016-12-13T07:47:52.120

0

You can use ShellRunas from Microsoft SysInternals. You can use "ShellRunas program.exe" in the shotcut to get the same behavior you had in XP.

EDIT: Apparently you have to type in the user name every time, so it's not exactly the behavior you wanted.

AlexDev

Posted 2010-03-26T14:56:16.030

Reputation: 121