Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. problem with WNetAddConnection2 and WNetCancelConnection2!!

problem with WNetAddConnection2 and WNetCancelConnection2!!

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminhelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    venadder
    wrote on last edited by
    #1

    Hi, I thought this was solved but there happens to be so mnay ways in which these two functions can fail Here is the scenerio. I need to connect to the server to find out if winzip command line utilities are installed or not. I use brute force method of connecting to the server running a dummy command using CreateProcess to run the command like c:\progra~1\winzip\wzzip.exe file.zip file.txt (assume file.txt exist). It turns out to be faster than checking for presence of exes and dependencies. It works like charm most of the times accept for one scenerio. This deals with connection problems rather than createprocess etc. I can do that only if I have valid access to drive c: on server to run the wzzip.exe. So, I use WNetAddConnection2 to connect to the \\servername\c$ with proper administrative rights ( administrative usernames and password to the server, server is on LAN). After completing processing I dc using WNetCancelConnection2 . The problem is if i go to winexplorer type in \\servername\c$, it prompts me for username and password. I enter the info and do what i do on c: of server and close the explorer. Now somehow windows remeber this connection and even a call to WNetCancelConnection2 fails to delete it. So when i call WNetAddConnection2 it returns the erro saying the credentials provided conflict with existing crediantls. But if i restart the computer and then run the app it conencts fine and do what it is suposed to do. Is there a way I can make windows forget the connection (it's not even mapped ). WNetCancelConnection2 is supposed to delete all non persistent conenctions liekt his, but It does not seem to be doing so. Does anyone has an idea what's going on here??? Thankyou in advance P.S. :can provide sample code, thought should explain teh scenerio first.

    H 1 Reply Last reply
    0
    • V venadder

      Hi, I thought this was solved but there happens to be so mnay ways in which these two functions can fail Here is the scenerio. I need to connect to the server to find out if winzip command line utilities are installed or not. I use brute force method of connecting to the server running a dummy command using CreateProcess to run the command like c:\progra~1\winzip\wzzip.exe file.zip file.txt (assume file.txt exist). It turns out to be faster than checking for presence of exes and dependencies. It works like charm most of the times accept for one scenerio. This deals with connection problems rather than createprocess etc. I can do that only if I have valid access to drive c: on server to run the wzzip.exe. So, I use WNetAddConnection2 to connect to the \\servername\c$ with proper administrative rights ( administrative usernames and password to the server, server is on LAN). After completing processing I dc using WNetCancelConnection2 . The problem is if i go to winexplorer type in \\servername\c$, it prompts me for username and password. I enter the info and do what i do on c: of server and close the explorer. Now somehow windows remeber this connection and even a call to WNetCancelConnection2 fails to delete it. So when i call WNetAddConnection2 it returns the erro saying the credentials provided conflict with existing crediantls. But if i restart the computer and then run the app it conencts fine and do what it is suposed to do. Is there a way I can make windows forget the connection (it's not even mapped ). WNetCancelConnection2 is supposed to delete all non persistent conenctions liekt his, but It does not seem to be doing so. Does anyone has an idea what's going on here??? Thankyou in advance P.S. :can provide sample code, thought should explain teh scenerio first.

      H Offline
      H Offline
      hillclymr
      wrote on last edited by
      #2

      A clip from an older project. Deletes all connections. Modify to suite your needs. Hope this helps. /+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- // DeleteAllConnections() // Purpose: Delete all network connections // Added : 4/06/04 //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- void TestDlg::DeleteAllConnections() { DWORD dwResult; HANDLE hEnum; DWORD cbBuffer = 16384; DWORD cEntries = 0xFFFFFFFF; LPNETRESOURCE lpnrDrv; #if _DEBUG return; #endif dwResult = WNetOpenEnum( RESOURCE_CONNECTED, RESOURCETYPE_ANY,0,NULL,&hEnum ); if (dwResult != NO_ERROR) { GetErrorMsg(dwResult); return; } // start enumerating all the connections while( dwResult != ERROR_NO_MORE_ITEMS ) { lpnrDrv = (LPNETRESOURCE) GlobalAlloc( GPTR, cbBuffer ); dwResult = WNetEnumResource( hEnum, &cEntries, lpnrDrv, &cbBuffer); if (dwResult == NO_ERROR) { for( DWORD ii = 0; ii < cEntries; ii++ ) { if( lpnrDrv[ii].lpLocalName != NULL ) dwResult=WNetCancelConnection(lpnrDrv[ii].lpLocalName, TRUE ); else dwResult=WNetCancelConnection(lpnrDrv[ii].lpRemoteName,TRUE ); GetErrorMsg(dwResult); } } } // cleanup GlobalFree( (HGLOBAL) lpnrDrv ); WNetCloseEnum(hEnum); } Erik

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups