title: Windows service cannot access shared folder at boot time until manually started or Windows Explorer fiddled
body: <p>I have a Windows service running in local system that simply keeps trying to access a file with a UNC path of the form \\machine\folder\file.txt until it succeeds. It succeeds immediately when I start the service manually, but on reboot it gets System Error 53 (Network Path not found) until I do something such as logoff or "fiddle" with <a href="http://en.wikipedia.org/wiki/Windows_Explorer" rel="nofollow noreferrer">Windows Explorer</a> such as double-clicking an unrelated text file (weird, I know). But there is no reliable trick; I am not sure what triggers it to suddenly be able to see the shared folder.</p>
  
  <p>However, I chanced upon an apparently reliable "solution," which is to attempt a CreateProcess on "net use I: \\machine\folder" from within the service to map the shared folder before attempting to access it (I continue using the UNC path, not I:). The <code>net use</code> call appears to immediately trigger my ability to access the shared folder from the service despite the fact that the <code>net use</code> call itself probably fails (I haven't checked because you're not even supposed to be able to map drives from a service). </p>
  
  <p>This sounds similar to <a href="https://stackoverflow.com/questions/687489/database-connection-doesnt-work-when-service-starts-at-boot-but-works-when-its">database connection doesn’t work when service starts at boot but works when it’s manually started</a> but in my case it is a network shared folder, plus I know it can also suddenly just start working under the circumstances described above.</p>
  
  <p>I don't think this is a permissions issue because it demonstrates full access capabilities on the shared folder when it succeeds in gaining access. But I would like to know the reason so I can handle it properly.</p>