JD12
(Fresh Scripter)
2012-08-22 04:56 PM
Activate Mapped Drives at Logon?

I am using a very basic script to map multiple network drives for users. All users are now on Win7 connecting to Win2K8 R2 DC's. The drive mappings work but most of the drives are not active (Red X'd out) until the user manually selects the drive. This causes some problems when an application attempts to read from the mapped drive but it hasn't been activated by the user. I've ready alot about this issue in the MS forums but have found no reliable fix. Can anyone here recommend an easy way to activate the drives from within the .kix file?
Thanks in advance,
Joe


ShaneEP
(MM club member)
2012-08-22 05:41 PM
Re: Activate Mapped Drives at Logon?

Have you tried disconnecting the drives before re-mapping them? Sounds like some kind of persistent mapping problem. What code are you using to map the drives exactly?

AllenAdministrator
(KiX Supporter)
2012-08-22 05:48 PM
Re: Activate Mapped Drives at Logon?

You also might check with out your Antivirus vendor, as I know some AVs cause this.

JD12
(Fresh Scripter)
2012-08-23 03:39 PM
Re: Activate Mapped Drives at Logon?

Thanks for the reply. I am deleting the mappings each time before mapping them again. This appears to be a known issue with Win7, where the drive mappings are read and processed before the network connection is completely established. I've made all the MS-recommended changes in group policy processing, etc. but with no effect. I'm hoping for an option in the script where I could enumerate the drive or such that would activate the connection before the user had time to open an application.

Here's the sanitized version of my script:
 Code:
;Drive mapping script for the IS department

USE G: /DEL
USE G: @HOMESHR ;Map G: to the users home directory

USE H: /DEL
USE H: "\\Server2\IS"

USE T: /DEL
USE T: "\\Server8\df"

USE X: /DEL
USE X: "\\Server2\SNOOPY" /persistent:yes

USE W: /DEL  ; disconnect W:  TS.2 WINTEG

Color y+/n
AT ( 9,40) @userid
AT (10,40) @fullname
AT (11,40) @priv
AT (12,40) @wksta
AT (13,40) @domain
AT (14,40) @lserver
Color w/n


RETURN

Thanks,
Joe


JD12
(Fresh Scripter)
2012-08-23 04:01 PM
Re: Activate Mapped Drives at Logon?

I'm pretty sure this is not an AV (McAfee) issue given the number of reported issues out there, but thanks for the thought.

AllenAdministrator
(KiX Supporter)
2012-08-23 04:11 PM
Re: Activate Mapped Drives at Logon?

Is this a GPO Logon Script?

Mart
(KiX Supporter)
2012-08-23 04:18 PM
Re: Activate Mapped Drives at Logon?

Not so much a solution for your issue but I have some suggestions.
If you are trying to map the X drive as a persistent drive then leave out “:yes”. This is not valid in kixtart. Deleting the X drive will most likely fail because if it is mapped as persistent it also needs to be removed as persistent. When deleting drives I always assume all drive are mapped as persistent. It is just a safe guard that the drive will always get deleted no matter if it was mapped persistent or not.

Is this all the code? If so then the RETURN is unneeded. Actually there is almost always a way to not use returns, goto’s and labels. They just make the code messy.


Robdutoit
(Hey THIS is FUN)
2012-08-26 05:40 PM
Re: Activate Mapped Drives at Logon?

hi there JD12, I also work with domains and use kixtart as a login script. I have actually spent the last few months completing rebuilding my script to make it 100% compatiblie with Windows 7 and Server 2008 standard. I remember having the same problem that you have and if memory serves me correctly the problem was caused by the drives being mapped persistently. But I cannot remember for sure, so what I will do is give you the coding that I use and the steps that I have taken in my new script as I don't have this issue in the new script.

1. Run the script from the group policy. I used to in the old days run my script from the netlogon folder. This causes a lot of issues with windows 7. You need to run it from a gpo.
2. Use the latest kixtart script as this take into account any changes with windows 7.
3. When calling from a gpo you need to call the file kix32.exe and you need to specify that you are calling the kixtart.kix script otherwise it does not run. this issue is specific to the latest version of kixtart. I did not have this issue with earlier versions. It used to just run kixtart.kix without me having to specify the file to be called.
4.Do not use persistent drives (as I think that this was the cause when I had the problem). To ensure that you don't have persistent drives, disable your script, logoff and logon again. If the drives are still there, you have a persistent setting somewhere.
try looking in the registry setting
 Quote:

("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Network\Persistent Connections", "SaveConnections", "No","REG_SZ")

5. I had an issue with windows 7 not mapping the drives at all, if I run it from the gpo. It worked perfectly if I ran the script manually while logged on, but it did not work when the script ran on login. You need to add the following code for windows 7
 Quote:


("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System", "EnableLinkedConnections", "1", "REG_DWORD")


