Batch file searches

  • Thread starter Thread starter andrew.pound
  • Start date Start date
A

andrew.pound

Bit of a problem, with a batch file I have to create, wonder if any
one can help

I have an existing share ?:\\server1\servershare that has been moved
to x:\\server2\servershare

As not all of the users that use this share have an exisitng share
mapped as x:\ is there a batch file I can get the users to click on
that
1. Searches for a mapped drive with the word \\server1\servershare
finds it, and deletes it
2. Then runs net use x: \\server2\servershare.

am happy with net use ?:/delete, but as stated not all users are using
the x drive for this share, and it must now reside there.

Any Help would be much appreicated
 
Bit of a problem, with a batch file I have to create, wonder if any
one can help

I have an existing share ?:\\server1\servershare that has been moved
to x:\\server2\servershare

As not all of the users that use this share have an exisitng share
mapped as x:\ is there a batch file I can get the users to click on
that
1. Searches for a mapped drive with the word \\server1\servershare
finds it, and deletes it
2. Then runs net use x: \\server2\servershare.

am happy with net use ?:/delete, but as stated not all users are using
the x drive for this share, and it must now reside there.

Any Help would be much appreicated

Try this:
Line1 @echo off
Line2 for /F "tokens=2" %%a in ('net use ^| find /i \\server1\servershare')
do set drive=%%a
Line3 if "%drive%"=="" goto :eof
Line4 net use %Drive% /del
Line5 net use x: \\server2\servershare

Note that these problems are usually avoided by having
an explicit logon script instead of relying on remembered
connections.
 
Try this:
Line1 @echo off
Line2 for /F "tokens=2" %%a in ('net use ^| find /i \\server1\servershare')
do set drive=%%a
Line3 if "%drive%"=="" goto :eof
Line4 net use %Drive% /del
Line5 net use x: \\server2\servershare

Note that these problems are usually avoided by having
an explicit logon script instead of relying on remembered
connections.- Hide quoted text -

- Show quoted text -

Totally agree, however inherited this task rather than set it out,
hopefully will be able to secure funds to get the process started in
mean time............ Thanks will try this and hopefully enough of my
fried brain will be able to get it running, cheers mate
 
Totally agree, however inherited this task rather than set it out,
hopefully will be able to secure funds to get the process started in
mean time............ Thanks will try this and hopefully enough of my
fried brain will be able to get it running, cheers mate- Hide quoted text -

- Show quoted text -

Alas failed, maybe through user error but believe that the error is in
Line 2, not sure why? any helpers

Cheers

Andrew
 
Alas failed, maybe through user error but believe that the error is in
Line 2, not sure why? any helpers

Cheers

Andrew

I can't tell because you're not telling us what YOUR line 2 looks like!
 
text -



I can't tell because you're not telling us what YOUR line 2 looks like!- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -

