Jump to content



Photo

Windows Mapped Drives Question

win7 win8.1

  • Please log in to reply
7 replies to this topic

#1 Brandonlowry531

Brandonlowry531

    Resident One Post Wonder

  • Joined: 09-May 14

Posted 09 May 2014 - 14:57

I am looking to create a script that will check the current drive maps on a computer and if the specific ones have been disconnected or lost then I want it to automatically reconnect it back. If possible.

 

For instance if I am suppose to have (H:) and (P:) connected I want it to check connection for those and if they aren't then I want it to reconnect it.

 

Thanks!




#2 spikey_richie

spikey_richie

    XXXIII

  • Tech Issues Solved: 5
  • Joined: 02-February 05
  • Location: Nuneaton, UK
  • OS: Windows 8.1u1 Pro 64-bit
  • Phone: Sony Xperia Z1

Posted 09 May 2014 - 15:03

Do you want this to run at boot? Login? Periodically; say every 10mins?



#3 sc302

sc302

    Neowinian Senior

  • Tech Issues Solved: 35
  • Joined: 12-July 05
  • Location: NJ, USA

Posted 09 May 2014 - 15:10

NET USE H: \\SERVERNAME\SHARENAME /PERSISTENT:YES

NET USE P: \\SERVERNAME\SHARENAME /PERSISTENT:YES

 

the persistent keeps the drive mapped always.  If it falls off then the script will run the next time the logon.  Never had a drive delete or remove itself. 

 

If the computer are getting an x on the drive, change your power options on the computers.  the x will go away after the computer tries to reconnect to the drive or if you remove all power options on the nic card. 



#4 Haggis

Haggis

    Neowinian Senior

  • Tech Issues Solved: 15
  • Joined: 13-June 07
  • Location: Near Stirling, Scotland
  • OS: Debian 7
  • Phone: Samsung Galaxy S3 LTE (i9305)

Posted 09 May 2014 - 15:10

also are you using vbscript or a batch file?

 

batch file you can use

if exist n:\. goto mapn
goto :eof

:mapn
NET USE N: \\SERVERNAME\SHARENAME /PERSISTENT:YES

etc ect



#5 mbaker82

mbaker82

    Neowinian

  • Joined: 26-May 14

Posted 27 May 2014 - 03:19

I know your looking for a script, however,

 

Do you have domain privileges (Server 2008R2-2012) ?  If so, use a GPO to set drive letters to specific users or groups.

 

You can also prevent locals from changing drive letters in the future.

 

Let me know if you need help with this change

 

Michael



#6 sc302

sc302

    Neowinian Senior

  • Tech Issues Solved: 35
  • Joined: 12-July 05
  • Location: NJ, USA

Posted 27 May 2014 - 12:45

I know your looking for a script, however,

 

Do you have domain privileges (Server 2008R2-2012) ?  If so, use a GPO to set drive letters to specific users or groups.

 

You can also prevent locals from changing drive letters in the future.

 

Let me know if you need help with this change

 

Michael

We can create a logon script to do just that.  No need for gpo.  GPOs can be finicky in regards to running.  If they don't get applied how do you force the mapping or manually map it?  Scripting it is a much better option because you have a backup when the gpo doesn't work for whatever reason, you can make the script part of the gpo if you so choose so that way you have the best of both worlds.  This is how I commonly execute drive mappings. 

 

Here are two scripting examples that will map a drive based on group membership (we can do pc name if they have a specific departmental prefix or suffix that would do it based on where the computer is, good for printer mappings by location).

 

kixtart script

 


map y: "\\servername\common share" /persistent:yes

 

if ingroup("domain group name")

map x: \\servername\sharename /persistent:yes

endif

 

vbscript:

 


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

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

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

Select Case strGroupName
Case "domain group name"
objNetwork.MapNetworkDrive "X:", "\\atl-fs-01\sharename"

End Select

 

Following either of these two examples will map the drive every time the user logs in, and if you change their membership will map the new drives for them as well.



#7 Anibal P

Anibal P

    Neowinian

  • Tech Issues Solved: 1
  • Joined: 11-June 02
  • Location: Waterbury CT
  • OS: Win 8.1
  • Phone: Android

Posted 27 May 2014 - 12:52

That reminds me I haven't glanced at our Domain logon scripts at work, our do something very similar, as well as other things 



#8 TPreston

TPreston

    Neowinian Senior

  • Tech Issues Solved: 2
  • Joined: 18-July 12
  • Location: Ireland
  • OS: Windows 8.1 Enterprise & Server 2012R2/08R2 Datacenter
  • Phone: Nokia Lumia 1520

Posted 27 May 2014 - 14:16

Consider using library's instead of mapped drives, it gives you a whole load more flexibility for example you can change the icon to something useful. pin them to the navtree or not, change the explorer columns to match the content  etc

 

if (!(Test-Path -path "$env:userprofile\AppData\Roaming\Microsoft\Windows\Libraries\Television.library-ms" )) {
SLUtil create Television
}
else {
}
if (!(Test-Path -path "$env:userprofile\AppData\Roaming\Microsoft\Windows\Libraries\Movies.library-ms" )) {
SLUtil create "Movies"
}
else {
}
if (!(Test-Path -path "$env:userprofile\AppData\Roaming\Microsoft\Windows\Libraries\New Movies.library-ms" )) {
SLUtil create "New Movies"
}
else {
}
if (!(Test-Path -path "$env:userprofile\AppData\Roaming\Microsoft\Windows\Libraries\Downloads.library-ms" )) {
SLUtil create Downloads
}
else {
}
if (!(Test-Path -path "$env:userprofile\AppData\Roaming\Microsoft\Windows\Libraries\Applications.library-ms" )) {
SLUtil create Applications
}
else {
}
SLUtil Icon "Downloads" "imageres.dll,-184"
SLUtil Icon "Movies" "imageres.dll,-1005"
SLUtil Icon "Applications" "imageres.dll,-87"
SLUtil Icon "Downloads" "imageres.dll,-184"
SLUtil Icon "New Movies" "imageres.dll,-1005"
SLUtil Icon "Television" "imageres.dll,-1008"
SLUtil addfolder Music "\\HyperV1\Music"
SLUtil addfolder Downloads "\\Getright\Downloads"
SLUtil addfolder Movies "\\HyperV1\Movies"
SLUtil addfolder Videos "\\HyperV1\Movies"
SLUtil addfolder "New Movies" "\\HyperV1\New Movies"
SLUtil addfolder Applications "\\HyperV1\Applications"
SLUtil addfolder Television "\\HyperV1\Television"

SLUtil NavPanePinnedState Videos False
SLUtil FolderType Music Music
SLUtil FolderType Downloads Generic
SLUtil FolderType Television Videos
SLUtil FolderType Movies Videos
SLUtil FolderType "New Movies" Videos