2

I need to write batch file in windows for one utility. But the utility asks for username and password everytime I run from command prompt. I want to pass the username and pwd when it prompts in command prompt. Now after the command runs, the question for username and password comes qs 2 seperate questions like: enter uname: enter pwd:

Which become a problem since only passing as %1 and %2 as parameter is not helping as uname and pwd is coming as seperate qs. Please help me write a batch in windows...Im totally new to windows prog...

1
  • Better option is to modify the utility if you have source code. Commented Mar 31, 2013 at 9:55

4 Answers 4

1

Have you checked that the utility:

  • doesn't have any command line parameters for entering username/password?
  • doesn't have other mechanism for entering username password, like using Environment variables?

I assume you checked all this and there is no other choice than typing the username and passwords manually.

In that case, you should have a look at AutoHotkey.
It is used to create scripts that can automate UI input, in particular running apps requiring keyboard and mouse control.

There is also a small utility called SendKeys.net used for batch files.
Haven't tested it though.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Renaud for the reply...Actually this is a third party utility and we dont have any control over it. After passing the command, it always asks for uname and pwd which we have to enter manually.. Now, i need to write a batch which will automate this whole process.. I tried all other ways but could not... Isnt there a way in windows batch to handle entering uname and pwd when prompted??
0

Renauld is right, command line parameters would be the best solution. Take a look to your utilities Manual or try utility.exe /?

The following solution MAY work (or may not) Write your answers to a file (e.g. "credentials.txt") (make sure, it contains only the two lines)

myusername
mypassword

Then try

myutility < credentials.txt

For security-reason this would not work, if I wrote that utility.

Comments

0

This task can be done by VBS in Windows. You can use SendKeys() to simulate the keyboard action. It works like the command 'expect' in Linux. BAT can't help you here.

Comments

0

You can call this batch-HTA-VBScript hybrid file (GUI Login Prompt):

<!-- :

  :: LoginGUI.bat | Wasif Hasan | Sep 2020
  :: This is a Batch-HTA-VBScript hybrid that will show a GUI window to login
  :: Save it as a .bat file and run it in your other batch files
  :: and returns the username and password as a result (to STDOUT) (in "username;password" format)
  :: If you enter no password in the dialog it will show an error message box and persist 
  :: Arguments: "BatchFilePath" "prompt (To Show beside the password box)" BoolAllowBlankUsername BoolAllowBlankPassword
  :: Default prompt is "password"

  @echo off & setlocal EnableDelayedExpansion
  if "%*"=="" (
  for /f "tokens=* delims=" %%a in ('echo "Password:" False False ^| mshta.exe "%~f0"') do set "pass=%%a"
  ) else (
  for /f "tokens=* delims=" %%a in ('echo %* ^| mshta.exe "%~f0"') do set "pass=%%a"
  )
  echo !pass! & exit /b 0

-->

<!DOCTYPE html>
<html>
<head>
<title>Password box</title>
<hta:application
  applicationName="Password box"
  border="thin"
  maximizeButton="no"
  minimizeButton="no"
  showinTaskbar="no"
  scroll="no"
  singleInstance="yes"
  contextMenu="no"
  selection="no"
/>
<script type="text/vbscript">
  Sub Window_OnLoad()
    Dim fso2, strPrompt, dblQuote
    window.resizeTo 320,180
    Set fso2 = CreateObject("Scripting.FileSystemObject").GetStandardStream(0)
    strPrompt = fso2.ReadLine
    dblQuote = Chr(34)
    strPromptX = Split(strPrompt," ")
    strPrompt = strPromptX(0)
    strPrompt = Replace(strPrompt, dblQuote, "")
    Document.All.prompt.innerHTML = strPrompt
    document.All.username.Focus
  End Sub
  Sub Validate() 
    Dim fso, GetPassword, GetUsername
    GetPassword = Document.All.Password.Value
    GetUsername = Document.All.username.Value
    If GetPassword = "" Then 
      If Not allowBlankPassword = True Then
        MsgBox "Please enter a password!",48,"Password box"
      End If
    ElseIf GetUsername = "" Then
      If Not allowBlankUsername = True Then
        MsgBox "Please enter a username!",48,"Password box"
      End If 
    Else
      Set fso = CreateObject("Scripting.FileSystemObject").GetStandardStream(1)
      window.Close(fso.write(GetUsername & ";" & GetPassword))
    End If
  End Sub
</script>
</head>
<body style="background-color:lightblue;font-family:Tahoma;">
<div align="center">
<span id="username_l">Username:</span>
<input type="text" size="20" id="username" /><br /><br />
<span id="prompt">Password:</span>
<input type="password" size="20" id="Password" />
<p><input type="button" value="Login" onClick="Validate()" /></p>
</div>
</body>
</html>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.