I created a batch file named "query.bat" that allows me to query a domain user account.

@echo on
set /p logonname=Enter logonname:
net user /domain %logonname%

Now, I'm wondering how I could modify the code so I can type "query %username%" then press enter instead of it being a two step process.


To convert a Set /P variable to a passed in argument

You can use batch arguments and pass the value of the logon name to the script as the first argument. You can then reference the value of the first argument with %1. You can simply change set /p logonname=Enter logonname: to be set logonname=%1 in your script instead.


@echo on
set logonname=%1
net user /domain %logonname%

Further Resources

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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