Solved

Open a remote disk drive

Posted on 2007-11-19
7
1,500 Views
Last Modified: 2013-11-20
I want to access a disk drive of a remote computer. is there any way i can do it? I am developing in VS2003 using VC++.  The function  CreateFile() can  open the disk drive of the local machine. I am not sure if the same function works for the remote disk drives too. Is there any function in VC++ that can do the same for the remote disk drives?
0
Comment
Question by:tariq6000
7 Comments
 
LVL 4

Accepted Solution

by:
yuy2002 earned 50 total points
ID: 20318058
Is the remote computer in the same lan network?If so , you can use disk map.
You can map the disk drive of remote computer to you local machine disk just as you have privilage to access the remote computer's disk.Then you could do evething on remote disk like the local disk.  
0
 
LVL 40

Assisted Solution

by:evilrix
evilrix earned 150 total points
ID: 20318273
Can't you just mount it as a network drive or access it via UNC path?
\\<servername>\<sharename>\<directory>
0
 

Author Comment

by:tariq6000
ID: 20318417
Yes, the remote disk is in the same LAN. But, I don't know how to map the remote disk on to the local machine. Can you please provide me a link to the sample code snippet illustrating on how it can be done?
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 40

Assisted Solution

by:evilrix
evilrix earned 150 total points
ID: 20318455
Use the UNC path...

HANDLE CreateFile(
   "\\remotepc\sharename\myfile.txt",
   ... OTHER OPTIONS
);

...or mount it as a network drive and use it as if it was local: -

http://www.cs.umd.edu/faq/pc/map_network_drive/map_network_drive.html

0
 
LVL 40

Assisted Solution

by:evilrix
evilrix earned 150 total points
ID: 20318461
Oops... I forgot the double slash for C-String...

CreateFile(
    "\\\\remotepc\\sharename\\myfile.txt",
    ... OTHER OPTIONS
);
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 50 total points
ID: 20320159
>>I don't know how to map the remote disk on to the local machine

That is done using 'WNetAddConnection2()', e.g.

#include <winnetwk.h>

    NETRESOURCE nr;

    ZeroMemory  (   &nr,    sizeof  (   NETRESOURCE));

    nr.dwType           =   RESOURCETYPE_DISK;
    nr.lpLocalName      =   "x:";
    nr.lpRemoteName     =   "\\\\theserver\\E$";

    //  authenticate server share using the remote user info
    dwRes   =   WNetAddConnection2  (   &nr,
                                       "SecretPassword",
                                       "UserName",
                                       0
                                   );

The above would map the drive as 'x:' (link with 'mpr.lib')
0
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 50 total points
ID: 20321822
You only can have access to a remote disk if there is a shared folder where you have access to.

Then you can map a free drive letter from the commandline by

  net use Z: \\server\share

If you don't have access either to 'server' or 'server\share' you'll get an appropriate error message. To see what driver letters are available you can type

   net use

and
 
  subst

These commands will show the dynamically defined drive letters either defined by 'net use' command or by 'subst' command. You have to add the local disk drive letters to get a full list.

Note, with 'net use' you only can map remote (folders of a) share using the UNC name.  With 'subst' you can map drive letters to any path using a local drive letter but not UNC paths. Also paths using driver letters defined with 'net use' can be used:

    net use K: \\my_server\my_share
    subst L: K:\any_path\any_folder

You can do all that programmatically by using the system function:

#include <process.h>

        int ret;
        if ((ret = system("net use K: \\\\my_server\\my_share")) != 0)
        {
               // error:  ret == 2 if path doesn't exist
        }

        if ((ret = system("subst L: K:\\any_path")) != 0)
        {
               // error:  ret == 2 if path doesn't exist
        }

The subst normally doesn't give an error when using an UNC name at the right side. But it will not work as a valid drive letter doing so.

You can check whether the 'subst' was successful by using the stat function:

#include <sys/stat.h>
#include <errno.h>

        ...
        if ((ret = system("subst L: K:\\any_path")) != 0)
        {
               // error:  ret == 2 if path doesn't exist
        }
         struct stat fs;
         if (stat("L:\\any_file_or_folder", &fs) != 0)
         {
               // errno will show the error code
         }  

Regards, Alex







0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In this article we have discussed the manual scenarios to recover data from Windows 10 through some backup and recovery tools which are offered by it.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

919 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

20 Experts available now in Live!

Get 1:1 Help Now