Our organisation is starting to look at moving file data from regular file servers to SharePoint Online document libraries. We would like to be able to present some of these libraries to certain users as box-standard network drives. This is to ease the transition to SharePoint, support legacy applications that don't understand SharePoint and umpteen other reasons known only to people in management.

Previously I've done this by using a little C# application which reads registry settings from HKCU that are pushed out by Group Policy. The app spawns an invisible IE window, automates the authentication process by clicking buttons, entering fields etc. and once finally authenticated, it passes a call to the OS to map the Document Library URL as a network drive.

Unfortunately it seems that at the end of the month, MS is going to change the logon screen and the tickbox to keep you signed in doesn't look to be present in the new version of the page, which I understand is a requirement to map a Document Library as a network drive.

I'm looking at writing a new version of the app which doesn't use invisible IE windows, instead passing a call to SharePoint directly using Microsoft.SharePoint.Client and making use of ClientContext and SharePointOnlineCredentials to get access to the authentication cookie. This all works fine, however despite keeping the cookie in memory while the application runs, the call to the OS to map the URL as a network drive doesn't seem to do anything.

Just wondering if anyone has tried something similar and if so, how you went about it?

Kind regards and many thanks in advance for any advice!


If you haven't already checked it out take a look at the PowerShell script from Jos, the source code is available here https://gallery.technet.microsoft.com/OneDriveMapper-automaticall-d7d498b0

I think it should cover everything you need to map Microsoft WebDAV drives.

If you would consider a commercial solution for drive mapping then take a look at Zee Drive which should simplify the whole process of mapping network drives to OneDrive for Business and SharePoint Online. Zee Drive provides additional features such as mapping to shared with me files, access to the recycle bin and more, all from Windows File Explorer.

Disclosure: Zee Drive is a tool my company develops


So I was able to achieve this using the SpoAuthUtility class, keeping the returned CookieContainer then using InternetSetCookie from wininet.dll to make the cookies persistent before mapping the drive using WNetAddConnection2 from mpr.dll to add the new network connection. Kind of round the houses, but it avoids the need for invisible IE windows and page manipulation that a lot of solutions seem to use. Tested on domain-joined devices in the office today, and has worked in every case its been put through.

Cheers for the advice guys!


Unfortunately Zee Drive will not do what you need, it will only allow you to either manually run scripts to transfer files or drag and drop manually. I have tried using powershell scripts within a scheduler and it simply does not work unless you open in ISE and run manually. The response from Zee Drive was :

'Zee Drive needs to run in a Windows session. It is designed for end users – if it is running as a service, or “headless” i.e. no Windows session, or being accessed from a different Windows session it won’t work.

We don’t support Zee Drive running as a service or for service type workloads – it is designed for end users working with documents'.

Shame as it has potentials.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.