DirExist with UNC

Started by billmeek, November 02, 2015, 11:00:40 PM

Previous topic - Next topic

billmeek


Hi all,

This is my first post after a *long* break from Winbatch (read that as many years).  I just re-bought the WinBatch+Compiler today and have started digging into the changes from my very old version.  So on something that I thought would be rather simple to get me started again, I've ran into a small issue.  Although the help file says that DirExist works on UNC paths, it returns an error even when the path exists.

For testing I've simplified the code to:

cdata = "\\DEFIANT8\data2\Video"
cdataerr = DirExist(cdata)

The value of cdata is a direct cut and past from Windows Explorer.  DirExist always returns 1 (@true) despite testing with UAC off and trying the different Studio types (WBStudio_IF, WBStudio_IT, etc.)

However if I map the same path to Z, this code returns zero:

cdata = "z:"
cdataerr = DirExist(cdata)

So either it's an issue with UNC with DirExist, a(nother) Windows 10 issue, or I'm up too late trying to code.

Thanks in advance for any help to this oldbie becoming a newbie,

-
Bill

td

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

billmeek

Correct me if I'm wrong, but my understanding is that UNC paths use the same security context and identity as the restricted token.  Even if my program is running elevated, it should be able to access the UNC path.


So the security context should not be an issue when using UNC paths with DirExist... which is the only place I'm having an issue.  DirExist works with mapped drives.
-
Bill

td

We need to get the story straight.  You stated intermediately after the code fragment showing the use of a UNC path  that  'DirExist always returns 1 (@true)'.  If this is actually the case then you DirExist is detecting the shares existence using your Explorer UNC path.  You also state that 'if I map the same path to Z, this code returns zero'.  Which indicates that the path does not exist or is invalid and DirExist is not detecting the mapped drive. The latter is common on UAC enabled systems because drives are often mapped as a restricted admin using Explorer or a command prompt but the script is attempting to access the drive as an elevated admin.

So is your first or second post correct?

Also, the security token used when accessing a share depends on configurable settings on both the client and server side.  It is, therefore, possible for an elevated process to be unable to access a share available to a restricted process or visa versa.

Finally,  per as usual DirExist has been faithfully tested with UNC paths on Windows XP, Vista, 7, 8, 8.1 and 10 and it works just fine, assuming the process running the script has the correct permissions.   
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

billmeek

Good catch.  From my first post the correct answer was "I'm up too late trying to code".  Last night I got the 2 test results backwards in my mind.  Normally I have enough sense to catch these little slip-ups on my own.

DirExist works correctly with UNC.  My brain sometimes doesn't (work correctly).

Thanks,
-
Bill

td

These things happen.  As any of this forum's regulars will tell you, I have been known to get my yang and yin backwards  a few times.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade