"Run As," Adding Names to Drop-Down Box

  • Thread starter Thread starter M.H.
  • Start date Start date
M

M.H.

When I right-click an application, and click "Run as...," the "Run As"
window pops up. There are two radio boxes, "Current User" and "The
following user:" If I fill the second radio box, "The following user:"
I have two fields, "User name" and "Password." The "User name" field is
also a drop-down box, which lists one or more account names to run
under. Currently, only the administrator account is listed in the
drop-down box. What I want to do is add another account to the "User
name" drop-down box, so I do not have to manually type in the desired
account every time I use the "Run As" feature. How do I do this? Thanks.
 
I am not sure if what you ask for can be done but their is an alternative.
Simply created a file called, "MyProgram.cmd" with notepad. Then use the
following to start the desired program with different user credentials.

Contents of "MyProgram.cmd"
-------
runas /user:username "c:\program files\myprogram.exe"

----

You will be asked for a password, simply type in the password for the
username you specified to start the program.

Or you can create Script called "MYProgram.vbs" with the user credentials
already supplied.

Contents of "MyProgram.vbs"
 
WTC said:
I am not sure if what you ask for can be done but their is an alternative.
Simply created a file called, "MyProgram.cmd" with notepad. Then use the
following to start the desired program with different user credentials.

Contents of "MyProgram.cmd"
-------
runas /user:username "c:\program files\myprogram.exe"

----

You will be asked for a password, simply type in the password for the
username you specified to start the program.

Or you can create Script called "MYProgram.vbs" with the user credentials
already supplied.

Contents of "MyProgram.vbs"

-------
set WshShell = CreateObject("WScript.Shell")
WshShell.Run "runas /user:Username ""C:\Program Files\myprogram.exe"""
WScript.Sleep 100
WshShell.Sendkeys "password~"

--------
Neither of those are working properly for me. The former, I get a CLI
prompt to enter my password. I do that, window closes, nothing happens.
Second one, I see a window flash, then nothing. I click on the .exe at
C:\Program Files\myprogram\myprogram.exe, it starts up without any problem.
 
M.H. said:
Neither of those are working properly for me. The former, I get a CLI
prompt to enter my password. I do that, window closes, nothing happens.
Second one, I see a window flash, then nothing. I click on the .exe at
C:\Program Files\myprogram\myprogram.exe, it starts up without any
problem.


Ok on the first run as command make sure you have the path to the program
wrap in quotes ("C:\Program Files\myprogram.exe"). Also make sure you
replace Username with you user account.

On the second one, the script, make sure you have the quotations exactly
like I have in the script. Also, replace Username with your User Account
Name. Change 100 to 500. If your password is 123456 then make sure the
password you enter has the ~ at the end like this "1234656~".
 
WTC said:
Ok on the first run as command make sure you have the path to the program
wrap in quotes ("C:\Program Files\myprogram.exe"). Also make sure you
replace Username with you user account.

On the second one, the script, make sure you have the quotations exactly
like I have in the script. Also, replace Username with your User Account
Name. Change 100 to 500. If your password is 123456 then make sure the
password you enter has the ~ at the end like this "1234656~".
Here is what I have:

LibertyBasic.cmd
-----
runas /user:MHxxxxx "C:\Program Files\Liberty BASIC v4.03\liberty.exe"
-----

LibertyBasic.vbs
-----
set WshShell = CreateObject("WScript.Shell")
WshShell.Run "runas /user:MHxxxxx ""C:\Program Files\Liberty BASIC
v4.03\liberty.exe"""
WScript.Sleep 500
WshShell.Sendkeys "xxxxx~"
-----

The only change made was "Sleep 500" from "Sleep 100." I'm still
getting for the cmd a CLI prompt to enter password, then nothing, and
for the VBS a window that flashes for slightly longer (I think, as is
that what "Sleep" does?) and then disappears.
 
M.H. said:
Here is what I have:

LibertyBasic.cmd
-----
runas /user:MHxxxxx "C:\Program Files\Liberty BASIC v4.03\liberty.exe"
-----

LibertyBasic.vbs
-----
set WshShell = CreateObject("WScript.Shell")
WshShell.Run "runas /user:MHxxxxx ""C:\Program Files\Liberty BASIC
v4.03\liberty.exe"""
WScript.Sleep 500
WshShell.Sendkeys "xxxxx~"
-----

