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. WNetAddConnection2 fails with error code 1312

WNetAddConnection2 fails with error code 1312

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasesysadminhelpquestion
2 Posts 1 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.
  • A Offline
    A Offline
    alma
    wrote on last edited by
    #1

    Hi! I have a win2000 service written in visual c++ 6.0 that has to access files from a shared folder from the local network neighborhood. The shared folders are password protected, so I have to create a connection to that folder. I tried to use WNetAddConnection2. But WNetAddConnection2 fails and returns the error code no. 1312. I looked it up in the winapi headers, error 1312 is called ERROR_NO_SUCH_LOGON_SESSION, the explanation given is : 'A specified logon session does not exist. It may already have been terminated.'. The list of files/locations is taken from a database, so is dynamically changing over time. Has anybody any idea how could I access files shared on other computers without logging in to the system? Thanks, Alma

    A 1 Reply Last reply
    0
    • A alma

      Hi! I have a win2000 service written in visual c++ 6.0 that has to access files from a shared folder from the local network neighborhood. The shared folders are password protected, so I have to create a connection to that folder. I tried to use WNetAddConnection2. But WNetAddConnection2 fails and returns the error code no. 1312. I looked it up in the winapi headers, error 1312 is called ERROR_NO_SUCH_LOGON_SESSION, the explanation given is : 'A specified logon session does not exist. It may already have been terminated.'. The list of files/locations is taken from a database, so is dynamically changing over time. Has anybody any idea how could I access files shared on other computers without logging in to the system? Thanks, Alma

      A Offline
      A Offline
      alma
      wrote on last edited by
      #2

      The solution i found is to use the CreateService function with user and password parameters set. Ex: -------------------------------------------------------------------------------- CString user = _T(".\\User"); CString pswd = _T("pswd"); LPSTR u = user.GetBuffer(user.GetLength()+1); LPSTR p = pswd.GetBuffer(pswd.GetLength()+1); SC_HANDLE hService = ::CreateService( hSCM, m_szServiceName, m_szServiceName, SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, szFilePath, NULL, NULL, _T("RPCSS\0"), u, p); -------------------------------------------------------------------------------- To create the connection: -------------------------------------------------------------------------------- NETRESOURCE nr; char* a = new char[MAX_PATH]; memset(a, 0, MAX_PATH); char* b = new char[MAX_PATH]; memset(b, 0, MAX_PATH); strcpy(a, (char*)"\\\\alma\\geza"); strcpy(b,(char*)"x:"); char pswd[20] = "pswd"; char account[20] = "user"; nr.lpRemoteName = a; nr.lpLocalName = b; nr.lpProvider = NULL; nr.dwType = RESOURCETYPE_DISK; DWORD flags = CONNECT_UPDATE_PROFILE; DWORD res; res = WNetAddConnection2(&nr, (char*)pswd, (char*)account, flags); delete []a; delete []b; if (res == NO_ERROR) return TRUE; else return FALSE;

      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