Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 284
  • Last Modified:

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
0
Flight5497
Asked:
Flight5497
  • 10
  • 10
1 Solution
 
Krzysztof PytkoActive Directory EngineerCommented:
Did you consider placing Case statement within existing CASE ? Put it in appropriate case option :)

Regards,
Krzysztof
0
 
Flight5497Author Commented:
:) 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
 
Krzysztof PytkoActive Directory EngineerCommented:
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
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
Flight5497Author Commented:
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
 
Krzysztof PytkoActive Directory EngineerCommented:
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
 
Flight5497Author Commented:
So I do not have to place a second variable for the second SELECT CASE?
0
 
Krzysztof PytkoActive Directory EngineerCommented:
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
 
Flight5497Author Commented:
Many thanks for your help I have emailed it over to you
0
 
Krzysztof PytkoActive Directory EngineerCommented:
No problem :)
Thanks, I've got it :) Need some time and resend it back to you :)

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

Krzysztof
0
 
Flight5497Author Commented:
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
 
Krzysztof PytkoActive Directory EngineerCommented:
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
 
Flight5497Author Commented:
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
 
Krzysztof PytkoActive Directory EngineerCommented:
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
 
Flight5497Author Commented:
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
 
Krzysztof PytkoActive Directory EngineerCommented:
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
 
Flight5497Author Commented:
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
 
Krzysztof PytkoActive Directory EngineerCommented:
You're welcome :) I'm glad that it works for you :)
and thank you for compliment ;)

Have a nice day.

Krzysztof
0
 
Flight5497Author Commented:
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 Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 10
  • 10
Tackle projects and never again get stuck behind a technical roadblock.
Join Now