The only change made was "Sleep 500" from "Sleep 100." I'm still
getting for the cmd a CLI prompt to enter password, then nothing, and
for the VBS a window that flashes for slightly longer (I think, as is
that what "Sleep" does?) and then disappears.


Could you open the Command Prompt and type:

runas /user:MHxxxxx "C:\Program Files\Liberty BASIC v4.03\liberty.exe"

Does any errors occur? If there is an error, it will also affect the
"LibertyBasic.vbs" script.
 
WTC said:
Could you open the Command Prompt and type:

runas /user:MHxxxxx "C:\Program Files\Liberty BASIC v4.03\liberty.exe"

Does any errors occur? If there is an error, it will also affect the
"LibertyBasic.vbs" script.
I discovered that I made an error in the username. It's not MHxxxx,
it's M. Hxxxx. Now when I type runas /user:M. Hxxxxx "C:\Program
Files\Liberty BASIC v4.03\liberty.exe" in the CLI, and then the
password, it says:

RUNAS ERROR: Unable to run - C:\Program Files\Liberty BASIC
v4.03\liberty.exe
1326: Logon failure: unknown user name or bad password.
 
M.H. said:
I discovered that I made an error in the username. It's not MHxxxx,
it's M. Hxxxx. Now when I type runas /user:M. Hxxxxx "C:\Program
Files\Liberty BASIC v4.03\liberty.exe" in the CLI, and then the
password, it says:

RUNAS ERROR: Unable to run - C:\Program Files\Liberty BASIC
v4.03\liberty.exe
1326: Logon failure: unknown user name or bad password.


If you have spaces in the username like M. Hxxxx then put quotes around it
like "M. Hxxxx". So now the runas line should look like this:

runas /user:"M. Hxxxx" "C:\Program Files\Liberty BASIC v4.03\liberty.exe"

Change the script file as well.
 
WTC said:
If you have spaces in the username like M. Hxxxx then put quotes around it
like "M. Hxxxx". So now the runas line should look like this:

runas /user:"M. Hxxxx" "C:\Program Files\Liberty BASIC v4.03\liberty.exe"

Change the script file as well.
I've added quotes around the username in both files. Now for the cmd
file, it prompts me to enter the password in a CLI, I do, then nothing
happens. The Script is now giving the error "Script: "%scriptname%"
Line: 2 Char: 29 Error: Expected end of statement Code: 800A0401 Source:
Microsoft VBScript compliations error."
 
WTC said:
If you have spaces in the username like M. Hxxxx then put quotes around it
like "M. Hxxxx". So now the runas line should look like this:

runas /user:"M. Hxxxx" "C:\Program Files\Liberty BASIC v4.03\liberty.exe"

Change the script file as well.
Oh, nm, regarding the cmd, if I enter the right password, the program
starts. Just if you enter the wrong password, the window closes,
without prompting the user to re-enter the password.
 
M.H. said:
I've added quotes around the username in both files. Now for the cmd
file, it prompts me to enter the password in a CLI, I do, then nothing
happens. The Script is now giving the error "Script: "%scriptname%"
Line: 2 Char: 29 Error: Expected end of statement Code: 800A0401 Source:
Microsoft VBScript compliations error."


I am sorry. I made an error...should have been double quotes around the
Username.

set WshShell = CreateObject("WScript.Shell")
WshShell.Run "runas /user:""M. Hxxxxx "" ""C:\Program Files\Liberty BASIC
v4.03\liberty.exe"""
WScript.Sleep 500
WshShell.Sendkeys "xxxxx~"

Hopefully this will work for you now. Wrap out for the line wrap in the 2nd
line. Also you can change the 500 to 100 if you wish.
 
M.H. said:
Oh, nm, regarding the cmd, if I enter the right password, the program
starts. Just if you enter the wrong password, the window closes,
without prompting the user to re-enter the password.

Glad you got that sorted out.
 
WTC said:
I am sorry. I made an error...should have been double quotes around the
Username.

set WshShell = CreateObject("WScript.Shell")
WshShell.Run "runas /user:""M. Hxxxxx "" ""C:\Program Files\Liberty BASIC
v4.03\liberty.exe"""
WScript.Sleep 500
WshShell.Sendkeys "xxxxx~"

