Solved

delete a specific network mapped drive with a bat file.

Posted on 2009-05-13
8
582 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 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

732 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