Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Login VB Script Amendment Issues

Posted on 2011-09-23
20
Medium Priority
?
283 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 10
20 Comments
 
LVL 39

Expert Comment

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

Regards,
Krzysztof
0
 
LVL 1

Author Comment

by:Flight5497
ID: 36586006
:) 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
ID: 36586083
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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 1

Author Comment

by:Flight5497
ID: 36586255
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 2000 total points
ID: 36586305
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
ID: 36586368
So I do not have to place a second variable for the second SELECT CASE?
0
 
LVL 39

Expert Comment

by:Krzysztof Pytko
ID: 36586424
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
ID: 36586756
Many thanks for your help I have emailed it over to you
0
 
LVL 39

Expert Comment

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

Krzysztof
0
 
LVL 1

Author Comment

by:Flight5497
ID: 36586816
No problems mate, again many thanks for all your help
0
 
LVL 39

Expert Comment

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

Krzysztof
0
 
LVL 1

Author Comment

by:Flight5497
ID: 36587271
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
ID: 36588818
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
ID: 36597854
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
ID: 36597897
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
ID: 36598289
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
ID: 36598411
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
ID: 36598459
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
ID: 36598471
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
ID: 36598512
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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
Group policies can be applied selectively to specific devices with the help of groups. Utilising this, it is possible to phase-in group policies, over a period of time, by randomly adding non-members user or computers at a set interval, to a group f…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

715 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