User Profile Login Script section in Active Directory?

Posted on 2005-05-02
Last Modified: 2008-08-05
This is actually a two piece question.  One is it possible to run more than one batch file/script in the User Profile: Login Script in Active Directory, or am I limited to one script per user (in the case I already have a script set in the User Profile: Login Script)?  

Second is it possible to assign a script to a Security Group?  Reason being is I have several OUs for separate departments (which I have scripts set in the GP for each department, mostly mapped drives) but have a Security Groups for Committees/Groups that span across several of these departments.  What I would like to do is set up a script to map shortcuts to shared folders for sharing their committee/group data.  Any help is welcome.  

Last thing, I've read in order to right a script to set up a shortcut you actually have to create the shortcut first , then copy that shortcut to the location you want on their computer?  Just a quick example of what I would like to do:

Server folder share path:
D:\Committee Folders\Management Team (Managment Team is shared folder)

What I would like to to create a shortcut to Management Team and place on the members desktop.
So what I would do is create shared folder to hold shorcuts that way the shortcuts aren't located in the shared folder:

D:\Committe Folder Shortcuts\Management Team.lnk (shortcut pointing to the Management Team folder)

;Delete the mapped drive
net use "T:" /d

;Setup a temp mapped drive for shortcut copy
net use "T:" \\Server\Committtee Folder Shortcuts

;Copy the shortcut if it isn't there
If Not Exist("%Userprofile%\Desktop\Management Team.lnk")
     copy "T:\\Server\Committee Folder Shortcuts\Management Team.lnk"  "%Userprofile%\Desktop"
End IF

;Clean out mapped drive thats not needed
net use "T:" /d

Please let me know if my logic looks right or if anything looks wrong.

Question by:HAC_ITS
    LVL 39

    Expert Comment

    that looks like it would work fine

    you can get logon scripts to run other scripts - just make the last line point to another script

    i have 5 different logon scripts, but only 1 printer script - 4 of the 5 logon scripts calls the printer script at the end

    Kix32 works wonders for things like this

    I am pretty sure that you can set up a policy which includes a logon script to selected members, but you can't directly make members of a security group run another script

    i have now used up the word script, and am banned from typing it anymore


    script script script
    LVL 6

    Expert Comment

    WSH/VBS code works really well in Windows 2000/XP/2003 :)

    I will post an example of it tomorrow.

    LVL 18

    Expert Comment

    I always recommend using group policy for login scripts vs. doing it on the accounts in AD if you are going to implement a script on a large scale basis. Meaning if you want more than just a couple of people to run the script then using group policy reduces the amount of work involved since you don't have to one by one add the script for each user. And it is so much easier to manage this way in case there needs to be changes made, it needs to be removed, etc.

    As far as mapping drives based on security groups.  You of course can't apply group policy direct to security groups. You can filter a policy so that only specific security groups will get the policy. Or you can do this in your script. I'll try to post an example of a vbs script that does this.  I map printers based on security groups using wsh/vbs and it is very simple to do.

    I like using wsh and vbs and mentioned by one post above. Its a matter of preference as to what you write your scripts in.....i seem to understand vbs more and feel more comfortable using it.
    LVL 6

    Accepted Solution

    'Declares variables used through-out the script

    DIM UserDriveLetter
    DIM drive
    DIM fso
    DIM message
    UserDriverLetter = "U:"

    'Removes previously mapped drives
    On error resume next

    Set oDrives = WshNetwork.EnumNetworkDrives
    For i = 0 to oDrives.Count - 1 Step 2
    WshNetwork.RemoveNetworkDrive oDrives.Item(i),true,true

    'Maps the User's Home directory

    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set wshNetwork = CreateObject("WScript.Network")
    Set fso = CreateObject("Scripting.FileSystemObject")

    wshNetwork.MapNetworkDrive "U:", "\\FILESERVER\" & wshNetwork.Username

    'Maps the pre-determined user directories

    wshNetwork.MapNetworkDrive "F:", "\\SERVER1\SHARE" & ""
    wshNetwork.MapNetworkDrive "H:", "\\SERVER1\ANOTHERSHARE" & ""
    wshNetwork.MapNetworkDrive "K:", "\\SERVER4\YETANOTHERSHARE" & ""
    wshNetwork.MapNetworkDrive "V:", "\\SERVER1\VIRUSDATSHARE" & ""

    'Maps Printers

    wshNetwork.AddWindowsPrinterConnection "\\SERVER1\PRINTER2"
    wshNetwork.AddWindowsPrinterConnection "\\SERVER2\PRINTER2"
    wshNetwork.AddWindowsPrinterConnection "\\SERVER1\PRINTER1"
    wshNetwork.AddWindowsPrinterConnection "\\SERVER3\PRINTER5"
    wshNetwork.SetDefaultPrinter "\\SERVER1\PRINTER2"

    'Runs Time Syncrhonization
    WshShell.Run ("\\SERVER\NETLOGON\time.vbs")

    'Calls AV update, place where Mcafee DAT files are downloaded daily.
    WshShell.Run ("V:\vupdate.exe /SILENT /PROMPT /F")

    'Displays Home Directory and Free Space

    Sub FindSpace(drive, message)
    DIM space
    DIM units

    space = drive.FreeSpace

    if space >= 1073741824 then
     space = Round(space / 1073741824, 2)
     units = "GB"
    elseif space >= 1048576 then
     space = Round(space / 1048576, 2)
     units = "MB"
    elseif space >= 1024 then
     space = Round(space / 1024, 2)
     units = "KB"
    end if

    message = message & vbCRLF & "You have " & space & " " & units & " free." & vbCRLF

    End Sub

    'Displays message to the user, will only display space left if disk quota is used.

    message = "User Directory Usage: " & vbCRLF

    Function ShowFreeSpace(UserDriveLetter)
       Dim fso, d, s
       Set fso = CreateObject("Scripting.FileSystemObject")
       Set d = fso.GetDrive(fso.GetDriveName(UserDriveLetter))
       s = "Drive " & UCase(UserDriveLetter) & " - "
       s = s & d.VolumeName   & "<BR>"
       s = s & "Free Space: " & FormatNumber(d.FreeSpace/1024, 0)
       s = s & " Kbytes"
       ShowFreeSpace = s
    End Function

    MsgBox message, , "Welcome to the Domain, " & wshNetwork.UserName

    The time.vbs:

    DIM fso
    DIM WshShell
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set fso = WScript.CreateObject("Scripting.FileSystemObject")

    WshShell.Run("%COMSPEC% /c net time \\\\TIMESERVER /set /y")

    If you have alot of users, it's better to setup the scripts like luv2smile suggested.  However, if you only deal with alimited amout of users, you can use user profiles.



    Author Comment

    I've just been using batch files (.bat) for scripts so using WSH/VBS would be new to me.  Could you point me in the direction for starting to go that route BILJAX or anyone else.

    LVL 6

    Expert Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    We recently endured a series of broadcast storms that caused our ISP to shut us down for brief periods of time. After going through a multitude of tests, we determined that the issue was related to Intel NIC drivers on some new HP desktop computers …
    I'm a big fan of Windows' offline folder caching and have used it on my laptops for over a decade.  One thing I don't like about it, however, is how difficult Microsoft has made it for the cache to be moved out of the Windows folder.  Here's how to …
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now