把 netres.lpRemoteName =argv[0];  改为 netres.lpRemoteName =*argv[0];  试试,我也没试过.

解决方案 »

  1.   

    C:\>yourprogram.exe \\192.168.0.1\ipc$ passwd username
        argv[0]                argv[1]     argv[2] argv[3] argv[0] 是 "C:\>yourgrogram.exe"
      

  2.   

    如果是这样
     C:\>yourprogram.exe \\192.168.0.1\ipc$ passwd username
     
    改成netres.lpRemoteName =argv[1];这样
      

  3.   

    DWORD dwRetCode = WNetAddConnection2(&netres, argv[1], argv[2], 0);改成 DWORD dwRetCode = WNetAddConnection2(&netres, argv[2], argv[3], 0);
      

  4.   

    #include <stdio.h>
    #include <windows.h>
    #include <Winnetwk.h>
    VOID main(int argc, char **argv)
    {
        NETRESOURCE netres;
        netres.dwScope = RESOURCE_GLOBALNET;
        netres.dwType = RESOURCETYPE_ANY;
        netres.dwDisplayType = RESOURCEDISPLAYTYPE_GENERIC;
        netres.dwUsage = RESOURCEUSAGE_CONNECTABLE;
        netres.lpLocalName = NULL;
        netres.lpRemoteName =argv[1];  
        netres.lpProvider = NULL;
        netres.lpComment = NULL;    DWORD dwRetCode = WNetAddConnection2(&netres, argv[2], argv[3], 0);
    }// Windows xp/Visual studio.net/Platform Nov 2001
    // 成功
      

  5.   

    C:\>temp.exe \\192.168.0.15\ipc$ user user
    ========================================================
    New connections will be remembered.
    Status       Local     Remote                    Network-------------------------------------------------------------------------------
    OK                     \\192.168.0.15\ipc$         Microsoft Windows Network
    The command completed successfully.
      

  6.   

    有没有 Link 这个库? Mpr.lib如果没有在 #include 语句后面加#pragma comment(lib,"mpr.lib")注意后面没有分号
      

  7.   

    差不多了,可是在最后的空白处出现了"unexpected end of file while looking for precompiled header directive"