Hopefully this will work for you now. Wrap out for the line wrap in the 2nd
line. Also you can change the 500 to 100 if you wish.
I now have this for the VBS:

set WshShell = CreateObject("WScript.Shell")
WshShell.Run "runas /user: ""M. Hxxxxx"" ""C:\Program Files\Liberty
BASIC v4.03\liberty.exe"""
WScript.Sleep 500
WshShell.Sendkeys "xxxxx~"

Still doesn't seem to be working. Just a window briefly flashes, then
closes.
 
M.H. said:
I now have this for the VBS:

set WshShell = CreateObject("WScript.Shell")
WshShell.Run "runas /user: ""M. Hxxxxx"" ""C:\Program Files\Liberty

There is no space between /user: and ""M.

It should read:

WshShell.Run "runas /user:""M. Hxxxxx"" ""C:\Program Files\Liberty BASIC
v4.03\liberty.exe"""
 
WTC said:
There is no space between /user: and ""M.

It should read:

WshShell.Run "runas /user:""M. Hxxxxx"" ""C:\Program Files\Liberty BASIC
v4.03\liberty.exe"""
K, both work now. Thanks.
 
What do you think of this script? It prevents the password from being
stored in the script directly, which would allow someone to easily steal
the password:

set WshShell = CreateObject("WScript.Shell")
WshShell.Run "runas /savecred /user:""M. xxxxx"" ""C:\Program
Files\Liberty BASIC v4.03\liberty.exe"""
WScript.Sleep 100

Upon first run, it prompts the user to enter a password in the CLI.
Afterwards, it appears to store the password (not sure where or how
securely), and run the program under the user account as defined in the
WshShell.Run line.
 
M.H. said:
What do you think of this script? It prevents the password from being
stored in the script directly, which would allow someone to easily steal
the password:

set WshShell = CreateObject("WScript.Shell")
WshShell.Run "runas /savecred /user:""M. xxxxx"" ""C:\Program
Files\Liberty BASIC v4.03\liberty.exe"""
WScript.Sleep 100

Upon first run, it prompts the user to enter a password in the CLI.
Afterwards, it appears to store the password (not sure where or how
securely), and run the program under the user account as defined in the
WshShell.Run line.


I am not too sure why either. I will run some tests when I get some free
time tonight. I will post back in the next 24 hours.
 
M.H. said:
What do you think of this script? It prevents the password from being
stored in the script directly, which would allow someone to easily steal
the password:

set WshShell = CreateObject("WScript.Shell")
WshShell.Run "runas /savecred /user:""M. xxxxx"" ""C:\Program
Files\Liberty BASIC v4.03\liberty.exe"""
WScript.Sleep 100

Upon first run, it prompts the user to enter a password in the CLI.
Afterwards, it appears to store the password (not sure where or how
securely), and run the program under the user account as defined in the
WshShell.Run line.


I cannot reproduce what you have done. When I removed the password line of
script like you have and run the script file, I am always prompted for a
password.

Maybe the program is not closing out properly? When you close the program
can you open Task Manager, look under processes and verify the liberty
program is not running. Make sure you have "Show Process from all users"
enabled. This may reveal the Liberty program is still running under the M.
xxxxx account.
 
WTC said:
I cannot reproduce what you have done. When I removed the password line of
script like you have and run the script file, I am always prompted for a
password.

Maybe the program is not closing out properly? When you close the program
can you open Task Manager, look under processes and verify the liberty
program is not running. Make sure you have "Show Process from all users"
enabled. This may reveal the Liberty program is still running under the M.
xxxxx account.
In Task Manager, it is running under the other, correct account. It is
closing properly as well, as the program is no longer listed in Task
Manager after quitting from it. Maybe you have to have the password
line in the script with the /savecred switch on one run? Although that
doesn't make sense, as it still prompted me for the password after
removing the password line, although only once.1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top