Wednesday, April 27, 2011

How to map a network drive to be used by a service

For this hack you will need SysinternalsSuite by Mark Russianovich: http://technet.microsoft.com/en-us/sysinternals/bb842062.aspx
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 z: \servername\sharedfolder /persistent:yes"
It's that easy!
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 z: /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 (Z:)". Do not let the name fool you. It may claim to be disconnected but it will work for everyone. That's how you can tell this hack is not supported by Microsoft.


UPDATE

Hi all,

Thanks for the feedback.

I have finally had a chance to try and find a workaround to get the mapping done when the computer restarts. I have done limited testing, but so far this seems to have worked.

Follow this article to create a service with whatever name u like

http://support.microsoft.com/kb/137890

I suggest creating something like

C:\Program Files\Resource Kit\Instsrv.exe MapDriveAsSystem C:\Program Files\Resource Kit\Srvany.exe

Then do the regedit as described in the article.

There is a bit more to it then just running the psexec command.

You HAVE TO MAKE SURE THE SERVICE RUNS under a USER account and NOT LOCAL SYSTEM

Then its upto you to set the service startup requirement. The service stays in started state although the psexec has completed its task. So if you were to manually delete the mapping the service would show as started regardless. To improvise on that. may be you could create a bat file with the psexec command to map as system and then a SC command to stop the same service.

Shouldnt matter though, as we are only doing this service creation to handle the mapping on a computer reboot.

Hope it helps.

Cheers

Rahul 

