Solved

Login VB Script Amendment Issues

Posted on 2011-09-23
20
276 Views
Last Modified: 2012-05-12
Hi Experts,

We at present have 2 login scripts. The first script will basically map drives based on the AD groups they are in, and the other will map printers based on what floor group they are in.

The problem I am presented with is that we will soon be placing in a load of new printers and there will be two instances of these printers one that will be able to printing in only black and white and the other that will be able to print in colour.  

Not all users on say the 2nd floor will be allowed to print to the colour printer. So as you can see from the printer mapping code snippet attached we pull in the groups that they are in and then use SELECT CASE now I want to place a conditional statement under each floor CASE statement that if they are also in a group called colour-printing then map the colour printer for their particular floor.

Now my VBS is limited and I tried placing an IF THEN conditional statement under the CASE statement for the 5th Floor but it does not pick it up, it just ignores it and carries on with the rest of the script.

Am I doing something wrong? and if so what is the best way to tackle this.
code.txt
0
Comment
Question by:Flight5497
  • 10
  • 10
20 Comments
 
LVL 39

Expert Comment

by:Krzysztof Pytko
Comment Utility
Did you consider placing Case statement within existing CASE ? Put it in appropriate case option :)

Regards,
Krzysztof
0
 
LVL 1

Author Comment

by:Flight5497
Comment Utility
:) right see what I mean by my VB Scripting is limited it is really going to be that simple isn't it :)

Just to make sure I have the code right would I be placing another SELECT CASE under the CASE "PRINTERS-5THFLOOR"?

Kind Regards
0
 
LVL 39

Expert Comment

by:Krzysztof Pytko
Comment Utility
Yes, that's right. In example

Case "PRINTERS-5THFLOOR"

    Select Case <new-case-statement>

       Case <statement>
       .....
       .....

    End Select

....
Err.Clear

End Select (main)

Krzysztof
0
 
LVL 1

Author Comment

by:Flight5497
Comment Utility
Unfortunately it is still not working for whatever reason

This is the code I have used inside the case:

For each UserGroup in objUserGroups
      strGroupName = UCase(UserGroup.Name)

Select Case strGroupName

Case "PRINTERS-5THFLOOR"
      Select Case strGroupName
            CASE "COLOUR-PRINTING"
                  objNetwork.AddWindowsPrinterConnection "\\servername\Phaser7500D_5thfloor"
            End Select
                  
      objNetwork.AddWindowsPrinterConnection "\\servername\canonir2270_5thfloor"
      objNetwork.AddWindowsPrinterConnection "\\servername\canonirc2880_4thfloor"
      objNetwork.AddWindowsPrinterConnection "\\servername\CanonIR2270-Fax5thfloor"
      Err.Clear
                  
End Select '(Main)

The code at the upper part of the file states what the variable will hold, and i have left as is and just reused that variable below, I have also defined another variable called strGroupName2 and added an additional line after the foreach giving strGroupName2 and used that different variable down within the new case statement but that did not work either. i am puzzled.
 

0
 
LVL 39

Accepted Solution

by:
Krzysztof Pytko earned 500 total points
Comment Utility
Try to use this instead of yours :)

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

Select Case strGroupName

case "group-name"
....


Krzysztof
0
 
LVL 1

Author Comment

by:Flight5497
Comment Utility
So I do not have to place a second variable for the second SELECT CASE?
0
 
LVL 39

Expert Comment

by:Krzysztof Pytko
Comment Utility
Nope, you don't have to. If you wish, you can send me this script on my e-mail at kpytko at go2 dot pl and I resend it corrected back to you :)

Krzysztof
0
 
LVL 1

Author Comment

by:Flight5497
Comment Utility
Many thanks for your help I have emailed it over to you
0
 
LVL 39

Expert Comment

by:Krzysztof Pytko
Comment Utility
No problem :)
Thanks, I've got it :) Need some time and resend it back to you :)

Krzysztof
0
 
LVL 1

Author Comment

by:Flight5497
Comment Utility
No problems mate, again many thanks for all your help
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 39

Expert Comment

by:Krzysztof Pytko
Comment Utility
No problem. OK, I set example syntax in your VBS. Let's check your e-mail :)

