How to access Azure share from a service? RRS feed

  • Question

  • I have an existing application running as a service which can be directed to use a specific drive and folder or UNC path as a storage area. I also have an Azure files share available on the system. But I cannot make the first use the second. When I tell the service to open a file on the Azure share fopen_s() fails with errno 22 "Invalid argument".

    Much the same code running in a command prompt (ie not a service) runs OK.

    I have tried logging on the service as a local admin user, not Local System as it normally runs, but that does not help.

    Anyone got any suggestions?

    Thursday, September 15, 2016 1:14 PM

All replies

  • Hi -

    Can you verify that you are mounting the file share from the service before attempting to access the file?

    And can you share the relevant code here?

    Thursday, September 15, 2016 8:53 PM
  • I'm mounting the file share in a command window before starting the service using a "net use" command to assign a drive letter and give a username and password.

    I cannot show the entire code; it's too long to be meaningful. The line which fails is:

    errno_t err = fopen_s(&fp, sFilePath, "r");

    where sFilePath is the full path of a file on the Azure share.

    Are you suggesting I should separately mount the share from the service before using it. What system call would do that?

    Friday, September 16, 2016 7:11 AM
  • This could be a problem with context. The account used has to set the credentials under the same context. For example, if you mount a file share in a command window running with administrative mode, and then try mounting it with the exact same account NOT in admin mode, it don't recognize the disk. So running it under an account as a service is different than running it under that account in the command line.

    I got this to work once by adding code to my service to mount the share. The code is available in this blog article, close to the end.


    Is that something you could do, or is the service a black box?


    Sr. Content Developer at Microsoft

    Friday, September 16, 2016 10:36 PM
  • To add to Robin's response, you can use psexec to ensure you run mount under the particular user account the service/app is running as, and while doing so you'll need use fully qualified user name i.e. [storageaccountname].file.core.windows.net
    Friday, September 16, 2016 10:56 PM
  • OK, thanks Robin and Mine. You have given me some things to check out. I can get into the service code to some extent  - it runs a DLL I supply ;) - so I'll give that a go and then report back.
    Monday, September 19, 2016 7:32 AM