Solved

Mapping Network Drive by code

Posted on 2004-08-25
6
285 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
[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
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Make the most of your online learning experience.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

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