locked
GetFileAttributesEx() "The system cannot find the path" Error RRS feed

  • Question

  • When I call GetFileAttributesEx() at work for files on a Mapped Network Drive I get "The system cannot find the path" Error. But the file exists in windows explorer on my mapped network drive. I am running in an application exe not a service. When I run the exe at home for mapped network drives it works fine. At work I am running under a domain. Could security be the problem. An app.exe running as an administrator under my account on a domain should still have access to files on a network share if I can access those files in windows explorer right?
    • Moved by Jesse Jiang Thursday, August 16, 2012 3:12 AM (From:Visual C++ General)
    Wednesday, August 15, 2012 1:14 AM

Answers

  • Mapped drive are per session objects. Once you elevated to another session you will only see the mapped drive of the elevated session. You have to run your code in the normal integrity level to get the mapped drives created in the normal integrity level.

    You can either access the mapped resources via their UNC paths, or just change the code that demand elevation unnecessarily.



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP

    • Marked as answer by flagrantHippo Friday, August 17, 2012 3:35 AM
    Thursday, August 16, 2012 5:17 AM

All replies

  •  An app.exe running as an administrator under my account on a domain should still have access to files on a network share if I can access those files in windows explorer right?

    Not necessarily. If your system at home is a Windows XP OS, then you truly are the administrator. However, under Windows 7, even if you are logged in as an administrator, the operating system only gives you a standard user's SID. You explicitly have to elevate your credentials to administrator before running the app.exe in order to switch to the true administrator's SID.

    However, this may not be what you are experiencing. What is the value returned by GetLastError()? What are the security settings of the mapped network drive?

    Wednesday, August 15, 2012 3:05 AM
  • Not sure of the security setting of the mapped network drive. Just know that I can read and write to it from windows explorer.

    The app in question is old and writes to program files log file so to run it it needs to run as administrator. (I know this is bad this will be changed). However when run as Administrator the network shares cannot be accessed. When run as normal it can access the shares but can't write to it's log.

    Error Code 3 is returned from GetLastError(). Which FormatMessage() converts to The system cannot find the path.

    This must be some where domain setting where an admin cannot access a share.

    Both pcs the app is running from are windows 7.
    Wednesday, August 15, 2012 8:10 PM
  • Hi ,

    I think your issue should be raised in the Application Security for Windows Desktop. I believe they will know more information of this issue than us, and I will move this one to that forum.

    Thanks for your understanding,

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, August 16, 2012 3:11 AM
  • Mapped drive are per session objects. Once you elevated to another session you will only see the mapped drive of the elevated session. You have to run your code in the normal integrity level to get the mapped drives created in the normal integrity level.

    You can either access the mapped resources via their UNC paths, or just change the code that demand elevation unnecessarily.



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP

    • Marked as answer by flagrantHippo Friday, August 17, 2012 3:35 AM
    Thursday, August 16, 2012 5:17 AM
  • "Once you elevated to another session you will only see the mapped drive of the elevated session".

    So when I run as an Admin in a domain I elevate to another session? But at home when I run as an Admin (Non Domain) I don't elevate the session? (Cuz at home it worked fine)

    "You have to run your code in the normal integrity level to get the mapped drives created in the normal integrity level"

    How come when I run windows explorer as an admin it does not create the mapped drive in the raised integrity level? Is it possible to map a network drive in an elevated session?

    Thanks for your answers. I already changed the code so the log is NOT written to program files anymore. Just curious about this stuff. thx again.

    Friday, August 17, 2012 3:35 AM
  • The integrity level is per-session. If you log in as administrator, you start with a windows explorer process at normal integrity level. If you run a process as administrator outside of Explorer, it will normally be running at higher integrity level, and it cannot directly access your mapped drives in the integrity level.

    If you see the same set of mapped drives in two integrity levels, you are probably using this or this walkaround.



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP


    Friday, August 17, 2012 3:52 AM