Jared
Jared

Reputation: 1897

Username/password dialog from batch script

I need to prompt for a username and password from a batch script subroutine and I have the following requirements:

  1. Must be user-friendly (i.e. not on the command line, but from a dialog box).
  2. Must mask the password.
  3. Must not require customized settings or installation before I run the batch script (no AutoIT or odd IE settings).
  4. Must be compatible with Windows XP, 2008, and 7 (though if variations on a theme are appropriate I can check the specific OS).

I'm assuming that I may need to use VBscript, which I can easily create from within the batch script and then delete afterward. I did find this link, with two different VBScript options, but the first one violates requirement 1 (console based), and the second violates requirement 3 (default IE settings aren't allowing dynamic content these days). Any other ideas?

Upvotes: 1

Views: 2978

Answers (3)

Rob Haupt
Rob Haupt

Reputation: 2144

Is using Powershell out of the question?

You can use Get-Credential to prompt for authentication.

$Credentials = Get-Credential Domain\UserName

Edit:

Another option if distributing this application is to just put the prompt for a username and password in the installer. You could do this in an MSI, but it is probably a lot more overhead than you'd want. You could instead use NSIS and prompt for the info in the installer wizard. NSIS is self-contained and would run on all the OS's you specified.

Upvotes: 1

Cheran Shunmugavel
Cheran Shunmugavel

Reputation: 8459

HTML Applications might work for you. You could create a simple page with an <input type="password" /> control. I can't think of a good way to get the password from the HTA back to the batch file, though, other than writing the password to a temporary file, or maybe a registry key.

Upvotes: 1

Uwe Keim
Uwe Keim

Reputation: 40736

I would write a native C++ or Delphi application that consists of a single dialog with a password input field.

Compiling this to a single executable and returning the entered value to the calling process, the batch script could ship with the executable in the same folder and use it to query for the password.

If .NET is an option, write a WindowsForms application instead of native C++ (for speed of development)

Upvotes: 1

Related Questions