Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

batch file scipt

Status
Not open for further replies.

sirron

Programmer
Mar 11, 2004
139
US
I have a batch file that runs a batch file

But this batch file has a custom cmd prompt.

When I run it it asks for a username and password.
I have the username and password.

How can I run it automaticly input the username password
username: admin
password changeme

example:

C:\bat>rem @echo off

C:\bat>C:

C:\bat>cd\CNR\NetworkRegistrar\bin

C:\CNR\NetworkRegistrar\bin>nrcmd.bat
username:

and this is the code

rem @echo off
C:
cd\CNR\NetworkRegistrar\bin
nrcmd.bat
 
Depends on what is in nrcmd.bat - something in there does the prompt.

You *might* be able to redirect into it:

echo myusername >temp.in
echo mypassword >>temp.in
CALL nrcmd.bat <temp.in
 
hello sirron,

What do the 2 prompts for name and password read? I mean such as "enter user name: " or something like that.

regards - tsuji
 



The two prompts read
username:
password:

I tried this I'm not sure that its working. If it is, how would I put my username (admin) and password (changeme)into the command automaticly.

Could you help me?


@echo off
C:
cd\CNR\NetworkRegistrar\bin
echo username>temp.in
echo password>>temp.in

CALL nrcmd.bat<temp.in
 
Sirron,

When you launch the bat, use the .exec method so that you can have a grip of the stdin and stdout. Something like this.
Code:
suser="jsmith"
spwd="x0y1z2"

set wshshell=createobject("wscript.shell")
wshshell.currentdirectory="c:\CNR\NetworkRegistrar\bin"
set oexec=wshshell.exec("nrcmd.bat")
prompt=""
wscript.sleep 100
do while true
    if not oexec.stdout.atendofstream then
        prompt=prompt & oexec.stdout.read(1)
        if instr(1, prompt, "username:",1)<>0 then exit do
    end if
    wscript.sleep 50
loop
oexec.stdin.write suser & vbcrlf
wscript.sleep 200
prompt=""
do while true
    if not oexec.stdout.atendofstream then
        prompt=prompt & oexec.stdout.read(1)
        if instr(1, prompt, "password:",1)<>0 then exit do
    end if
    wscript.sleep 50
loop
oexec.stdin.write spwd & vbcrlf
'let the rest bat run until finished only if necessary
do while oexec.status<>1 : wscript.sleep 100 : loop
Do not expect to get it through. Run it an monitor what happens on the console for further debugging

- tsuji
 
set wshshell=createobject("wscript.shell")
wshshell.currentdirectory="c:\CNR\NetworkRegistrar\bin"
set oexec=wshshell.exec("nrcmd.bat")

This part runs great but the rest is not working.

Once this nrcmd.bat runs it will open the DOS command

the username is first, here it is asking for an input username
username:

after you input the username it will ask for an input password
password:

Do you know why its not working, or is there a way to input commands in the DOS prompt
 
sirron,

Have you modified the suser and spwd to your spec. They are there for your specific input.

- tsuji
 
this is what I changed

suser="admin"
spwd="changeme"

set wshshell=createobject("wscript.shell")
wshshell.currentdirectory="c:\CNR\NetworkRegistrar\bin"
set oexec=wshshell.exec("nrcmd.bat")
 
sirron,

That is how it is intended. I'll test the logic. Not this moment, time is late for me.

- tsuji
 
sirron,

I do not have much to modify the original proposal. It flows correctly in big picture. Only minor specific consideration might be needed.

But one thing I have not pointed out, in case you do not know, is that you have to run the script with cscript as host. So either you have a file association with cscript //nologo as command (if not the default action, access it with right-click context menu) or you click out the cmdprompt window and issue the instruction:
[tt] cscript.exe //nologo scriptname.vbs[/tt]
with path appended if necessary.

- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top