Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Open a remote disk drive

Posted on 2007-11-19
7
Medium Priority
?
1,519 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 150 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 450 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
LVL 40

Assisted Solution

by:evilrix
evilrix earned 450 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 450 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 150 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 150 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
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.

719 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