I didn't know if I should start this topic under "Programming" but it seems to be the only place to put it.
I want to run a batch file that will automatically map a network drive before it continues the script. The problem I have is that if for some reason the drive is already mapped, or the batch file has been run twice in one session, the "net use" command returns an error. The script still works in the end, but I would like to bypass the "net use" command altogether if the drive is already mapped.
I've been digging through the net trying to find anything that can help me out, but to no avail. The closest thing I can find is just typing "net use" can tell you if the drive is already mapped or not, but I can't take any one piece of that result and use it in my script.
Does anyone have any suggestions? My purpose here is to write an IF statement that determines:
IF drive X: is already mapped, then skip net use command and proceed with the remainder of the script.
ELSE, run net use command and proceed with the remainder of the script.
I figured ERRORLEVEL could come in handy, but that only works after I get the error that I'm trying to avoid in the first place.
Samsung Galaxy Watch8 is now selling at its lowest price ever by Fiza Ali
Amazon is now offering Samsung Galaxy Watch8 at its lowest price yet with a 34% discount (purchase link down below). The Galaxy Watch8 is equipped with a 1.5-inch Super AMOLED display with a resolution of 480x480 pixels and support for 16 million colours.
The watch is powered by a penta-core processor with clock speeds of up to 1.6GHz, runs Wear OS, and includes 2GB of RAM and 32GB of internal storage. For connectivity, the watch supports Bluetooth 5.3, Wi-Fi 802.11a/b/g/n on both 2.4GHz and 5GHz bands, and NFC. Furthermore, supported Bluetooth profiles include A2DP, AVRCP, HFP, and HSP. Location services are provided through GPS, GLONASS, BeiDou, and Galileo satellite systems.
Moreover, the Galaxy Watch8 includes a range of sensors as well, including an accelerometer, barometer, bioelectrical impedance analysis (BIA) sensor, electrical heart sensor (ECG), optical heart rate sensor, gyroscope, geomagnetic sensor, infrared temperature sensor, and ambient light sensor.
For media playback, the watch supports MP3, M4A, 3GA, AAC, OGG, OGA, WAV, AMR, and AWB audio formats. In terms of water resistance, it has a 5 ATM rating, which should make it suitable for swimming and everyday exposure to water. Finally, the device is powered by a 435mAh lithium-ion battery, and when it comes to its performance, Samsung rates the battery for up to 40 hours of use with the Always-On Display turned off.
Samsung Galaxy Watch 8 (2025) 44mm Smartwatch: $249.99 (Amazon US) - 34% off
Good to know
This Amazon deal is U.S. specific, and not available in other regions unless specified.
We only use first-party seller links (at the time of article publishing); ensure that you purchase from a first-party seller link only.
Check out Today's Deals on Amazon | or our recent tech deals.
Become a Prime member (for Students or SNAP) via Neowin
Get Prime Access - Prime for half price (for qualifying Medicaid, EBT, SNAP)
Subscribe to Prime Video, Audible Plus, Music Unlimited or Kindle Unlimited via Neowin
As an Amazon Associate, we earn from qualifying purchases.
Question
Xtreme $niper
I didn't know if I should start this topic under "Programming" but it seems to be the only place to put it.
I want to run a batch file that will automatically map a network drive before it continues the script. The problem I have is that if for some reason the drive is already mapped, or the batch file has been run twice in one session, the "net use" command returns an error. The script still works in the end, but I would like to bypass the "net use" command altogether if the drive is already mapped.
I've been digging through the net trying to find anything that can help me out, but to no avail. The closest thing I can find is just typing "net use" can tell you if the drive is already mapped or not, but I can't take any one piece of that result and use it in my script.
Does anyone have any suggestions? My purpose here is to write an IF statement that determines:
IF drive X: is already mapped, then skip net use command and proceed with the remainder of the script.
ELSE, run net use command and proceed with the remainder of the script.
I figured ERRORLEVEL could come in handy, but that only works after I get the error that I'm trying to avoid in the first place.
Thanks!
Link to comment
https://www.neowin.net/forum/topic/616815-ms-dos-batch-automatically-determine-if-drive-is-already-mapped/Share on other sites
19 answers to this question
Recommended Posts