Solved

Mapping Network Drive by code

Posted on 2004-08-25
6
280 Views
Last Modified: 2010-04-17
Hello everybody,
We are wanting to create a .cmd or .bat file that will map to a certian drive on our network, copy some files over, then disconnect from that network drive.

Can this be done.  We know how to do the copying part, just need help with the Mapping parts.

We are using Windows NT 4.0 and Windows XP Pro

Thanks
0
Comment
Question by:awehme
6 Comments
 
LVL 7

Accepted Solution

by:
LRHGuy earned 300 total points
ID: 11892976
Did you try:

Net Use T: \\servername\sharename

to connect and

Net Use T: /DELETE

to disconnect?

"T:" is the drive you use for the copy.
0
 
LVL 22

Assisted Solution

by:cookre
cookre earned 200 total points
ID: 11892984
You can easily do that with 'net use' :

NET USE
[devicename | *] [\\computername\sharename[\volume] [password | *]]
        [/USER:[domainname\]username]
        [/USER:[dotted domain name\]username]
        [/USER:[username@dotted domain name]
        [/SMARTCARD]
        [/SAVECRED]
        [[/DELETE] | [/PERSISTENT:{YES | NO}]]

NET USE {devicename | *} [password | *] /HOME

NET USE [/PERSISTENT:{YES | NO}]
0
 
LVL 22

Expert Comment

by:cookre
ID: 11893090
If you don't have a drive letter that will be available on every box you run it on, you'll have to use *, then do another net use to redirect the list of mappings to a text file you then parse in a for loop to find the assigned letter.

I've got the code for that on another box somewhere - lets see if I can find it...
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 22

Expert Comment

by:cookre
ID: 11895498
Found it.
This will leave the mapped to drive letter in DriveLetter


set /a LoopCnt= 0
set /a TryCnt= 10
:Mappit

                   *** the following is all one line ***
for /f "tokens=1-8 delims=. " %%a in ('net use * \\SERVERNAME\SHARENAME %Passwd% /user:USERNAME ^| find /I "connected"') do set DriveLetter=%%b
                   *** the above is all one line ***

if exist %lib1%\ goto GotIt
set /a LoopCnt= 1 + %LoopCnt%
if %LoopCnt% GTE %TryCnt% goto BadMapping
goto Mapppit

0
 

Expert Comment

by:zowyy
ID: 11899696
On my Windows 2000 network at home, the following worked well without requiring a drive mapping:

STEP 1: Establish a resource connection on the remote computer with

  NET USE \\<server>\IPC$

NOTE: this will attempt to log onto the remote computer with whatever user name and password you used to log onto the computer where the .bat file is running.  If you need to register with the remote computer under a different name, use

    NET USE \\<server>\IPC$ /USER:<UserName>

If you need to supply a password, you will be prompted for one by the DOS command line interface.

NOTE: you may need to include a domain as in "google\awehme" (without the quotes, of course) instead of just a user name.

STEP 2: You can then use a command with a direct path using a "\\<server>\<share>" syntax where <server> can be either an IP (such as 192.168.1.2) or the server's text-based name.

I did this successfully on my network using the following commands:

DIR \\192.168.1.3\C$

COPY \\192.168.1.3\C$\CRASH.TXT C:\TEMP\CRASH.TXT

This approach saves the trouble of mapping and unmapping since the IPC$ resource can remain connected indefinitely (it will drop out when you reboot).  You can also use it to connect to multiple network shares and move files between them without tying up drive letters--preventing possible conflicts if the drive letter is already in use.

In fact, if your user account and password are the same on both the computer running the .bat file and the network server(s), you might try it without the NET USE \\<server>\IPC$ command.  I just used IPC$ because my user names were different on the two computers.
0
 
LVL 2

Author Comment

by:awehme
ID: 11909693
Thanks guys.....I'm a newbie as you tell.

Answer from LRHGuy is all I neeeded, but cookre's answer will come in handy down the road.

Thanks
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

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

11 Experts available now in Live!

Get 1:1 Help Now