Solved

Open a remote disk drive

Posted on 2007-11-19
7
1,488 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

As hardware bugs go, this is a strange one! I upgraded a laptop in December 2011 with a 512GB Crucial m4 2.5-inch/9.5mm SATA Solid State Drive (SSD), Crucial part number CT512M4SSD2: http://www.crucial.com/store/partspecs.aspx?IMODULE=CT512M4SSD2 …
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…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

707 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

18 Experts available now in Live!

Get 1:1 Help Now