Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

delete a specific network mapped drive with a bat file.

Posted on 2009-05-13
8
Medium Priority
?
585 Views
Last Modified: 2012-05-06
I have a mapped drive M:\\xxx\xxx which needs to be deleted from all users on the network however, i have the M drive letter mapped to a different share on 2 different machines that I don't want deleted. Is there a way to have the bat files delete a specific mapping without upsetting the good mapping?

I want to lose m:\macfiles\macshare but not M:\\hciwhseprt\commondata (this is only specific on 4 machine and needs to stay because it's hard coded in a file.

I'm using this in a bat file in a domain login script via group policy
0
Comment
Question by:tbonehwd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 7

Expert Comment

by:spamster
ID: 24377982
M: is mapped to \\macfiles\macshare?
Then find a file that's in the the macshare directory (but it can't be in the commondata folder), for example - file.txt - and put this in the logon script

IF EXIST M:\file.txt (
net use m: /d
)
0
 
LVL 4

Expert Comment

by:delyan_valchev
ID: 24378008
Try something like. Findstr returns errorlevel 0 if string is found and 1 if not.
Hope it helps!
net use | findstr macfiles
if ERRORLEVEL 0 net use m: /d

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:tbonehwd
ID: 24378028
M is mapped to \\macfiles\macshare and doesn't exist anymore.  I have replaced the map with an X to the new server name and share.  M: should be mapped to a different server on 3 different machines only.  
0
 

Author Comment

by:tbonehwd
ID: 24378051
net use [DRIVE]: \\[PATH]\ /DELETE  I tried this but it still deleted the drive.  I dont' want to use VB I'm trying to keep is a simple bat file

My statement was net use M: \\macfiles\macshare /delete
0
 
LVL 1

Expert Comment

by:alayanna
ID: 24378056
Create a kix script:
$KEY = "HKEY_CURRENT_USER\Network\m"
$VALUE = "RemotePath"
$FIND = "\\hciwhseprt\commondata"

$Data = ReadValue($KEY,$VALUE)
      For Each $Item In Split($Data,",")
            If NOT $Item = $FIND
                  SHELL 'BAT FILE'
            EndIf
      Next
Quit
0
 
LVL 4

Accepted Solution

by:
delyan_valchev earned 500 total points
ID: 24378185
You can reverse the findstr logic to search for the "good" shares and if they exist do nothing, otherwise delete the M: mapping.
BTW. the syntax to delete the M: drive should be:
net use m: /d
without the path.
net use | findstr hciwhseprt
if errorlevel 1 net use m: \\hciwhseprt\commondata

Open in new window

0
 

Author Closing Comment

by:tbonehwd
ID: 31581135
this was the only one that worked!  Thanks.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An introduction to the wonderful sport of Scam Baiting.  Learn how to help fight scammers by beating them at their own game. This great pass time helps the world, while providing an endless source of entertainment. Enjoy!
Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question