0

I would like to start Internet Explorer as a different user through a command line alias. I liked the approach of using an AutoRun registry setting to call an environment setting script.

So I have an AutoRun registry key (REG_SZ) setup for HKCU\Software\Microsoft\Command Processor to execute an env.cmd file. The env.cmd file has one line in it: DOSKEY ieas=runas /user:user /netonly "C:\Program Files\Internet Explorer\iexplore.exe"

My question is whether there a way to write the DOSKEY command in the env.cmd file so that I can pass in the user name when I invoke ieas? I want to type: ieas MyDomain\SomeUser and have runas use MyDomain\SomeUser for the /user variable and prompt me for the specified account's password.

AgentExe
  • 17
  • 4
  • `DOSKEY ieas=runas /user:$1 /netonly "C:\...\iexplore.exe"` as per `doskey /?` (use full path to `iexplore.exe`, of course) – JosefZ Jul 10 '15 at 00:18
  • Thanks! That worked. I tried $* as well, but $1 is more appropriate for the use intended. – AgentExe Jul 13 '15 at 15:20

1 Answers1

0
DOSKEY ieas=runas /user:$1 /netonly "C:\Program Files\Internet Explorer\iexplore.exe"

As per doskey /?:

Edits command lines, recalls Windows commands, and creates macros.

DOSKEY [/REINSTALL] [/LISTSIZE=size] [/MACROS[:ALL | :exename]]
  [/HISTORY] [/INSERT | /OVERSTRIKE] [/EXENAME=exename] [/MACROFILE=filename]
  [macroname=[text]]
...
  macroname           Specifies a name for a macro you create.
  text                Specifies commands you want to record.
...

The following are some special codes in Doskey macro definitions:
$T     Command separator.  Allows multiple commands in a macro.
$1-$9  Batch parameters.  Equivalent to %1-%9 in batch programs.
$*     Symbol replaced by everything following macro name on command line.
JosefZ
  • 28,460
  • 5
  • 44
  • 83