Link to home
Create AccountLog in
Avatar of cfwirth

asked on

Logon and Shutdown Scripts

I have a logon script on our Windows 2008 server that maps drives to the users.  I am using the NET USE F: \\server\share  command.  I want to be able to disconnect the mapped drives when the user shutsdown so when they are using the computer away from the network the mapped drives will not be available.  We are having an issue in Excel 2007 where they are receiving the message Initializing Root Folder To Display when doing a Save As on a spreadsheet and it takes a long time to save.

I am testing the NET USE F: /delete command before I create a shutdown script and save it to the GPO.  When I run this command on a computer and then log back into the network the drive letter that I deleted does not reappear.  When I logged into the same computer as another user, creating a new profile, all the drives appear.  What could be causing the drives not to appear after using the NET USE /delete command?


Avatar of Don
Flag of United States of America image

Avatar of cfwirth


I am using group polcies to map the drives as a logon script.  If I want to disconnect them using a script should that be placed in the logoff scripts or shutdown scripts?
You dont need logon scripts to map drives anymore(that was my point),  read the link :)
If you want to use logon scripts, which is what I do, instead of GP then this is what I suggest
Instead of the net use f: \\servername\sharename
do an IFstatement like this

if exist \\server\downloads net use l: \\server\downloads

That way if the user is on the network and connected if will make a network drive, if they are not if won't.

If you are worried about or having problems with Windows "remembering" the drive you can aad the persistent (remember) switch and set that to N (no)
if exist \\server\downloads net use l: \\server\downloads /p:n

Additionally, you can add a logoff script to delete all network drives when the users logoff or shut down, simply create a logoff script with a list of network drives and delete them like this

net use l: /d
net use m: /d
etc. etc,
Avatar of cfwirth


I created a logoff script that contains the following:
 Net use * /delete /yes

I placed thisscript in the PDC's group policy. When I log into the server the mappings are present. When I shutdown the computer I see that the logoff scripts run on the computer but when I turn the computer back on while not connected to the network the share are still trying to connect.  If I run the net use * /delete /yes command at a command prompt it works and the shares are disconnected.  I am not sure why the logoff script is not working.  Any suggestios?

If you use Group Policy Preferences to map your drives, you wont have any of these issues.
When you create the network connections are you using the persistent set to No switch?
if exist \\server\downloads net use l: \\server\downloads /p:n

Where the network connections originally created with net use statements of by using Windows Explorer?
What version of Windows are you doing your testing on?
Avatar of cfwirth


Here is an example of how the commands were entered into the logon script.

 net use f: \\servername\sharename

I am using Windows 2008 Standard
Change it to
net use f: \\servername\sharename p:/n

Server is 2008, what about Clients--XP or Win 7
Avatar of cfwirth


All clients are Win XP SP 3
Were the original connections created with net use or with Windows Explorer
Avatar of cfwirth


With Net Use.
Now I am troubled--is this happening on all your PCs or just some? Did changing to using
net use f: \\servername\sharename p:/n
If you did, did that resolve it?
Avatar of cfwirth


I haven't added /p:n yet.

Avatar of cfwirth


I added the /p:n to the mappings and they still appear when not logged into the network.  When shutting down it shows that the logoff script is running but the net use * /delete /yes command does not work.  I can get it to work if I enter this command at a command prompt on the computer.
Well the only other option I can offer you is to use the logon script to clean up what the logoff script does not or else you may have to use GPO

Logon Script
if not exist \\server\downloads net use l: /d /y

or you can do what I do, this is from a production script that I use--what this does is that it will delete the network drive and will not reconnect if it is not on the network but if it is it will.

@Echo On
net use /p:n
Set Server=SQLServer

Net Use G: /d /y
Net Use G: \\%Server%\Downloads
GoTo PublicFolder

Net Use H: /d /y
Net use H: \\%Server%\PublicFolder
GoTo MS-Dynamics

Net Use M: /d /y
Net Use M: \\%Server%\MS-Dynamics
GoTo Users

Net Use U: /d /y
Net Use U: \\%Server%\%UserName%

Avatar of cfwirth


Well I think I figured out why the logoff script would not work. It was user error, on my part. I entered the command incorrectly.  I entered in net use *: /delete /yes.  I put a colon after the asterisk. Now the mappings are deleted when logging out of the network.  One question though. When I am not connected to the network and shutdown the computer it still says 'running logoff script'. I do not have a logoff script on the computer only on the PDC.   Why would it still show running a logoff script while not connected to the network?

Thanks for all the help.
If you are using the GPO to control logoff scripts and the PC is set to check for and run logoff scripts then it will look to see if there are logoff scripts to run. Do you have logon and logoff scripts set to run from a server share or do you have copies on each PC? If the latter then it will still run--if the former then it will just check but not actually run them.
Avatar of cfwirth


I have the logon/logoff scripts on a server share and the GPO controls them.  There are no scripts on the PC itself.
Avatar of Lionel MM
Lionel MM
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
You can use MMC and the "Resultant set of Policy" snap-in to see how the central policy is stored (the resulk, changes) that are stored locally
Charlie--are we all set and done with this question? I think we are -- if not please let me know what else I can help you with on this-thanks!
Avatar of cfwirth


I think everything works now.  Thanks for the help.
Could you then close it and accept one of my answers as the solution please--thanks!