HI mate, thanks for everything so fae Line 2 looks like
for /F "tokens=2" %%a in ('net use ^| find /i \\data2\counterfraud
$')do set drive=%%a

Hope you can help. Cheers anyway
Andrew
 
HI mate, thanks for everything so fae Line 2 looks like
for /F "tokens=2" %%a in ('net use ^| find /i \\data2\counterfraud
$')do set drive=%%a

Hope you can help. Cheers anyway
Andrew

Two mistakes: One of mine, one of yours. I omitted some double
quotes and you omitted a space before the word "do". The line
should read like so:

for /F "tokens=2" %%a in ('net use ^| find /i "\\data2\counterfraud"') do
set drive=%%a
 
Hide quoted text -




Two mistakes: One of mine, one of yours. I omitted some double
quotes and you omitted a space before the word "do". The line
should read like so:

for /F "tokens=2" %%a in ('net use ^| find /i "\\data2\counterfraud"') do
set drive=%%a- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -

<Bows down before genius> thank you very much, worked a treat, and as
usual a complete revised job to do, they now want the same drive
letter mapped and there are 130 odd shares, this is going to be fun,
have made a small amendment to file and will use faithful cut and
paste, now will lokk like this exept about another 129 drives to map
LOL, (pause is for testing purposes only)
"It's not the despair, I can cope with the despair...It's the Hope"


:counterfraud
for /F "tokens=2" %%a in ('net use ^| find /i "\\data2\counterfraud
$"') do set drive=%%a
pause
if "%drive%"=="" goto :dacaudit
pause
net use %Drive% /del
pause
net use %Drive% \\dptdata\counterfraud$ /persistent:Yes
pause

:dacaudit
for /F "tokens=2" %%a in ('net use ^| find /i "\\data2\dacaudit$"') do
set drive=%%a
pause
if "%drive%"=="" goto :eof
pause
net use %Drive% /del
pause
net use %Drive% \\dptdata\dacaudit$ /persistent:Yes
pause
 
<Bows down before genius> thank you very much, worked a treat, and as
usual a complete revised job to do, they now want the same drive
letter mapped and there are 130 odd shares, this is going to be fun,
have made a small amendment to file and will use faithful cut and
paste, now will lokk like this exept about another 129 drives to map
LOL, (pause is for testing purposes only)
"It's not the despair, I can cope with the despair...It's the Hope"


:counterfraud
for /F "tokens=2" %%a in ('net use ^| find /i "\\data2\counterfraud
$"') do set drive=%%a
pause
if "%drive%"=="" goto :dacaudit
pause
net use %Drive% /del
pause
net use %Drive% \\dptdata\counterfraud$ /persistent:Yes
pause

:dacaudit
for /F "tokens=2" %%a in ('net use ^| find /i "\\data2\dacaudit$"') do
set drive=%%a
pause
if "%drive%"=="" goto :eof
pause
net use %Drive% /del
pause
net use %Drive% \\dptdata\dacaudit$ /persistent:Yes
pause

Thanks for the feedback. There is no need to do it 130 times -
let the batch file handle it!

@echo off
for /F %%a in ('type c:\Shares.txt') do call :Sub %%a
goto :eof

:Sub
for /F "tokens=2" %%a in ('net use ^| find /i "\\data2\%1"') do set
drive=%%a
pause
if "%drive%"=="" goto :eof
pause
net use %Drive% /del
pause
net use %Drive% \\dptdata\%1 /persistent:Yes
pause
 
Thanks for the feedback. There is no need to do it 130 times -
let thebatchfilehandle it!

@echo off
for /F %%a in ('type c:\Shares.txt') do call :Sub %%a
goto :eof

:Sub
for /F "tokens=2" %%a in ('net use ^| find /i "\\data2\%1"') do set
drive=%%a
pause
if "%drive%"=="" goto :eof
pause
net use %Drive% /del
pause
net use %Drive% \\dptdata\%1 /persistent:Yes
pause- Hide quoted text -

- Show quoted text -

Exceptional Job, thanks, if OK made a couple of changes, but is
working really well
@echo off
REM ***Create search criteria within the text file****
for /F %%a in ('type d:\dptshares.txt') do call :Sub %%a goto :eof


REM ****Create a sub routine which searches for exisitng \\data2
shares****
REM ****then remembers the drive letter and deletes the drive*****
REM ****Then creates the same share on the new DPTdata server****
REM ****Thanks to Pegasus and Andy Gates***********
:Sub
for /F "tokens=2" %%a in ('net use ^| find /i "\\data2\%1"') do set
drive=%%a
if "%drive%"=="" goto :eof
net use %Drive% /del
net use %Drive% \\dptdata\%1$ /persistent:Yes
set drive=

Awesome job thanks
 
Exceptional Job, thanks, if OK made a couple of changes, but is
working really well
@echo off
REM ***Create search criteria within the text file****
for /F %%a in ('type d:\dptshares.txt') do call :Sub %%a goto :eof


REM ****Create a sub routine which searches for exisitng \\data2
shares****
REM ****then remembers the drive letter and deletes the drive*****
REM ****Then creates the same share on the new DPTdata server****
REM ****Thanks to Pegasus and Andy Gates***********
:Sub
for /F "tokens=2" %%a in ('net use ^| find /i "\\data2\%1"') do set
drive=%%a
if "%drive%"=="" goto :eof
net use %Drive% /del
net use %Drive% \\dptdata\%1$ /persistent:Yes
set drive=

Awesome job thanks

Seeing that the scope of your task has changed considerably
since your first post, a generic solution would look like so.
It checks if there are any connections to the old server
and replaces them with connections to the new server. This
would make the process much faster.

@echo off
rem Check all existing connections for the old server name
for /F "tokens=2,3" %%a in ('net use ^| find /i "\\data2"') do call :Sub %%a
%%b
goto :eof

:sub
rem Replace connections to the old server
set old=%*
set new=%old:data2=dptdata%
echo net use %old% /del
echo net use %new% /persistent:yes
 
Seeing that the scope of your task has changed considerably
since your first post, a generic solution would look like so.
It checks if there are any connections to the old server
and replaces them with connections to the new server. This
would make the process much faster.

@echo off
rem Check all existing connections for the old server name
for /F "tokens=2,3" %%a in ('net use ^| find /i "\\data2"') do call :Sub %%a
%%b
goto :eof

:sub
rem Replace connections to the old server
set old=%*
set new=%old:data2=dptdata%
echo net use %old% /del
echo net use %new% /persistent:yes- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -

Seemed a lot quicker but unfortunatley did not map new server shares,
they remained as they were, although it takes a little while to run,
can live with the other one, thanks very much, and have learned a
terrific amount from this. nice job
 
Back
Top