Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using a script to keep a mapped networkconnection alive, but ofcourse the mapped connection is gone when I logout. The point is now, that I'm running this on Windows Server 2008 R2, where I use remote desktop to login on the administrator account. However, it should remain logged in and not remove the mapped connection as this script takes care of not logging out on MS office 365 sharepoint.

Is there a way to keep the mapped networklocation (L:) available after logout? So the script can run to remain the connection?

# Create an IE Object and navigate to my SharePoint Site

$ie = New-Object -ComObject InternetExplorer.Application

# Don't need the object anymore, so let's close it to free up some memory

# Just in case there was a problem with the web client service
# I am going to stop and start it, you could potentially remove this
# part if you want. I like it just because it takes out a step of 
# troubleshooting if I'm having problems.

Stop-Service WebClient
Start-Service WebClient

# We are going to set the $Drive variable here, this is just
# going to tell the command what drive letter to map you can 
# change this to whatever you want (if you change it to a 
# drive that is already mapped it will overwrite it, so be careful.

$Drive = "L:"

# You can change the drive destiniation to whatever you want,
# it has to be a document library or folder of course.
$DrvDest = ""

# Here is where we create the object to map the network drive and
# then map the network drive
$net = New-Object -ComObject WScript.Network;

# That is the end of the script, now schedule this with task
# scheduler and every so often and you should be set.
share|improve this question
If I understand you correctly, your actual problem is getting logged out of MS Office 365 when you log out of your remote desktop session and this is how you want to avoid that? – Oliver Salzburg Oct 16 '12 at 10:17
I would like to keep the L: drive available on logout, or some other way around so I can run any .NET application that can use the L: to upload files to with that location. – Rob Oct 16 '12 at 12:25
Why? What applications? NT Services? Mapped drives are session specific. – snowdude Oct 20 '12 at 9:35

Instead of trying to keep a network drive open why not simply use the UNC path to the resource. e.g.


instead of


share|improve this answer
This is not an answer, \\Server\folder is no drive I can map to. Can you explain me how to map to that folder? – Rob Oct 16 '12 at 9:18
Mapped drives only last for the 'session' in which the login exists. Are you trying to do something in an NT service? – snowdude Oct 16 '12 at 9:21

first you should learn how to:

Open SharePoint document library in windows explorer

then you can create a batch file, with net use command you will config which user to authenticate and can set the user and password for your desired shared folder

[devicename | *] [\\computername\sharename[\volume] [password | *]]
        [/USER:[dotted domain name\]username]
        [/USER:[username@dotted domain name]
        [[/DELETE] | [/PERSISTENT:{YES | NO}]]

NET USE {devicename | *} [password | *] /HOME

if you need , you can map administrator shared folders that always hide for other users
share|improve this answer
Can you tell me how I can use this to connect to a sharepoint with username and password? – Rob Oct 30 '12 at 15:41
if you want to map a network drive, to PCs in your domain, they may report slow speed to open their "my computer"s because your server didn't respond immediately . – saber tabatabaee yazdi Oct 31 '12 at 4:19
when you are in any SharePoint Document Library with internet explorer, you will see option to "open this DL in windows explorer" and then if you replace "http://" by "\\" and "/" by "\" you can have windows address like shared folders in file servers. that named FQDN. by this address you can map a network drive – saber tabatabaee yazdi Oct 31 '12 at 4:22
for managed map network drive you can create a batch file script with those commands that above and place in GPO in Active Directory to run in all start up joined computers in your domain. (please if is this helpful +1, comments and answers) – saber tabatabaee yazdi Oct 31 '12 at 4:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .