Jump to content


Photo

FileCreate dir fails on network drive


  • Please log in to reply
14 replies to this topic

#1 fragman

fragman
  • Members
  • 1591 posts

Posted 13 January 2011 - 02:00 PM

I suspect this is a known issue, but I wanted to report it anyway:
I tried using FileCreateDir on a network drive, and it fails with Errorlevel 1. Autohotkey_L (Unicode, both 32 and 64 bit) is running with admin permissions and I can create a directory there using windows explorer.

#2 Eedis

Eedis
  • Members
  • 1591 posts

Posted 13 January 2011 - 03:39 PM

How are you writing out the directory? Are you using the host name or IP address?

\\192.168.1.1\Shared

\\Host_Name\Shared



#3 fragman

fragman
  • Members
  • 1591 posts

Posted 13 January 2011 - 05:42 PM

It's a mounted network drive, not a network share. In explorer it appears with a drive letter. I have received reports from users of my application and I was also able to observe this behavior myself.

#4 sinkfaze

sinkfaze
  • Moderators
  • 6081 posts

Posted 13 January 2011 - 06:06 PM

I suspect this is a known issue...


I believe you're right:

Revision 55 - August 19, 2010

. . .

Excludes FileCopyDir, FileRecycle, FileMoveDir, FileRemoveDir, FileRecycleEmpty, FileCreateDir and FileInstall as the APIs used do not consistently set or return a Win32 error code.



#5 fragman

fragman
  • Members
  • 1591 posts

Posted 13 January 2011 - 06:09 PM

I think that changelog entry only means that the return code is not set in a proper/correct way, it does not mention problems with network drives.

#6 sinkfaze

sinkfaze
  • Moderators
  • 6081 posts

Posted 13 January 2011 - 06:23 PM

You're right I misread that, but at the same time A_LastError will be of no use to try to troubleshoot the problem anyway. FWIW I attempted the same on a network drive and experienced the same failure.

#7 sinkfaze

sinkfaze
  • Moderators
  • 6081 posts

Posted 13 January 2011 - 06:40 PM

For some reason it works when I use DllCall, you might try it:

DllCall("CreateDirectoryW","Str","W:\this\directory\test")


#8 fragman

fragman
  • Members
  • 1591 posts

Posted 13 January 2011 - 09:31 PM

Thanks for the workaround, I will try it tomorrow.

#9 Lexikos

Lexikos
  • Administrators
  • 8835 posts

Posted 13 January 2011 - 10:07 PM

Works for me on Windows 7 and Windows XP SP3.

FYI, CreateDirectory has two parameters. Calling it directly only bypasses the check to see if the directory already exists and the recursive creation of parent directories. (CreateDirectory does not need to succeed for the parent directories, only for the final path.) FileCreateDir has the following failure points:
[*:26m65oec]DirName is empty.
[*:26m65oec]DirName already exists and does not have the "directory" attribute. FileExist(DirName) should not return "D" in that case.
[*:26m65oec]DirName is longer than MAX_PATH (260).
[*:26m65oec]CreateDirectory fails.

#10 sinkfaze

sinkfaze
  • Moderators
  • 6081 posts

Posted 13 January 2011 - 10:14 PM

FYI, CreateDirectory has two parameters.


Yeah I noticed that when I was reading on how to use the function but was unsure of how to use that parameter. Since it was optional in this case anyway and I knew what to expect as far as the check was concerned I just bypassed it.

#11 fragman

fragman
  • Members
  • 1591 posts

Posted 13 January 2011 - 10:42 PM

I don't think any of the failure points are being met, atleast it's nothing obvious. I will try if FileExist returns an invalid value.

#12 Lexikos

Lexikos
  • Administrators
  • 8835 posts

Posted 14 January 2011 - 12:12 AM

Since it was optional in this case anyway ...

You must pass a value for each parameter, otherwise it will use whatever garbage happens to be on the call stack. In this case, "optional" means you can pass a NULL (zero) value, which is exactly what FileCreateDir does.

#13 fragman

fragman
  • Members
  • 1591 posts

Posted 14 January 2011 - 09:34 AM

Calling CreateDirectory directly doesn't work for me either. It sets an error code 3, "ERROR_PATH_NOT_FOUND" "The system cannot find the path specified."

I also found this topic: <!-- m -->http://www.eggheadca... ... twork.aspx<!-- m -->

Edit: And this: <!-- m -->http://thedailyrevie... ... -102235068<!-- m -->

All topics seem to point to a permission issue.

Edit2: I just tried running it as non-admin and it worked. So it appears that it needs to be executed with the user account that is used to map the network drive. Can anyone think of a way to do this with a script running as admin?

#14 Rseding91

Rseding91
  • Members
  • 664 posts

Posted 10 February 2011 - 01:26 PM

EDIT: .. sorry about bumping this post I missread the last-posted date.


Question: Does the admin account in question have create directory permissions on the network location?

And also: Does the admin account in question have the same drive map setup? Or was the drive mapped under the normal account?

It sounds to me like the drive was mapped under the user account and when you run-as admin the admin account doesn't know that drive exists (because it was not setup for the admin).

Does any of that make any sence?

#15 fragman

fragman
  • Members
  • 1591 posts

Posted 10 February 2011 - 02:48 PM

I think the latter might be true. I now circumvented it by writing a batch file and running it hidden through the explorer process.