Accessing network drive from ASP.NET through network drive, not UNC

Recently we came across a situation where we needed to connect to Network drive using mapped drive, but not UNC. But default, this is not allowed by windows. So our code gave error like – Directory not found.

We had to use E: drive as many other places are using the same variable in our .Net c# application.

For this hack you will need SysinternalsSuite by Mark Russianovich:

Step One: Open an elevated cmd.exe prompt (Run as administrator)
Step Two: Elevate again to root using PSExec.exe: Navigate to the folder containing SysinternalsSuite and execute the following command “psexec -s cmd.exe” you are now inside of a prompt that is “nt authority\system” and you can prove this by typing “whoami”
Step Three: Create the persistent mapped drive as the SYSTEM account with the following command:

net use e: \\networkdomain\sdata password /user:domain\username /persistent:yes

WARNING: You can only remove this mapping the same way you created it, from the SYSTEM account. If you need to remove it, follow steps 1 and 2 but change the command on step 3 to: “net use e: /delete”
NOTE: The newly created mapped drive will now appear for ALL users of this system but they will see it displayed as “Disconnected Network Drive (E:)”. Do not let the name fool you. It may claim to be disconnected but it will work for everyone.

In the IIS website, use impersonate identity to a application pool.