CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 1999
    Location
    Cincinnati, Ohio
    Posts
    195

    how to use map a network drive?

    Does anyone know how to programmatically map a network drive? It looks like one would use the function NetUseAdd(), but it is not working. This is what I tried:


    int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
    {
    int nRetCode = 0;
    USE_INFO_1 ui1;
    DWORD dwParmError;

    // initialize MFC and print and error on failure
    if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
    {
    // TODO: change error code to suit your needs
    cerr << _T("Fatal Error: MFC initialization failed") << endl;
    nRetCode = 1;
    }
    else
    {
    ui1.ui1_local = _T("E:");
    ui1.ui1_remote = _T("\\\\FPGHEB001NWR\\SHARED");

    ui1.ui1_password = NULL;
    ui1.ui1_asg_type = USE_DISKDEV;

    ::NetUseAdd( NULL, 1, (UCHAR*) &ui1, &dwParmError);
    }

    return nRetCode;
    }





  2. #2
    igbrus is offline Elite Member Power Poster
    Join Date
    Aug 2000
    Location
    Los Angeles
    Posts
    4,658

    Re: how to use map a network drive?

    See WNetAddConnection2

    Rating isn't important...But gurus respect it and keep high

  3. #3
    Join Date
    May 2002
    Location
    U.S.A
    Posts
    88
    #include <windows.h>
    #include <Winnetwk.h>
    #include <iostream>
    using namespace std;
    void main ( void )
    {
    NETRESOURCE nr;
    DWORD res;
    TCHAR szLocalName[32] = "Q:";
    TCHAR szRemoteName[MAX_PATH] = "\\\\micrle\\c$";
    nr.dwType = RESOURCETYPE_ANY;
    nr.lpLocalName = szLocalName;
    nr.lpRemoteName = szRemoteName;
    nr.lpProvider = NULL;
    res = WNetAddConnection2(&nr, NULL, NULL, FALSE);

    res = WNetCancelConnection2("Q:", CONNECT_UPDATE_PROFILE, TRUE);
    return;
    }
    Thanks,

    Todd

  4. #4
    Join Date
    Apr 2004
    Location
    India
    Posts
    10

    !!!Urgent!!! doubt on lpRemoteName of NETRESOUCE

    Hi
    #include <windows.h>
    #include <Winnetwk.h>
    #include <iostream>
    using namespace std;
    void main ( void )
    {
    NETRESOURCE nr;
    DWORD res;
    TCHAR szLocalName[32] = "Q:";
    TCHAR szRemoteName[MAX_PATH] = "\\\\micrle\\c$";//doubt
    nr.dwType = RESOURCETYPE_ANY;
    nr.lpLocalName = szLocalName;
    nr.lpRemoteName = szRemoteName;
    nr.lpProvider = NULL;
    res = WNetAddConnection2(&nr, NULL, NULL, FALSE);

    res = WNetCancelConnection2("Q:", CONNECT_UPDATE_PROFILE, TRUE);
    return;
    }

    I have a doubt in this code listing what if we dont know the (path "\\\\micrle\\c$") path and if i only know the URL.

    For example if i want to map all the shared folders of say microsoft server i.e i have got only url:ftp://ftp.microsoft.com So, how can i pass the value for parameter szRemoteName.

    Thank U...

  5. #5
    igbrus is offline Elite Member Power Poster
    Join Date
    Aug 2000
    Location
    Los Angeles
    Posts
    4,658
    In this case you should enumerate all shared folders and map them one by one. BTW I don't think you will succeed with ftp server

  6. #6
    Join Date
    Apr 2004
    Location
    India
    Posts
    10

    Can we use CFtpConnection for drive mapping???

    Hi,


    Can we use CFtpConnection for connecting to an FTP server and is it possible to do drive mapping with this connection?


    Thank U.

  7. #7
    igbrus is offline Elite Member Power Poster
    Join Date
    Aug 2000
    Location
    Los Angeles
    Posts
    4,658
    1. Yes
    2. No

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured