Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I use runas /user:abc cmd to start a command prompt. After login, I will run a vbs script.

The login abc has special file/folder permission, and it is the main reason for using runas. Otherwise the vbs script will not work due to lack of permission

Inside this command prompt session, how can I obtain the username which started the runas command? I want to log this information inside my vbs script.

As an example, let's say my id is 'akong'. After I started command prompt as 'abc' with runas, I want to be able print out 'akong' one way or another.

share|improve this question

3 Answers 3

AFAIK you would need to send this information in to the script.

example:

runas /user:abc program.exe %username%

I'm guessing that the env will get expanded before the command is processed.. but I have no way of verifying that at the moment.

share|improve this answer

as long as you dont use /noprofile as a switch for runas, user abc's profile will load. You can simply type

whoami

at the command line and it will return domainname\abc

or from in the VBScript:

Set objNet = CreateObject("WScript.NetWork")

strInfo = "User Name is " & objNet.UserName & vbCRLF & _ "Computer Name is " & objNet.ComputerName & vbCRLF & _ "Domain Name is " & objNet.UserDomain

MsgBox strInfo

share|improve this answer
    
Thanks for the answer. I have clarified my question by adding an example. I actually want to print my original id, not the runas id 'abc'. Whoami prints 'abc' regardless /noprofile is used or not. –  Anthony Kong Jan 23 '13 at 4:30

I am beginning to think it's not possible to get the original user's name. At the commandline I tried

Set

It lists all the 'abc' user details and none of the 'akong' user.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.