Solved

Open a remote disk drive

Posted on 2007-11-19
7
1,513 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
[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
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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

710 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