Solved

delete a specific network mapped drive with a bat file.

Posted on 2009-05-13
8
578 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
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 7

Expert Comment

by:sfarazmand
ID: 24377987
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
 

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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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 125 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

Are end users causing IT problems again?

You’ve taken the time to design and update all your end user’s email signatures, only to find out they’re messing up the HTML, changing the font and ruining the imagery. What can you do to prevent this? Find out how you can save your signatures from end users today.

Join & Write a Comment

Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now