Link to home
Start Free TrialLog in
Avatar of Flight5497
Flight5497

asked on

Login VB Script Amendment Issues

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
Avatar of Krzysztof Pytko
Krzysztof Pytko
Flag of Poland image

Did you consider placing Case statement within existing CASE ? Put it in appropriate case option :)

Regards,
Krzysztof
Avatar of Flight5497
Flight5497

ASKER

:) 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
Yes, that's right. In example

Case "PRINTERS-5THFLOOR"

    Select Case <new-case-statement>

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

    End Select

....
Err.Clear

End Select (main)

Krzysztof
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.
 

ASKER CERTIFIED SOLUTION
Avatar of Krzysztof Pytko
Krzysztof Pytko
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So I do not have to place a second variable for the second SELECT CASE?
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
Many thanks for your help I have emailed it over to you
No problem :)
Thanks, I've got it :) Need some time and resend it back to you :)

Krzysztof
No problems mate, again many thanks for all your help
No problem. OK, I set example syntax in your VBS. Let's check your e-mail :)

Krzysztof
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 :)
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
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.
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
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?
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
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.
You're welcome :) I'm glad that it works for you :)
and thank you for compliment ;)

Have a nice day.

Krzysztof
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