login script to remove mapped drives

B

Bunert

I have a login script that maps some drives and copies some files. It works
great.

I have some users that have mapped some drives to locations on the network
that no longer exist. I want to delete the mappings as the login script
remaps them properly. The delete does not work from within the login script
but it works if manually typed on the client at the cmd prompt.

I am using:

NET USE X: /DELETE /YES to delete the persistent mapping. (I also tried
without the /YES)

If in my login script, the X: drive does not delete - although in the same
login script I map a U: drive which maps ok so I know the script is being
called and functional.

If I go to the client and do type the the /delete at the cmd prompt - the X:
drive gets deleted properly.

If I put the login script on the client desktop and run it there, the X
drive does not delete. I do not get a "command completed successfully" -
however I do not get an error either.

Any thoughts?

thanks
 
M

Mark Heitbrink [MVP]

Hi,
I am using:
NET USE X: /DELETE /YES to delete the persistent mapping. (I also tried
without the /YES)

Did you try "net use *" (Asterix) instead of the driveletter?

Mark
 
K

KTosser

You could try using a vbs login script. I have used these before with
great success.

This first one will remove mappings and then set mappings for all users
that get the script:

<<Script Start>>
On Error Resume Next

Set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = CreateObject("Wscript.Network")

'removes mapped drive H
objNetwork.RemoveNetworkDrive "H:", True, True

'creats maped drive H
objNetwork.MapNetworkDrive "H:", "\\Server\Share"
<<Script End>

Or this second one will map differently depending on what AD security
groups they are members of

<<Start Script>>
On Error Resume Next

Set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = CreateObject("Wscript.Network")

strUserPath = "LDAP://" & objSysInfo.ComputerName
Set objUser = GetObject(strUserPath)

'Finds users group membership
For Each strGroup in objUser.MemberOf
strGroupPath = "LDAP://" & strGroup
Set objGroup = GetObject(strGroupPath)
strGroupName = objGroup.CN

'Removes curent mappings
objNetwork.RemoveNetworkDrive "H:", True, True
objNetwork.RemoveNetworkDrive "I:", True, True
objNetwork.RemoveNetworkDrive "R:", True, True
objNetwork.RemoveNetworkDrive "S:", True, True
objNetwork.RemoveNetworkDrive "T:", True, True


'Mappings for all users
objNetwork.MapNetworkDrive "H:", "\\Server\Share"


'Mappings Based on Group Membership
Select Case strGroupName

Case "Group 1"
objNetwork.MapNetworkDrive "I:", "\\Server\Share1"

Case "Group 2"
objNetwork.MapNetworkDrive "R:", "\\Server\Share 2"

Case "Group 3"
objNetwork.MapNetworkDrive "S:", "\\Server\Share 3"

Case "Group 4"
objNetwork.MapNetworkDrive "T:", "\\Server\Share 4"

End Select
Next
<<End Script>>

Hope one of these will help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top