?
Solved

delete a specific network mapped drive with a bat file.

Posted on 2009-05-13
8
Medium Priority
?
584 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
In this modest contribution, I want to share with the IT community (especially system administrators, IT Support Engineers and IT Help Desks) about Windows crashes/hangs and how to deal with these particular problems.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

770 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