Batch Script

March 11, 2011 at 09:15:36
Specs: Windows 7
I have been trying to create batch a script that maps a couple of drives with username and password prompt. That I have managed to do but I want it to repeat should the user get their password wrong and exit once they have successfully connected.

The script so far is: (please bare in mind I am a complete noob to this)

SET /P Username= Please Enter your Username:
editv32 -m -p "Please Enter your Password: " PWD
NET USE K: "\\kwy-sr-002\RMShared Documents" /USER:"KINGSWAY\%Username%" "%PWD%"
NET USE J: "\\kwy-sr-003\%username%$" /USER:"KINGSWAY\%Username%" "%PWD%"


See More: Batch Script

Report •


#1
March 11, 2011 at 11:21:15
Is this a domain or a workgroup. It looks like you have a domain named KINGSWAY. If this is the case then join the computers to the domain and let it do the authentication.

Report •

#2
March 11, 2011 at 11:35:10
These are going to be standalone but my aim is to use the script to map some drives for that session.


Report •

#3
March 11, 2011 at 12:59:28
You could use a if exists to see if the drive mapped...

@echo off

:MapDrives

SET /P Username= Please Enter your Username:
editv32 -m -p "Please Enter your Password: " PWD

NET USE K: "\\kwy-sr-002\RMShared Documents" /USER:"KINGSWAY\%Username%" "%PWD%"
NET USE J: "\\kwy-sr-003\%username%$" /USER:"KINGSWAY\%Username%" "%PWD%"

If not exist K: do (
  Echo User Name or Password failed...
  Goto :MapDrives
)

http://www.robvanderwoude.com/if.php


Report •

Related Solutions

#4
March 11, 2011 at 14:02:45
Excellent

That worked nicely, i had to change it slightly to

If not exist "b:\" (
Echo User Name or Password failed...
Goto :MapDrives

but works a treat.

CHeers


Report •

#5
March 14, 2011 at 14:46:46
Back again with a related question.

Is there an if "or" statement?

eg

If not exist "b:\ or n:\"
(
Echo User Name or Password failed...
Goto :MapDrives

I need it to determine if there is one or more drive already connected


Report •

#6
March 14, 2011 at 16:05:06
No, you will have to do it through a If Else...

IF not exist "b:\" (
Goto :DoSomething
) ELSE (IF not exist "n:\" (
Goto :DoSomething
))
Goto :End

:DoSomthing
echo Your command here

:End

This is equivalent to an OR.


Report •

#7
March 15, 2011 at 13:08:17
Unfortunately it does the first part seems to ignore the ELSE command altogether.

I have two types of users connecting with this script Staff and students

Staff have M:\ Students have N:\ below is the stat

When staff connect it will ignore the N:\ drive and vice versa for the students for M:\

I want it to then say if either n:\ or m:\ not connect got back to :mapdrives

If it is connected got to end.


Report •

#8
March 15, 2011 at 13:46:20
If you're checking to see if neither drive exists (logical AND), that'd look something like this:
IF NOT EXIST "N:\" IF NOT EXIST "M:\" CALL :mapdrives

How To Ask Questions The Smart Way


Report •


Ask Question