Reputation: 13
I am trying to remove a mapped network drive and add it back again. Users who have problems with their mapped drives, can use this script to fix their not working network-drive so I dont have to do it by hand. Also, I am flushing the DNS since it could be the source of the issue the user has.
I am not that good at batch and don't understand, why my script ain't working. Hope someone can help here.
In response to @Gerhard: I make it this "complicated" since windows sometimes stops deleting mapped drives since it runs background tasks on it. And to make sure, the Drive gets deleted, I made this loop.
@echo off
::flushing DNS may also help with some problems a user might have
ipconfig /flushdns
::while the X drive exists, it the script tries to delete it till it succeeds.
:while
IF exist "X:\*" (
net use X: /delete
if exist "X:\*"(
goto :while
)
) ELSE (
if not exist "X:\*" (
net use X: \\<Domain> /persistent:yes
)
)
Upvotes: 0
Views: 2508
Reputation:
Your else
statement is not correct. The parentheses needs ro be on the same line as else
. As in ) else (
.
You also do not need to parenthesize each if
statement either. You needed a space between \(
in the statement if exist X:\(
and lastly, you do not need to check if not exist
as your else
statement already confirmed it does not:
@echo off
ipconfig /flushdns
:while
if exist X:\* (
net use X: /delete
if exist X:\* goto :while
) else (
net use X: \\<domain> /persistent:yes
)
Upvotes: 0