I also found that sometimes settings were not being applied consistently and I came to the conclusion that the script was writing settings to the registry before the user key was loaded, so the settings were not being applied. To correct this, I told the script to wait till the user ID was loaded, then continue loading the script. I don't believe that this is causing your problem, but it may be worth your while to add. Put this right at the beginning of your script, so that it will wait for the User ID to be loaded then run your script.
 Quote:

? "User logged on is " @Userid
while
@USERID = ""
sleep 300
? "sleeping for 300 milliseconds"
loop


You may have a problem with your network card drivers. Try updating to the latest version as you may have an issue where the network card driver seems to lose the connection. I had this and I had to change from version 6.00 to version 6.20 for the realteak card, but I had to manually select the driver rather than have windows choose my driver. I doubt that is your problem, because you are obviously having the issue where the x appears straight on login, but its always worthwhile to update the network card drivers.

I believe that your problem is that your drives are set to be persistent. With regards to your script, if you do not have persistent drives, there is no need to delete the drives at all. when you logoff the drives will automatically be deleted. so get rid of the part of your script where you are deleting the mapped drives as this is not required.
Hope that my answer helps somewhat


ShaneEP
(MM club member)
2012-08-26 09:16 PM
Re: Activate Mapped Drives at Logon?

All good suggestions. However, 'Sleep 300' will cause a sleep of 300 seconds, not 300 milliseconds. Use sleep 0.3 if you want 300 milliseconds.

Robdutoit
(Hey THIS is FUN)
2012-08-26 09:36 PM
Re: Activate Mapped Drives at Logon?

Oh dear God, either the user id is already loaded by the time the script starts running or the function is not working at all, because the logon is not being held up for 300 seconds. But thanks for that. I didn't realise that. I have updated my script accordingly.

AllenAdministrator
(KiX Supporter)
2012-08-26 11:29 PM
Re: Activate Mapped Drives at Logon?

And keep in mind that "EnableLinkedConnections" is not a supported configuration by Microsoft. If you are interested, there is another thread around here that has a script to help get around this mapping limitation.

Robdutoit
(Hey THIS is FUN)
2012-08-28 05:03 PM
Re: Activate Mapped Drives at Logon?

Thanks for pointing that out Allen. When time permits I will have a look at the alternative option to "EnableLinkedConnections" and see what that is all about. for the moment, it fixes the problem, so will leave for the time being until I have fixed all my other problems with my new script. Thanks

JD12
(Fresh Scripter)
2012-08-29 02:49 PM
Re: Activate Mapped Drives at Logon?

Robdutoit, thanks much for the detailed response. And thanks everyone for the other clarifications. I will be working on this over the next couple of weeks as time permits. I will post back my results.

Cheers,
Joe


JD12
(Fresh Scripter)
2012-08-29 03:58 PM
Re: Activate Mapped Drives at Logon?

Robdutoit, would you have a sample of the code you're using in your script?
Thanks,
Joe


Robdutoit
(Hey THIS is FUN)
2012-08-29 06:37 PM
Re: Activate Mapped Drives at Logon?

I use a function that I created called checkandsetregvalue which is self explanatory. This sets the necessary registry settings for my mapped drives to work

 Quote:


;================================================================================================
; Checks the registry value and if incorrect, it applies correct setting, otherwise says already applied
;================================================================================================

Function CheckAndSetRegValue($RegPath, $RegValue, $RegData, $RegType)

$ReturnValue = ReadValue($RegPath, $RegValue)

If ($ReturnValue = $RegData)
; ? "Registry value already applied:"
; ? "Path: " + $RegPath
; ? "Value: " + $RegValue
; ? "RegData: " + $RegData
; ? "Value Type: " + $RegType
Else
WriteValue($RegPath, $RegValue, $RegData, $RegType)
; ? "Registry value is being set for: "
; ? "Path: " + $RegPath
; ? "Value: " + $RegValue
; ? "RegData: " + $RegData
; ? "Value Type: " + $RegType
EndIf
EndFunction

;=================================================================
; Delete Persistent Network connections ie mapped drives
;=================================================================

CheckAndSetRegValue ("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Network\Persistent Connections", "SaveConnections", "No","REG_SZ")

;======================================================================================================
;This setting fixes a problem with mapped drives not working with domain users in windows 7 - something to do with uac
;======================================================================================================

CheckAndSetRegValue($HKLMSOFT + "\Microsoft\Windows\CurrentVersion\Policies\System", "EnableLinkedConnections", "1", "REG_DWORD")

;=============================================================
; Maps user drives
;=============================================================

Use X: $ServerName + "\software"

If ingroup ("managers") or ingroup ("office") = 1
? "Do not map P drive as don't need for these users"
Else

;=================================================================
; Mapping the P: drive for staff and pupils
;=================================================================

Use P: $ServerName + "\shared\access"
Endif



Allen has mentioned that one should not use "EnableLinkedConnections", so you might want to look up his alternative that he suggested. I have not had time to look into that as yet.

On my test server (windows 2008 server) I have noticed the problem with the red crossed on drives that I have manually mapped on my server (with the setting to map again for every logon. This is not a script issue, its a windows vista/7 issue to do with persistent mappings.

Rob