18 comments:

  1. Works great! However, when I logged off/on the drive was not there. Is it possible to make this part of my login script? I'm using Win7.

    ReplyDelete
    Replies
    1. UPDATE

      Hi all,

      Thanks for the feedback.

      I have finally had a chance to try and find a workaround to get the mapping done when the computer restarts. I have done limited testing, but so far this seems to have worked.

      Follow this article to create a service with whatever name u like

      http://support.microsoft.com/kb/137890

      I suggest creating something like

      C:\Program Files\Resource Kit\Instsrv.exe MapDriveAsSystem C:\Program Files\Resource Kit\Srvany.exe

      Then do the regedit as described in the article.

      There is a bit more to it then just running the psexec command.

      You HAVE TO MAKE SURE THE SERVICE RUNS under a USER account and NOT LOCAL SYSTEM

      Then its upto you to set the service startup requirement. The service stays in started state although the psexec has completed its task. So if you were to manually delete the mapping the service would show as started regardless. To improvise on that. may be you could create a bat file with the psexec command to map as system and then a SC command to stop the same service.

      Shouldnt matter though, as we are only doing this service creation to handle the mapping on a computer reboot.

      Hope it helps.

      Cheers

      Rahul

      Delete
  2. Im not sure why you want it to be in the login script. bcos the reason you would use this mapping, is so that its not dependent on a user login.

    Not sure why it would have disappear. have tested it on win2k8 and has been fine. may be u missed the persistent switch ?

    ReplyDelete
    Replies
    1. UPDATE

      Hi all,

      Thanks for the feedback.

      I have finally had a chance to try and find a workaround to get the mapping done when the computer restarts. I have done limited testing, but so far this seems to have worked.

      Follow this article to create a service with whatever name u like

      http://support.microsoft.com/kb/137890

      I suggest creating something like

      C:\Program Files\Resource Kit\Instsrv.exe MapDriveAsSystem C:\Program Files\Resource Kit\Srvany.exe

      Then do the regedit as described in the article.

      There is a bit more to it then just running the psexec command.

      You HAVE TO MAKE SURE THE SERVICE RUNS under a USER account and NOT LOCAL SYSTEM

      Then its upto you to set the service startup requirement. The service stays in started state although the psexec has completed its task. So if you were to manually delete the mapping the service would show as started regardless. To improvise on that. may be you could create a bat file with the psexec command to map as system and then a SC command to stop the same service.

      Shouldnt matter though, as we are only doing this service creation to handle the mapping on a computer reboot.

      Hope it helps.

      Cheers

      Rahul

      Delete
  3. I double-checked and it works if I log off/on. However, if I power off/on it doesn't work. I'm running win7 home premium, 64-bit. Not sure if that matters.

    ReplyDelete
    Replies
    1. UPDATE

      Hi all,

      Thanks for the feedback.

      I have finally had a chance to try and find a workaround to get the mapping done when the computer restarts. I have done limited testing, but so far this seems to have worked.

      Follow this article to create a service with whatever name u like

      http://support.microsoft.com/kb/137890

      I suggest creating something like

      C:\Program Files\Resource Kit\Instsrv.exe MapDriveAsSystem C:\Program Files\Resource Kit\Srvany.exe

      Then do the regedit as described in the article.

      There is a bit more to it then just running the psexec command.

      You HAVE TO MAKE SURE THE SERVICE RUNS under a USER account and NOT LOCAL SYSTEM

      Then its upto you to set the service startup requirement. The service stays in started state although the psexec has completed its task. So if you were to manually delete the mapping the service would show as started regardless. To improvise on that. may be you could create a bat file with the psexec command to map as system and then a SC command to stop the same service.

      Shouldnt matter though, as we are only doing this service creation to handle the mapping on a computer reboot.

      Hope it helps.

      Cheers

      Rahul

      Delete
  4. Has anyone come up with a way to have this persist after a reboot, or failing that, a batch script that applies it every time?

    Thanks!

    ReplyDelete
    Replies
    1. UPDATE

      Hi all,

      Thanks for the feedback.

      I have finally had a chance to try and find a workaround to get the mapping done when the computer restarts. I have done limited testing, but so far this seems to have worked.

      Follow this article to create a service with whatever name u like

      http://support.microsoft.com/kb/137890

      I suggest creating something like

      C:\Program Files\Resource Kit\Instsrv.exe MapDriveAsSystem C:\Program Files\Resource Kit\Srvany.exe

      Then do the regedit as described in the article.

      There is a bit more to it then just running the psexec command.

      You HAVE TO MAKE SURE THE SERVICE RUNS under a USER account and NOT LOCAL SYSTEM

      Then its upto you to set the service startup requirement. The service stays in started state although the psexec has completed its task. So if you were to manually delete the mapping the service would show as started regardless. To improvise on that. may be you could create a bat file with the psexec command to map as system and then a SC command to stop the same service.

      Shouldnt matter though, as we are only doing this service creation to handle the mapping on a computer reboot.

      Hope it helps.

      Cheers

      Rahul

      Delete
  5. Srvany is the answer. run the psexec command using a batch file that is run as a service. http://support.microsoft.com/kb/137890

    ReplyDelete
  6. I get an error requesting a username for the NAS drive I'm using.

    C:\windows\system32>net use z: \\192.168.1.200\Pictures /persistent:yes
    The password is invalid for \\192.168.1.200\Pictures.

    Enter the user name for '192.168.1.200': System error 1223 has occurred.

    The operation was canceled by the user.

    ReplyDelete
    Replies
    1. u have to give your computer account full control on the share. it uses the computer account name.

      Delete
  7. I can confirm the mapped drive disappears after a reboot on Win7 64 bit. This is a major issue, and home someone can post a workaround. Thank you!

    ReplyDelete
    Replies
    1. UPDATE

      Hi all,

      Thanks for the feedback.

      I have finally had a chance to try and find a workaround to get the mapping done when the computer restarts. I have done limited testing, but so far this seems to have worked.

      Follow this article to create a service with whatever name u like

      http://support.microsoft.com/kb/137890

      I suggest creating something like

      C:\Program Files\Resource Kit\Instsrv.exe MapDriveAsSystem C:\Program Files\Resource Kit\Srvany.exe

      Then do the regedit as described in the article.

      There is a bit more to it then just running the psexec command.

      You HAVE TO MAKE SURE THE SERVICE RUNS under a USER account and NOT LOCAL SYSTEM

      Then its upto you to set the service startup requirement. The service stays in started state although the psexec has completed its task. So if you were to manually delete the mapping the service would show as started regardless. To improvise on that. may be you could create a bat file with the psexec command to map as system and then a SC command to stop the same service.

      Shouldnt matter though, as we are only doing this service creation to handle the mapping on a computer reboot.

      Hope it helps.

      Cheers

      Rahul

      Delete
  8. UPDATE

    Hi all,

    Thanks for the feedback.

    I have finally had a chance to try and find a workaround to get the mapping done when the computer restarts. I have done limited testing, but so far this seems to have worked.

    Follow this article to create a service with whatever name u like

    http://support.microsoft.com/kb/137890

    I suggest creating something like

    C:\Program Files\Resource Kit\Instsrv.exe MapDriveAsSystem C:\Program Files\Resource Kit\Srvany.exe

    Then do the regedit as described in the article.

    There is a bit more to it then just running the psexec command.

    You HAVE TO MAKE SURE THE SERVICE RUNS under a USER account and NOT LOCAL SYSTEM

    Then its upto you to set the service startup requirement. The service stays in started state although the psexec has completed its task. So if you were to manually delete the mapping the service would show as started regardless. To improvise on that. may be you could create a bat file with the psexec command to map as system and then a SC command to stop the same service.

    Shouldnt matter though, as we are only doing this service creation to handle the mapping on a computer reboot.

    Hope it helps.

    Cheers

    Rahul

    ReplyDelete
  9. Using psexec to map a network drive as SYSTEM no longer appears to work for Windows 7 after I applied a round of about 10 or 12 security fixes. The drive still appears in My Computer with the Red X but when you click on it you get "Logon failure: unknown user name or bad password.". If anyone knows which Windows update it was or a work around I'd be grateful. Thanks in advance.

    ReplyDelete
  10. So.. you wanna delete that drive?

    ReplyDelete
  11. No. I know how to delete it. I want a work around to make it work. Is this still working for everyone that is current on updates on Win7 Ultimate?

    ReplyDelete
  12. Excellent, this hack worked perfectly for me on the first try. Now I am able to use CrashPlan to backup the network shares from my NAS to any CrashPlan destination. This is with the newest CrashPlan version running on WinXP Pro.

    Cheers,

    ReplyDelete