Windows Server - Login script with drive mappings based on DL
Asked By Paco7
29-Nov-07 09:52 AM
I am trying to write a login script for the company I work for and I want to
run a different section of th escript based on the membership of a DL.
I was using IFMEMBER, but that only works on security groups.
Does anyone know how I can accomplish this, without having to create
duplicate security groups for the various DL I was hoping to use?
I am using a good old fashioned batch file, not VB Script (I don't know VB).
Example:
(text is wrapped, there is only 1 space between IFMEMBER.EXE and Domain\group)
%logonserver%\netlogon\Process\IFMEMBER.EXE DOMAIN\___Office-Coppell_TX___
IF ERRORLEVEL 1 goto CP_LAUNCH
This is just bypassed since this is a DL, I have tested my script with a
security group and it works, so I know the script is ok.
Even a way to use an AD attribute to run specific areas of the script, such
as the physicalDeliveryOfficeName attribute, since I have that populated in
AD.
--
Thanks,
Paco
Active Directory
(1)
Office
(1)
VB
(1)
ObjNetwork.MapNetworkDrive
(1)
ObjSysInfo.UserName
(1)
Wscript.Network
(1)
PhysicalDeliveryOfficeName
(1)
ObjGroup.IsMember
(1)
Richard Mueller [MVP] replied...
A batch file cannot retrieve information from Active Directory unless you
use third party tools like IfMember.exe. Perhaps you can use a command line
tool, like dsquery or Joe Richards' adfind or MemberOf. You may need to
retrieve the NT name of the user, from the %username% environment variable,
then use that in a query. See these links for Joe's tools:
http://joeware.net/freetools/tools/adfind/index.htm
http://www.joeware.net/freetools/tools/memberof/index.htm
--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
Paco7 replied...
I actually already tried the ifmember and was able to get it to dump the
distribution list, but I couldn't figure out how to use that in a script.
Also, I am pleased that you responded, I have used your site for many years
and continue to check back for good stuff!
I think I have found something that will work for me on
http://cswashington.netreach.net and was wondering if you could give me your
opinion on it?
http://cwashington.netreach.net/depo/view.asp?Index=246&ScriptType=vbscript
--
Thanks,
Paco
Richard Mueller [MVP] replied...

The script you linked will work, but it is VBScript. It shows how VBScript
can retrieve the value of any single-valued string attribute, parse it, and
use it to make decisions in VBScript.
Of course if you are using VBScript, I still think it makes sense to use
group membership. If you are not concerned with group nesting, and you just
want to know if the user is a direct member of a group, the code can be
relatively simple. For example:
==========
Set objNetwork = CreateObject("Wscript.Network")
' Bind to current user object.
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
' Bind to group to test membership.
Set objGroup = GetObject("LDAP://cn=TestGroup,ou=West,dc=MyDomain,dc=com")
' Check membership.
If (objGroup.IsMember(objUser.AdsPath) = True) Then
' The current user is a member of the group. Map a drive.
objNetwork.MapNetworkDrive "K:", "\\MyServer\GroupShare"
End If
===========
I use the LDAP provider because it is faster and reveals many more
attributes. The cwashington script uses the WinNT provider, which can be
easier to understand. My script above requires Windows 2000 or above (for
the ADSystemInfo object) while the cwashington script requires Windows 95
(and DSClient). My script can be revised to support Win9x as well. Other
differences are a matter of style, although I would recommend not using "On
Error Resume Next" as it makes troubleshooting nearly impossible. Note that
the IsMember method of the group object that I use in my example works for
both security and distribution groups. It will not reveal membership in the
--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
Paco7 replied...
Good info, thanks. I want to use membership of a Distribution List to
determine what drives get mapped, the problem is I have found nothing that
will allow me to do that. Everything I have see, and used over the years,
only allows parsing security groups for that membership, not even mail
enabled security groups.
--
Thanks,
Paco
Al Dunbar replied...
Interesting, but it seems unusual to use non-security enabled objects to
arbitrate access. Once mapped, of course, the user will still need access to
the underlying folders, or there wouldn't be much point.
/Al
Paco7 replied...
I agree, and they do have the access to the various drives to be mapped just
not applied by a single security group; and I was trying to avoid having to
create a security group with the same membership as the various site specific
DL.
I guess worst case I can use an ldap dump periodically to dump the DL
membership and then another to update the security group membership.
Thanks to all who replied.
--
Thanks,
Paco

Event id 2042 / 2041 (Directory service) + 12292 / 11 (VSS) Windows Server Hi, I am getting lots of event logs in all 3 domain controllers recently. First of all in Directory service, I am getting these event id 2042 & 2041 as below: { Event Type: Error Event controllers when I try to use backup utility to backup anything: {Backup Status Operation: Backup Active backup destination: File Media name: "Volume 2 Backup.bkf created 10 / 15 / 2008 at 2 me. I really appreciate any reply. Thanks in advance. With best regards, Hemal Windows Server Active Directory Discussions HPSERVER.kbgca.local (1) Volume Shadow Copy Service (1) Active Directory (1) Windows Server (1) RIDNextRID (1) RIDPreviousAllocationPool (1) CheckSDRefDom (1) Dellserver.kbgca.local (1) Hi a252-4c11bf6117e5 Last attempt @ 2008-10-15 18:08:02 failed, result 8614 (0x21a6): The Active Directory cannot replicate with this server because the t ime since the last replication with
could be causing this? Thanks Jason Windows Server Discussions ObjNetwork.RemoveNetworkDrive (1) ObjNetwork.EnumNetworkDrives (1) ObjNetwork.MapNetworkDrive (1) ObjSysInfo.UserName (1) Wscript.Network (1) ObjUser.samAccountName (1) ObjUser.MemberOf (1) ObjUser.GetEx (1) Here are MAPS TO THE SECURE USER FOLDER BASED ON THE USERNAME '- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Set objSysInfo = CreateObject("ADSystemInfo") strUser = objSysInfo.UserName Set objUser = GetObject("LDAP: / / " & strUser) strUserName = objUser.samAccountName strOUPath = objUser.Parent arrContainers = Split(strOUPath, ", ") arrOU arrContainers(0), " = ") strOU = arrOU(1) strDrive = " \ server02 \ Secure Folder - "& strUserName Set objNetwork = CreateObject("Wscript.Network") objNetwork.MapNetworkDrive "A:", strDrive '- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 'MAPS THE GROUP DRIVES '- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Set objSysInfo = CreateObject("ADSystemInfo") Set objNetwork = CreateObject("Wscript.Network
Profile: http: / / forums.techarena.in / members / 169993.htm View this thread: http: / / forums.techarena.in / active-directory / 1288776.htm http: / / forums.techarena.in Windows Server Active Directory Discussions Windows Server 2008 R2 (1) Windows Server 2008 (1) Active Directory (1) NetBIOS (1) ProcessingTimeInMilliseconds (1) EventRecordID (1) DNSLint (1) FRSUtil (1) GPResult from GPUpdate and Profile: http: / / forums.techarena.in / members / 169993.htm View this thread: http: / / forums.techarena.in / active-directory / 1288776.htm http: / / forums.techarena.in TBaze, Two quick things: 1) Windows Firewall turned on
12-02 10:05:15+1100 620 264 Trying to make out of proc datastore active 2008-12-02 10:05:15+1100 620 264 Out of proc datastore is now active 2008-12-02 10:05:15+1100 620 264 Out of proc datastore is shutting 12-02 10:05:15+1100 712 364 Trying to make out of proc datastore active 2008-12-02 10:05:16+1100 712 364 Out of proc datastore is now active 2008-12-02 10:05:16+1100 712 364 Out of proc datastore is shutting 12-02 10:05:16+1100 992 3e4 Trying to make out of proc datastore active 2008-12-02 10:05:16+1100 620 264 Out of proc datastore is now 2008-12-02 10:05:16+1100 992 3e4 Out of proc datastore is now active 2008-12-02 10:05:16+1100 992 3e4 Out of proc datastore is shutting 12-02 10:35:17+1100 1632 a4 Trying to make out of proc datastore active 2008-12-02 10:35:18+1100 1632 a4 Out of proc datastore is now active 2008-12-02 10:35:18+1100 1632 a4 Out of proc datastore is shutting
Wait" thanks Windows Group Policy Discussions ADODB.Connection (1) ADODB.Command (1) ObjADObject.sAMAccountName (1) Active Directory (1) ObjADObject.GetInfoEx (1) StrNetBIOSDomain (1) ADsDSOObject (1) Vista (1) Hello Rick, see inline Best objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & " \ " & strNTName strUserDN = objTrans.Get(ADS_NAME_TYPE_1779) ' Bind to the user object in Active Directory with the LDAP provider. Set objUser = GetObject("LDAP: / / " & strUserDN) ' Map user home directory. strHomeShare = objUser.homeDirectory If strHomeShare <> "" Then strHomeDrive = objUser.homeDrive If strHomeDrive = "" Then strHomeDrive = "J:" End If On Error Resume Next objNetwork.MapNetworkDrive strHomeDrive, strHomeShare wscript.sleep 1000 If Err.Number <> 0 Then On Error GoTo 0 objNetwork.RemoveNetworkDrive strHomeDrive, True, True wscript.sleep 1000 objNetwork.MapNetworkDrive strHomeDrive, strHomeShare End If On Error GoTo 0 End If ' Map a network drive