you may notice that the network/mapped drives are randomly disappearing. A logoff/login will fix it temporarily, but what a pain. This is how you permanently fix the vanishing drives.
Registry Method
Use this method to change default time-out period of autodisconnect .
Run | regedit
Locate and then click the following key in the registry:
autodisconnect
Key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters
Value:
Value: autodisconnect
Data type : REG_DWORD
Range : Hexadecimal
Default value: ffffffff4. KeepConn : Change time-out the client-side during a UNC connection, specify in KeepConn. Locate and then click the following key in the registry:
Key:
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\LanmanWorkstation\Parameters]
Value:
Value: KeepConn
Data type : REG_DWORD
Range : 1 to 65535 (sec)
Default value: 600 sec = 10 mins
Command Line Method
1. autodisconnect :
change the default time-out period for the autodisconnect feature of the Server service,
2. Run | cmd as Admin
3. Type following cmd:
net config server /autodisconnect:-1
net config server /autodisconnect:number
More info:
0 = the autodisconnect feature is not turned off
-1 = the autodisconnect feature is turned off
1-65,535 = number is the number of minutes that you want the server to wait before it disconnects a mapped network drive
4. Windows 10 only:
This can the SMB issues with dropping network shares:open a administrator command prompt and type the following hitting enter after each line.
sc.exe config lanmanworkstation depend= bowser/mrxsmb10/nsi
sc.exe config mrxsmb20 start= disabled
then Restart the computer
To reverse :
sc.exe config lanmanworkstation depend= bowser/mrxsmb10/mrxsmb20/nsi
sc.exe config mrxsmb20 start= auto
then Restart the computer
Others:
1. Network Adapters:
I've found that by turning off the network card's power saving features I've not been losing the drives.
2. Group Policy :
Group Policy drives which are set to "Recreate". Windows 8/10 automatically runs Group Policy updates in the background and disconnects/reconnects the drive to Recreate it.
Change the drive to "Update" in group policy and the issue will disappear!
Run | gpedit.msc:
User Configuration > Preferences > Windows Settings > Drive Maps
Change the drive to “Update” in group policy
3. Run a custom .bat file on login and network connect:
- FixMappedDrives.bat
Sample file below, this connects to mapped drives based on loginid of user, in this case I am hard coding a userid to a mapped drive credential. This could be altered to use dynamic credentials based on userid and lookup up creds based on current logged in user.
- task Scheduler
Run bat fule on following events:
A) Login and
StartUp using StartUp folder or Task Scheduler Logon event
B) Network connect
Task Scheduler task: Network connect event
- Sample files:
FixedMapDrives.bat
@echo off
echo MyFileServer:MapDrives Login Script START
echo MyFileServer:MapDrives Checking connection to MyFileServer....
ping -n 10 MyFileServer > nul
echo MyFileServer:MapDrives done Checking connection to MyFileServer.... Error: %errorlevel%
if %errorlevel% == 0 (
echo MyFileServer:MapDrives CONNECTED
goto connected
) ELSE (
echo MyFileServer:MapDrives ERROR- Not Connected
goto end
)
:connected
echo MyFileServer start Map Drives for user %username%...
echo off
net use * /delete /yes
IF /i NOT "%username%"=="User1" GOTO NEXT1
echo MyFileServer:MapDrives Add DoyleJ mapped drives
net use * /delete /yes
NET USE M: \\MyFileServer\homes\User1 /USER:MyFileServer\User1 SomePassword
NET USE Y: \\MyFileServer\Public /USER:MyFileServer\User1 SomePassword
NET USE P: \\MyFileServer\Photo /USER:MyFileServer\User1 SomePassword
NET USE V: \\MyFileServer\Video /USER:MyFileServer\User1 SomePassword
GOTO ENDIF
:NEXT1
IF /i NOT "%username%"=="user2" GOTO NEXT2
echo Add user2
echo off
net use * /delete /yes
NET USE M: \\MyFileServer\homes\user2 /USER:MyFileServer\user2 SomePassword
NET USE Y: \\MyFileServer\Public /USER:MyFileServer\user2 SomePassword
NET USE P: \\MyFileServer\Photo /USER:MyFileServer\user2 SomePassword
NET USE V: \\MyFileServer\Video /USER:MyFileServer\user2 SomePassword
GOTO ENDIF
:NEXT2
echo Add Public
echo off
net use * /delete /yes
NET USE Y: \\MyFileServer\Public /USER:MyFileServer\User1 SomePassword
GOTO ENDIF
:ENDIF
:end
echo MyFileServer Login Script DONE
- Powershell
FixedMapDrives.ps1
$i=3
while($True){
$error.clear()
$MappedDrives = Get-SmbMapping |where -property Status -Value Unavailable -EQ | select LocalPath,RemotePath
foreach( $MappedDrive in $MappedDrives)
{
try {
New-SmbMapping -LocalPath $MappedDrive.LocalPath -RemotePath $MappedDrive.RemotePath -Persistent $True
} catch {
Write-Host "There was an error mapping $MappedDrive.RemotePath to $MappedDrive.LocalPath"
}
}
$i = $i - 1
if($error.Count -eq 0 -Or $i -eq 0) {break}
Start-Sleep -Seconds 30
}
No comments:
Post a Comment