Tech Support Guy banner
Status
Not open for further replies.

Remove Network Drive - GPO not working

Solved 
3K views 5 replies 2 participants last post by  reticentAJ 
#1 ·
Hi Folks,

I'm trying to remove a network drive ( K: ) mapped to our 200+ users. I created a VB Script and when I double click on some machine, it works without any issues. However, When I try to add this script as log on / log off script, it doesn'r remove network drive.
This logon script is not executing for some reason, in gpreport /h it shows blank under last run column.

However, rsop.msc shows this scirpt executed.

Below is my script.
-------------------------------------

Option Explicit

Dim objNetwork, strDriveLetter, objFSO
'strDriveLetter = "K:"

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objNetwork = CreateObject("WScript.Network")


' Section to mcheck and remove K drive
If (objFSO.DriveExists("K:") = True) Then
objNetwork.RemoveNetworkDrive "K:", True, True
End If

Wscript.Quit

-------------------------------------
 

Attachments

See less See more
2
#2 ·
So with the provided code, I was able to duplicate your results; the script worked when launched manually, but not when set as a logon or logoff script. Unfortunately, I am no VBS expert (or expert at any code language for that matter).

What I was able to find, though, was an alternative to complete this task using a batch file. Here's the article:
https://www.petri.com/forums/forum/...-logoff-script-for-dissconnecting-mapp-drives

There is really only one line of code required to complete this task:

Code:
@echo off

NET USE k: /DELETE /YES
From there, I was able to set this batch file as a logoff script and achieve the desired results. Unfortunately, it wouldn't work as a logon script. Since you didn't seem to have a preference of logon vs. logoff, this should be suffice.

Out of my own curiosity, why would you want to do this? I mean if users are always adding this network drive, why would you want to keep removing it? I assume since they keep adding it, they need it to accomplish their work. Not really related to your question, just a little curious. :)
 
#3 ·
This would work for sure. But what will happen when this script will execute and there is no K Drive. Will it show an error ?

For your curiosity, we mapped this drive previously and users used it. But now management has decided to remove access from everyone to limited users. Hence we are going to remove it on all those OUs using GPO, where no more required. :)
 
#4 ·
If there is no K drive when the batch file executes, no error will be produced. Windows will continue to log out, shutdown, etc normally. The reason is because essentially the task has already been completed, even if it wasn't by the script. Would be pretty silly to produce an error saying it couldn't remove a drive that doesn't exist. I've also tested this on my computer to ensure no error will be produced, and I receive no error.
 
#6 ·
Great! If you could mark the thread as solved if you believe the issue to be resolved, it would be appreciated.
 
Status
Not open for further replies.
You have insufficient privileges to reply here.
Top