Solved

delete a specific network mapped drive with a bat file.

Posted on 2009-05-13
8
583 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
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
A small collection of useful tips and tricks for Windows 10 users that I decided to write as a result of recent questions that were asked and answered at Experts Exchange. Two short video tutorials included. Enjoy..
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

691 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