+ Post New Thread
Page 3 of 4 FirstFirst 1234 LastLast
Results 31 to 45 of 56
Windows Thread, Login script problem in Technical; I assign printers based on computer OU membership. Basically, it's all done using the ADSI extensions. You can get the ...
  1. #31
    ajbritton's Avatar
    Join Date
    Jul 2005
    Location
    Wandsworth
    Posts
    1,632
    Thank Post
    23
    Thanked 75 Times in 45 Posts
    Rep Power
    34

    Re: Login script problem

    I assign printers based on computer OU membership. Basically, it's all done using the ADSI extensions.

    You can get the full computer path from ADSystemInfo.ComputerName and then check for the presence of particular OUs.

    Code:
    dim oAdSysInfo, sCompPath
    set oAdSysInfo = CreateObject("AdSystemInfo")
    sCompPath = oAdSysInfo.ComputerName
    if InStr(1, sCompPath, "OU=ICT Suite", 1) then 
      ' Code here to map printer(s) for ICT Suite
    end if

  2. #32

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,807
    Thank Post
    3,320
    Thanked 1,056 Times in 977 Posts
    Rep Power
    365

    Re: Login script problem

    I've heard lots of good things about python , never tried it myself. Maybe one of you could point me in the direction of where to get it from, how to configure it, tutorials etc etc , that would be nice as I would like to give it a go.

    As for scripting, try admin script editor here :

    http://www.adminscripteditor.com/main.asp

    Just on my lunch break so not much time to look around for printer scripts etc. I posted on here with my printer script on the same thread as RIC's printer script so would be worth while checking that out as I did a select case with some other things

  3. #33

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,807
    Thank Post
    3,320
    Thanked 1,056 Times in 977 Posts
    Rep Power
    365

    Re: Login script problem

    @ ajbritton, any chance you could post your printer script here ( that or attach it ) so that I could have a look at it later on.

    thx

  4. #34

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,804
    Thank Post
    110
    Thanked 583 Times in 504 Posts
    Blog Entries
    1
    Rep Power
    224

    Re: Login script problem

    I've heard lots of good things about python , never tried it myself. Maybe one of you could point me in the direction of where to get it from, how to configure it, tutorials etc etc , that would be nice as I would like to give it a go.
    These links should get you going:

    http://www.activestate.com/Products/ActivePython/
    http://www.die-offenbachs.de/detlev/eric3.html
    http://docs.python.org/tut/tut.html

  5. #35
    ajbritton's Avatar
    Join Date
    Jul 2005
    Location
    Wandsworth
    Posts
    1,632
    Thank Post
    23
    Thanked 75 Times in 45 Posts
    Rep Power
    34

    Re: Login script problem

    As I think I mentioned earlier, my logon script is a bit stupidly big, but the essence of what you need to do is here. I've added some comments

    Code:
    ' Declare object variables
    dim oAdSysInfo, sCompPath
    
    ' Create the AdSystemInfo object
    set oAdSysInfo = CreateObject("AdSystemInfo")
    
    ' Create the Wscript.Network object
    set oWshNet = CreateObject("Wscript.Network")
    
    ' Obtain the full path to the computer account
    sCompPath = oAdSysInfo.ComputerName
    
    ' Check to see if the computer is in (or below) a particular OU
    if InStr(1, sCompPath, "OU=ICT Suite", 1) then
      ' Add a printer connection based on computer OU membership
      oWshNet.AddWindowsPrinterConnection "\\ServerName\PrinterShareName"
    end if
    Hope this helps

  6. #36

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,807
    Thank Post
    3,320
    Thanked 1,056 Times in 977 Posts
    Rep Power
    365

    Re: Login script problem

    I havent really used InStr that much , InStrRev I used once. This is a long shot but if you dont ask you dont get ( And in some cases at least with me I dont get even when I ask lol ) but any chance you could incorporate that into this script so that It works with my script.

    Preferably put the Check to see if the computer is in an OU into a function so that I can call it when needed.

    Please find my script attached as a txt file
    Last edited by mac_shinobi; 27th August 2008 at 02:46 PM.

  7. #37

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,807
    Thank Post
    3,320
    Thanked 1,056 Times in 977 Posts
    Rep Power
    365

    Re: Login script problem

    What can python be used for and does it have a steep learning curve ?

  8. #38
    ajbritton's Avatar
    Join Date
    Jul 2005
    Location
    Wandsworth
    Posts
    1,632
    Thank Post
    23
    Thanked 75 Times in 45 Posts
    Rep Power
    34

    Re: Login script problem

    Gecko.. Please don't take this the wrong way, but from looking at your script (and the fact that you've asked me to help you with it) I'm guessing that you're still learning VB Script. I think the best way of learning is by doing, so rather than rewrite your script, I'll try to help you along the way as follows...

    The InStr function is just like the InStrRev function, except that it starts looking for the for the substring from the beginning of the source string, rather than from the end, so...
    Code:
    TwoPos = InStr("12345678987654321", "2")
    ...returns the value 2

    Whereas...
    Code:
    TwoPos = InStrRev("12345678987654321", "2")
    ...returns the value 14

    Here's the function to determine if a computer is in an OU. You can just add the function to the end of your existing script.
    Code:
    Function IsComputerInOu(sOU)
      dim oAdSysInfo, sComputerDN
      set oAdSysInfo = CreateObject("AdSystemInfo")
      sComputerDN = oAdSysInfo.ComputerName
      IsComputerInOu = (InStr(1, sComputerDN, "OU=" & sOU, vbTextCompare) > 0)
    End Function
    Usage: IsComputerInOU(<OU Name>)
    Returns: True if computer account is in or below an OU with the name 'OU Name'
    Example:
    Code:
    If IsComputerInOu("IT1") Then
      oWshNet.AddPrinterConnection("\\cse2k01\KyoceraM")
    end if
    The function works because of what is returned by the AdSystemInfo.ComputerName method. This returns not just the Computer Name, but the Distinguished Name (DN) (see RFC 1779) of the computer account object. If you imagine that your computer is call IT1-01, that it is in an OU called IT1, which in turn is in an OU called Computers, which is in the domain School.Local, then the Distinguished Name (DN) of the computer account object would be
    Code:
    cn=IT1-01,ou=IT1,ou=Computers,dc=School,dc=Local
    It's then a simple matter to use InStr to see if, for instance the string 'ou=IT1' exists in the full DN string. If it does, then computer account is in (or below) the IT1 OU.

  9. #39

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,807
    Thank Post
    3,320
    Thanked 1,056 Times in 977 Posts
    Rep Power
    365

    Re: Login script problem

    I understand that ( glad you chose to do it this way actually because you are totally right about learning more when you do it ) so defintly no hard feelings there and appreicate the help as well

    With regards to this :

    Whereas...
    Code:
    TwoPos = InStrRev("12345678987654321", "2")

    would return 14

    Surely it would return 2 and not 14 since it is going from the end to the begining and if you look at the string of numerical values you will see that the number 2 is the 2nd one in from the end even though there is another 2 at the beginging.

    Might be wrong on that point but just wanted to confirm

  10. #40

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,804
    Thank Post
    110
    Thanked 583 Times in 504 Posts
    Blog Entries
    1
    Rep Power
    224

    Re: Login script problem

    Quote Originally Posted by gecko
    What can python be used for and does it have a steep learning curve ?
    Off the top of my head:

    - Shell scripting on various flavors of *nix.
    - Scripting language for various applications (XChat, the IRC client I use for example).
    - Scripting language for some games. Large chunks of Eve Online and Unreal Tournament are written in Python.
    - Alternative to PHP/Perl/ASP/etc for running your website.
    - Entire applications can be written in python. The Eric Python IDE I linked to above is written in Python (somewhat paradoxical!)

    Now as far as scripting under windows goes. It can do anything VB scripts can. AD intergration, WMI queries, you name it.

  11. #41

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,807
    Thank Post
    3,320
    Thanked 1,056 Times in 977 Posts
    Rep Power
    365

    Re: Login script problem

    program itself to make me lots of money ? lol Just felt like adding another paradoxical thing in there I wish it did though )

  12. #42

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,807
    Thank Post
    3,320
    Thanked 1,056 Times in 977 Posts
    Rep Power
    365

    Re: Login script problem

    well I will be darned.

    I tested it out and for this vbscript :

    TwoPos = InStrRev("12345678987654321", "2")
    MsgBox TwoPos

    It returns 16

    how come it ignores the first 2 at the end if its supposed to search it from the end to the start ?

    Me.Confused = Very True lol.

    So the 2nd parameter in InStrRev, does that make it search for the value number 2 or what does that do because in my InStrRev in my printer script it is something along the lines of :

    InStrRev(strComputer,-1,1)

    or something to that extent ( Not exactly sure what difference the numerica values make but they must make a big difference.

    Would be nice to know exactly what differences the different numbers make exactly !!

  13. #43

    Join Date
    Aug 2005
    Location
    Birmingham, UK
    Posts
    490
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: Login script problem

    IT doesnt ignore the second "2":

    InStrRev doesnt "count" from the end it just returns the position of the matching character but performs its search in reverse order. Each characters position is determined from left to right starting from one, therefore, when doing a InStrRev in your example, it finds the first instance of the character "2", which is in the 16th position in the string, therefore returns 16

  14. #44

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,807
    Thank Post
    3,320
    Thanked 1,056 Times in 977 Posts
    Rep Power
    365

    Re: Login script problem

    So you are saying InStrRev basically searches from left to right but returns the 2 on the left hand side and no the right hand side ?

  15. #45

    Join Date
    Aug 2005
    Location
    Birmingham, UK
    Posts
    490
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: Login script problem

    Thats not what i said at all,

    InStrRev searches from right to left, but it returns the position of the result it finds based on the standard positioning number system, for example:

    Code:
    intPosition = InStrRev("this is a string", "i")
    would return 14, as the first "i" encountered when checking from right to left is the 14th character (in the word "string" and including the spaces in the count) when counting from left to right.

    Hope this makes sense

SHARE:
+ Post New Thread
Page 3 of 4 FirstFirst 1234 LastLast

Similar Threads

  1. Installing/Copying Fonts from Login Script
    By mattpant in forum Windows
    Replies: 10
    Last Post: 11th August 2011, 09:24 PM
  2. Set firefox proxy via login script
    By Jackd in forum Windows
    Replies: 2
    Last Post: 24th December 2009, 01:59 PM
  3. Printers disappearing after login script
    By gshaw in forum Windows
    Replies: 11
    Last Post: 10th June 2009, 06:47 PM
  4. Problem with Home Drive and login scripts
    By ArchersIT in forum Windows
    Replies: 4
    Last Post: 11th July 2007, 12:17 PM
  5. Replies: 4
    Last Post: 23rd November 2006, 09:33 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •