Thursday, February 26, 2015

Network Drive Mapping for Windows Services

This Article will explain about the steps need to be followed to use the Network Shared folders in the
Windows Services .

When we see the " Directory Path Invalid  " error during the Service start up, most of solutions
comes in Google search will tell us to use the UNC (Universal Naming Convention) Path for instead of Shared Folder mapping.

But sometimes the UNC path is not a perfect solution, especially in my  case where it has $ symbol in that path.  The Shared folder is from one windows server and it has a $ symbol in the path .

The UNC path with the $ symbol is not  accepted by the Apache  HTTP server while publishing the directory using the Alias name.

So what we did to resolve this issue.

the solution is we should have  a Drive letter for the mapped Shared Folder and it should be with the user
NT AUTHORITY / SYSTEM ..

Here is the one time setup to resolve this issue.


1. Download the Sysinternals Suite to the system from Microsoft website.
2.  Unzip the suite and keep it in some folder. (Ex C:\tmp)
3. Open the Command prompt using Run as Administrator .
4. type whoami in the command prompt it will show ur user id .
5. Go to Sysinternals suite folder and execute the following command
                      psexec -i -s comd.exe
        It will open a new command prompt.
       if check user id using the command whoami  .. It will display NT AUTHORITY \SYSTEM.
6. In the new command prompt execute the mapping command

        Syntax
                            net use DRIVELETTER: UNCPath /persistent:yes /savecre

       Ex  :
                            net use L: \\server1\folder1  /persistent /savecre

7. Now a New Drive will be available in the My Computer with the Title "Disconnected Network Drive"
    Don't worry about the title it is connected and you can access the files.
    Except  the user System for all others it will display as Disconnected Network Drive .
8. Now go to Apache HTTP Server Config file (httpd.conf)  which is available in the installed folder
   under conf directory .
 
     The Directory directive used to publish the files to the browser can use the newly created Drive path.



In case if you want to have the drive connected every time you logged in , you can add the step
6 command in a batch file.

Open the Control Panel --> Administrative Tools --> Scheduled Tasks - Schedule a Task and should run as "SYSTEM" .

That's all !!!
 Now start the HTTP Server and it will serve you those files.