Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

logon script in VBS


  • Please log in to reply
3 replies to this topic

#1 hispaladin

hispaladin

  • Members
  • 245 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Middle of a corn field
  • Local time:05:00 PM

Posted 23 May 2013 - 04:42 PM

I am working on a logon script in VBScript and am having trouble.  The script I am making is just to map drives for the users.  We have three catagories of users that need drives mapped, domain users (everyone), accounting, and domain admins.  the domain users will get the home directory mapped as well as the public directory, the accounting users will also get the accounting share mapped, and the domain admins will get the accounting and apps share mapped.   The script works fine on my computer (win 8) as I am a domain admin and if I add myself to the accounting group it will run fine as that also.  However if I run the script on a WinXP machine under a user in the accounting group i get a type mismatch error at line 19 at the word "Join".  any ideas why this is happening?  I really don't know much at all about VBScript so most of this I have found online and pieced together what I wanted.  Here is the script I am using

 

on error resume next
 
Const accounting     = "cn=accounting"
Const admin         = "cn=domain admins"
 
Set objNetwork = CreateObject("Wscript.Network")
 
'objNetwork.RemoveNetworkDrive "H:", True, True
objNetwork.RemoveNetworkDrive "P:", True, True 
objNetwork.RemoveNetworkDrive "K:", True, True
objNetwork.RemoveNetworkDrive "J:", True, True
 
Set wshNetwork = CreateObject("WScript.Network")
'wshNetwork.MapNetworkDrive "h:", "\\server2\home\" & wshNetwork.UserName
wshNetwork.MapNetworkDrive "p:", "\\server2\public"
 
Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
strGroups = LCase(Join(CurrentUser.MemberOf))
 
If InStr(strGroups, accounting) Then
 
    wshNetwork.MapNetworkDrive "j:", "\\server2\accounting"
 
ElseIf InStr(strGroups, admin) Then
 
    wshNetwork.MapNetworkDrive "j:", "\\server2\accounting"
    wshNetwork.MapNetworkDrive "k:", "\\server2\apps\agris"
 
 
End If

 



BC AdBot (Login to Remove)

 


#2 hispaladin

hispaladin
  • Topic Starter

  • Members
  • 245 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Middle of a corn field
  • Local time:05:00 PM

Posted 24 May 2013 - 02:56 PM

OK got it working, turns out that if the user is a part of only one or two security groups then (CurrentUser.MemberOf) will not be an array which means LCase(Join(CurrentUser.MemberOf)) will not work.  One has to put in a If Then Else switch to determine if it is an array or not.  If it is not then you would use LCase(CurrentUser.MemberOf)  leaving off the extra () with Join in there.  here is the finished script that now works fine.

 

 

on error resume next
 
Const accounting     = "cn=accounting"
Const admin         = "cn=domain admins"
 
Set objNetwork = CreateObject("Wscript.Network")
 
objNetwork.RemoveNetworkDrive "P:", True, True 
objNetwork.RemoveNetworkDrive "K:", True, True
objNetwork.RemoveNetworkDrive "J:", True, True
 
Set wshNetwork = CreateObject("WScript.Network")
wshNetwork.MapNetworkDrive "p:", "\\agpfile\public"
 
Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
 
If IsArray(CurrentUser.MemberOf) Then
  strGroups = LCase(Join(CurrentUser.MemberOf))
Else
  strGroups = LCase(CurrentUser.MemberOf)
End If
 
If InStr(strGroups, accounting) Then
 
wshNetwork.MapNetworkDrive "j:", "\\server2\accounting"
 
ElseIf InStr(strGroups, admin) Then
 
wshNetwork.MapNetworkDrive "j:", "\\server2\accounting"
wshNetwork.MapNetworkDrive "k:", "\\server2\apps"
 
End If

 

 

And apparently VBScript is kind of picky about capitalization because I had that first If Then Else switch in all lower case and it would not take it.



#3 KamakaZ

KamakaZ

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:09:00 AM

Posted 16 July 2013 - 01:53 AM

Wouldn't this cause a problem if you had another group called "accountingSomething" for example (something starting with accounting), the user may not be a part of the "accounting" group but the InStr() will still return true?

 

Would it be better to join with some random character that is not likely to be in one of the group names and check for the full name? ie: "cn=accounting[random character here]"


There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.


#4 hispaladin

hispaladin
  • Topic Starter

  • Members
  • 245 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Middle of a corn field
  • Local time:05:00 PM

Posted 16 July 2013 - 08:04 AM

On that I honestly don't know.  I did some digging and found that server 2008 supports group policy objects (I think that is what its called) where you can set all that up so I ditched the script and used that instead.  Which for the record works well on everything newer than XP and it will work on XP you just have to add something to the machine locally (which I don't remember off hand what).






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users