Krzysztof
0
 
LVL 1

Author Comment

by:Flight5497
Comment Utility
It is a real pain this script I still could not get it to work I place my group I have created and assigned to only the users that are allowed to print in colour on the 5th floor.

i uncommented the printers for the 5th floor you commented out because i would like them put in as they are 5th floor printers then I simply added the group name in AD which is COLOUR-PRINTING, and then placed in the printer to map.

I ran the script it came up with no errors but still did not put the printer in. The second I reverted the script back to its original, it placed the printer back.

So it definitely seems to be skipping over the code for whatever reason and I am unsure as to why!

Sorry to be a continuing pain :)
0
 
LVL 39

Expert Comment

by:Krzysztof Pytko
Comment Utility
OK, that's no problem. We will figure it out :) If you can wait until Monday, that would be good :) I need my environment to check and validate this script.

So, see you on Monday at EE :D

Krzysztof
0
 
LVL 1

Author Comment

by:Flight5497
Comment Utility
Sorry I have not replied sooner, yeah today is fine look forward to getting this solved with your help :) speak to you later on today.
0
 
LVL 39

Expert Comment

by:Krzysztof Pytko
Comment Utility
OK, now it works in my env. Can you test it?

It was necessary to implement new variable for sub Select groups. I used strGroup for main Select Case and strGroup2 for sub Select.

I also removed Option Explicit which caused that script didn't want to work.

Check your e-mail :)

Regards,
Krzysztof
0
 
LVL 1

Author Comment

by:Flight5497
Comment Utility
You sir are a legend!!!

I just tried this and it worked a treat. So I presume I just do the same thing for the other floors sub selects?

Would I have to have a different strGroup for each sub select under the relevant floors i.e. strGroup3 etc?
0
 
LVL 39

Expert Comment

by:Krzysztof Pytko
Comment Utility
Hi, great! Yes, you need sub Select for each floor and unfortunately new variable for all of them :( But there is not so much to do :)

Regards,
Krzysztof
0
 
LVL 1

Author Comment

by:Flight5497
Comment Utility
Brilliant mate I will get get that done.

Thank you so much for your help, you are a credit to this site and the reason why people think this is the best resource on the web!

Thanks for going above and beyond mate, it is really appreciated.
0
 
LVL 39

Expert Comment

by:Krzysztof Pytko
Comment Utility
You're welcome :) I'm glad that it works for you :)
and thank you for compliment ;)

Have a nice day.

Krzysztof
0
 
LVL 1

Author Comment

by:Flight5497
Comment Utility
For those using this as a reference and knowledge base for their own similar scripting requirement I have attached a snippet of the code, provided to me by iSiek.

I hope this helps you all as much as it helped me. Again many thanks iSiek really appreciate your help.  



On Error Resume Next

Set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = CreateObject("WScript.Network")
Set objShell = CreateObject("WScript.Shell")
Set objSysEnv = objShell.Environment("SYSTEM")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
Set objFSO = CreateObject("Scripting.FileSystemObject")

strDomain = LCase(objNetwork.UserDomain)
strUser = LCase(objNetwork.UserName)

For Each strGroup in objUser.MemberOf

  strGroupPath = "LDAP://" & strGroup
  Set objGroup = GetObject(strGroupPath)
  strGroupName = LCase(objGroup.CN)
  
  Select Case strGroupName
  
   Case "printers-5thfloor"
    objNetwork.AddWindowsPrinterConnection "printer path"
    objNetwork.AddWindowsPrinterConnection "printer path"
    objNetwork.AddWindowsPrinterConnection "printer path"
    
      For Each strGroup2 in objUser.MemberOf
        strGroupPath = "LDAP://" & strGroup2
        Set objGroup = GetObject(strGroupPath)
        strGroupName = LCase(objGroup.CN)
        
        Select Case strGroupName
      
        Case "colour-printing"
        objNetwork.AddWindowsPrinterConnection "printer path"
        
        End Select
      
      Next

  End Select  
Next

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Synchronize a new Active Directory domain with an existing Office 365 tenant
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…

771 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

14 Experts available now in Live!

Get 1:1 Help Now