script runs for users but not computers?

Discussion in 'Scripting' started by Me Myco, Sep 2, 2004.

  1. Me Myco

    Me Myco Guest

    Hi all,

    This probably seems pretty basic but I am quite new to scripting so
    any help would be appreciated. I thought this is more a permissions
    issue but figured you guys have surely run into this so here goes.

    I have a pretty basic printer script that works if I use the user for
    permissions (for access to the printer and to run the GPO) and apply
    it via logon in a GPO or locally. But if I try this script using the
    computer for permissions it fails with a "The system cannot find the
    file specified" Code: 80070002 or a Code 800A0046 - "Permissions
    Denied" if I try to run the script locally.

    I have many users that logon to several different workstations and if
    I use the user for permissions they get printers that arent
    neccessarily located in the area they happen to be at. Ideally I would
    like to be able to set up a GPO that runs this script (successfully)
    and have only selected computer accounts run it. I would think this
    could be done yes?
     
    Me Myco, Sep 2, 2004
    #1
    1. Advertisements

  2. The default printer is a property of the user account,
    which pretty much means that the way this is done is
    within the user account's security context.
    You really do not want to configure a default printer
    for the system account (which never prints).
    If you have issues with which account is selected
    then you need to put more smarts into your routine
    so it can be sensitive to what user account it is and/or
    which printer should be provided, or else, reexamine
    how you are using GPOs to target sets of users with
    different version of the login script.
     
    Roger Abell [MVP], Sep 2, 2004
    #2
    1. Advertisements

  3. ....You can set a "location" attribute to different groups of computers to
    check it from the user's logon script and to connect to the printer
    accordingly ...Or you can put computers in Printing groups ...there are lot
    of ways to do so ... Below is just an example how to choose a printer
    depending on which computer our user is logged on ...

    Set WshNetwork = CreateObject("WScript.Network")
    strComputer = WshNetwork.ComputerName
    Set objComputer = GetObject("LDAP://CN=" & _
    strComputer & ",CN=Computers,DC=company,DC=com")
    Select Case objComputer.Get("location")
    Case "Accountants"
    strPrinter = "\\PrintServer1\Printer1"
    Case "Sales"
    strPrinter = "\\PrintServer2\Printer2"
    Case "Lawyers"
    strPrinter = "\\PrintHouse\OffsetPress"
    End Select
    WshNetwork.AddWindowsPrinterConnection strPrinter
     
    Yevgen Lazaryev, Sep 2, 2004
    #3
  4. Me Myco

    Me Guest

    On Thu, 2 Sep 2004 09:02:28 -0400, "Yevgen Lazaryev"

    Thanks for the quick response. As I wrote, I'm quite new to scripting
    and I have a few questions if you don't mind.
    I think I understand about why one would use an attribute to "sort" on
    but I'm still fuzzy on how one ties a location to a group? For that
    matter why wouldn't I just use the printer name?
    Is the above line "Accountants" the "location" or group?
    I am assumming that this script would need to include more for this
    line above to work. For example...

    Set strPrinter = CreateObject("WScript.Network")

    Or some such variable? I did mention I am really new to scripting! :)

    Again, thanks for your help.
     
    Me, Sep 2, 2004
    #4
  5. | I think I understand about why one would use an attribute to "sort" on
    | but I'm still fuzzy on how one ties a location to a group? For that
    | matter why wouldn't I just use the printer name?

    ....I mentioned groups as another option of checking computer attributes
    because if you depend on "location" attribute you need to set it first for
    any computer in question (if it wasn't set before) ...manually in computer
    properties in AD Users and Computers or using another script to do it
    .....However checking the "location" attribute is simplier than "memberOf"
    .... And if you don't use "location" for any other purposes you really can
    just put there the printer name and then remove Select Case statement from
    the script .... If even the "location" attribute is already in use you can
    add printer name there with delimiter, like semicolon, and then use Split()
    function to retrieve it directly ... So you need to decide if using this
    attribute is OK for you ... There is another problem however ...My script
    assumes that all your computers are in "Computers" container in Active
    Directory when creating the objComputer object

    | >Set objComputer = GetObject("LDAP://CN=" & _
    | >strComputer & ",CN=Computers,DC=company,DC=com")

    ...If your computers are in separate OUs it won't be so simple to get the
    attributes ... Actually if the number of computers is small enough we could
    simply put their names directly into the script without calling LDAP ...

    | >Select Case objComputer.Get("location")
    | >Case "Accountants"
    | Is the above line "Accountants" the "location" or group?

    ..... in this example "Accountants" means "location" string in computer
    properties in AD ...

    | >strPrinter = "\\PrintServer1\Printer1"
    | I am assumming that this script would need to include more for this
    | line above to work. For example...
    |
    | Set strPrinter = CreateObject("WScript.Network")
    |
    | Or some such variable? I did mention I am really new to scripting! :)


    ....Well ...:) ..."Good coding" assumes that we need to declare variables
    before using them, like

    Dim strPrinter

    in the first line of a script , but VBS can initialize variables without
    that so it works ....
     
    Yevgen Lazaryev, Sep 3, 2004
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.