Thursday, February 25, 2010

Access Network Shared Drive using Command Prompt

In order to access the network shared drive from command prompt using the UNC path \\ServerName\ShareName we first need to map the drive to a drive letter and then use that drive letter in the same session on the command prompt.

Creating a network shared drive in a drive letter and then trying to access it by using the command prompt would not work as both are done in different sessions.

The other thing to take care is a network shared drive may require authentication which is usually done under the hood if you are in a network. So sometimes you might have to provide explicit authentication information.

In order to map the drive with a credential and to a drive we use

net use \\ServerName\ShareName /user:domain\username password && pushd \\ServerName\ShareName

For example to map a share on the server \\10.15.16.88\CertConfig
net use \\10.15.16.88\CertConfig /user:mydomain\anton.alfred mypassword && pushd \\10.15.6.88\CertConfig

In case you are logged in with a domain account which has credentials to login to the share you could just do

pushd \\ServerName\ShareName
or
pushd \\10.15.16.88\CertConfig

After this command you should get a message saying "The command run successfully" and the command prompt should show the drive letter we are in namely
Z:\>

Once this is done we can clean up if required by issuing the following command

DriveLetter:\> popd && net use ServerName\ShareName /delete
or
Z:\>popd && net use \\10.15.16.88\CertConfig /delete

In case you have not mapped the drive using net use you could just do

DriveLetter:\> popd
or
Z:\>popd

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home