Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ERROR: Login script for Mapped drives ...

Status
Not open for further replies.

MojoZig

Technical User
Sep 27, 2005
61
US
Ok, I am really having a tough time with this and need some help cleaning it up and fixing my error. This code is supposed to connect to LDAP and map the user's department S: drive and Division T: drive. The code works if you are getting an S: and T: but if the user doesn't have a Division, nothing gets mapped on my full script I run, on this one I get an error.

So I broke the entire full script down to just this portion. This is what happens: If my test user is in the first listed group only "COO_AP_Airport", the scirpt errors with "Line: 11 Char:1 Object not a collection" If I un-Rem the DIM line, same error ...

If the user IS a member of both groups below, they both get mapped properly. (The full script has many more departments and divisions)

Can anybody assist me please?? Line 11 is: "For Each strGroup in objUser.MemberOf"

Should the line to DIM those items be there or not and how do I fix it to where if the user is in only one group that one group gets mapped?


Code:
' VB Script Document

'These next lines connect to LDAP

'DIM strUserPath, strGroup, objUser, objSysInfo, strGroupPath, objGroup, strGroupName, objNetwork

Set objNetwork = CreateObject("WScript.Network")
Set objSysInfo = CreateObject("ADSystemInfo")
strUserPath = "LDAP://" & objSysInfo.UserName
Set objUser = GetObject(strUserPath)

For Each strGroup in objUser.MemberOf
    strGroupPath = "LDAP://" & strGroup
    Set objGroup = GetObject(strGroupPath)
    strGroupName = objGroup.CN

   
on error resume next     

    Select Case strGroupName


   Case "COO_AP_Airport"
objNetwork.MapNetworkDrive "S:", "\\chldept\Drive\Airport"

   Case "COO_AP_Administration"
objNetwork.MapNetworkDrive "T:", "\\chldept\Drive\Airport\COO_AP_Administration"            

         End Select   

    Next
 
Hey, yall wanna see an even better script. I like to call it .. DUN DUN DUN.... <evil background music plays>


logonscript.bat


Code:
net use m: \\server\share
net use n: \\server\share\user\%username%
net use o: \\server2\publicdata
Mine runs WAAAAAAAAAAAAAAAAAAAY faster than all of your fancy vbscripts do.

JUST KIDDING! Have to stir the pot every now and again! Actually I am a vbscript freak and have changed all the batch files that we used to used to map 10 different offices and 10 different sites into 1 very nice vbscript. It uses a select case structure to determine the OU the user is in. I don't like that, but the method that the company uses to transfer users entails moving them to a different OU. How dumb. Group membership would be a nicer solution, but you work with what you're given right? And YES you do need On Error Resume Next a lot of times when vbscripting because if you don't use it the scripts can bomb out when it sees a NULL somewhere. You can check for the NULL, but if you've proven it doesn't matter than just resume next.


Steve
Systems Engineer
 
Mark,
How's it going? got a question for you in your script. I'm afraid that this will show my level of incompitance but i'll ask anyway!

In your script you grab the PC name:

'Grab the computer name for use in add-on code later
strComputer = WSHNetwork.ComputerName

In my addin portion, I have a line that puts the hosts file on each machine:

Code:
Const OverwriteExisting = TRUE
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "\\server\updates$\hosts", WshShell.ExpandEnvironmentStrings("%systemroot%\system32\drivers\etc\"), OverwriteExisting

I have a new issue where a certain set of PCs (7 of them) can't get this host file now since an application they use dynamically updates the file.

I was going to pull those PCs from their home OU, but first wanted to try something on the script. Didn't know if an "else if", "for each" or an array would be what I need to use, I'm thinking an array:

If the strComputer name is in the array, it shouldn't get the hosts file, if the strComputer name is not in the array, it should get the host file ...

For... Each might work as well. Just didn't want to muck up my script you created!

Thoughts?

MojoZig ...
 
Nevermind, I'm going to just remove the hosts file all together since we do not really need to push it down each time. That's an easy fix!

MZ
 
Good solution. If you DID need to do something with it, let me know (in a new thread) and I can give you some sample code to EDIT the existing file rather than replace it.

I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top