Jump to content
Sign in to follow this  
jazzyjeff

Login Script

Recommended Posts

jazzyjeff

Hi,

I am using the following script to map network drives based on user group membership:

#include<AD.au3>

DriveMapDel ("H:")
DriveMapDel ("I:")
DriveMapDel ("J:")
DriveMapDel ("K:")
DriveMapDel ("L:")
DriveMapDel ("M:")
DriveMapDel ("N:")
DriveMapDel ("O:")
DriveMapDel ("P:")
DriveMapDel ("Q:")
DriveMapDel ("R:")
DriveMapDel ("S:")
DriveMapDel ("V:")
DriveMapDel ("W:")
DriveMapDel ("X:")
DriveMapDel ("Y:")
DriveMapDel ("Z:")

Global $aUser, $sFQDN_Group, $sFQDN_User, $iResult

; Open Connection to the Active Directory
_AD_Open()

; Get the Fully Qualified Domain Name (FQDN) for the current user
$sFQDN_User = _AD_SamAccountNameToFQDN()

; Get an array of group names (FQDN) that the current user is immediately a member of
$aUser = _AD_GetUserGroups(@UserName)
$sFQDN_Group = $aUser[1]

; Check the group membership of the specified user for the specified group
$iResult = _AD_IsMemberOf($sFQDN_Group, $sFQDN_User)

Select
    Case $iResult = "Domain Admins"
        DriveMapAdd("M:","\\app2\K5-Staff")
        DriveSetLabel("M:\","M Drive - Apps")
        DriveMapAdd("N:","\\app2\K5-Common")
        DriveSetLabel("N:\","N Drive - Common Apps")
        DriveMapAdd("T:","\\staffshare1\departmentshares$\Technology")
        DriveSetLabel("T:\","T Drive - Technology")
        DriveMapAdd("X:","\\techstore1\toolbox$")
        DriveSetLabel("X:\","X Drive - Toolbox")
        DriveMapAdd("Y:","\\techstore1\toolbox$\Deployment Drive\Elementary")
        DriveSetLabel("Y:\","Y Drive - Deployment")
        DriveMapAdd("Z:","\\StaffStore2\Userdata$\" &@UserName)
        DriveSetLabel("Z:\","Z Drive - " & @UserName & " - Home Directory")
EndSelect

; Close Connection to the Active Directory
_AD_Close()

The drive mapping part works fine, but the labels work for some of the drives and not others. Why is this? I am guessing my code is ok if it works for some of the drives, but maybe there is a problem with the "DriveSetLabel" function?

I have attached an image to help understand what I mean.

The drives should read:

M Drive - Apps

N Drive - Common Apps

T Drive - Technology

etc..

Thanks in advance for any help.

Jeff

post-54196-12748847013954_thumb.jpg

Share this post


Link to post
Share on other sites
water

Are you sure you want to do the "DriveSetLabel" in your login script?

I understand that "DriveSetlabel" writes the volume label to the disk. But that's something you do when you create the disk. That means once and not at every logon.

I recommend to remove the "DriveSetLabels" from your login script and set the labels once manually.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
JohnOne

Donr know about the function but you might try adding some error checking

For instance DriveSetLabel() returns 1 if success and 0 if fail, as does DriveMapDel()

I would start with checking those return values.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
jazzyjeff

Water,

Thanks for the response. I understand what you are saying about the drive label being used once.

I am currently using a Kix script with the MapDrive UDF that achieves the results. Unfortunately, the script takes a long time to finish executing (almost a minute). The AutoIT script finishes in seconds.

The time it completes the task is pretty critical as the teachers and students at my school assume everything is going to be ready as soon as they log in.

We set the labels on the drive because it made it easier for the users to see what drive they were looking at. Now that we have implemented, it will be tough to take away, as I can imagine a few people complaining.

I am going to try a suggestion in this article.

http://www.autoitscript.com/forum/index.php?showtopic=22041

I'll post a response when I get to test it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×