Error access denied in script

Home Forums Scripting General Scripting Error access denied in script

This topic contains 10 replies, has 4 voices, and was last updated by Avatar Daveinholland 12 years, 9 months ago.

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #118842

    Hi everyone

    What is wrong with this script?

    Iget this:

    “Location of script”

    error line 17

    char 1 access denied

    error: access denied

    800A0046

    Dim objShell, colSysEnvVars, strDefPrinter, PrinterPath, WshNetwork, rc

    Set objShell = WScript.CreateObject(“WScript.Shell”)
    Set colSysEnvVars = objShell.Environment(“SYSTEM”)

    strDefPrinter = “\Server1” + colSysEnvVars(“Def_Printer”)
    Set WshNetwork = WScript.CreateObject(“WScript.Network”)

    WshNetwork.AddWindowsPrinterConnection(“\Server1printer1”)
    WshNetwork.AddWindowsPrinterConnection(“\Server1printer2”)
    WshNetwork.AddWindowsPrinterConnection(“\Server1printer3”)
    WshNetwork.AddWindowsPrinterConnection(“\Server1printer4”)
    WshNetwork.AddWindowsPrinterConnection(“\Server1printer5”)
    WshNetwork.AddWindowsPrinterConnection(“\Server1printer6”)
    WshNetwork.AddWindowsPrinterConnection(“\Server1printer7”)
    WshNetwork.AddWindowsPrinterConnection(“\Server1printer8”)
    WshNetwork.AddWindowsPrinterConnection(“\Server1printer9”)

    If Len(strDefPrinter) <> 11 Then
    WshNetwork.SetDefaultPrinter strDefPrinter
    End If

    Avatar
    rvalstar
    Member
    #286452

    Re: Error access denied in script

    Is there a permission prob w/ printer9 (line 17 if I counted correctly)?

    Have you tried commenting out that line and did the problem go away or move?

    #218926

    Re: Error access denied in script

    Also, have you deliberately put a space in the path to the printers?

    Avatar
    rvalstar
    Member
    #286454

    Re: Error access denied in script

    Good catch.

    #290949

    Re: Error access denied in script

    Hi

    Thanks a lot. Yes this turned out to be the problem thanks a lot. Maybe another question to you. How can I set the default printer per department in teh script? So let’s say I want to use printer 1 for sales printer 2 for helpdesk?

    Avatar
    Dumber
    Participant
    #196101

    Re: Error access denied in script

    something like this:

    If ingroup (“sales”) then
    WshNetwork.SetDefaultPrinter strDefPrinter
    end if

    Private Function InGroup(strGroup)
    On Error Resume Next
    InGroup = False
    ‘Search strUserGroups for strGroup
    If Instr( 1, LCase( strUserGroups ), LCase( strGroup ), 1) Then InGroup = True
    End Function[/CODE]

    see here for more details:
    [url]http://groups.msn.com/windowsscript/general.msnw?action=get_message&mview=0&ID_Message=12785&LastModified=4675525389838796327[/url][CODE]If ingroup (“sales”) then
    WshNetwork.SetDefaultPrinter strDefPrinter
    end if

    Private Function InGroup(strGroup)
    On Error Resume Next
    InGroup = False
    ‘Search strUserGroups for strGroup
    If Instr( 1, LCase( strUserGroups ), LCase( strGroup ), 1) Then InGroup = True
    End Function[/CODE]

    see here for more details:
    http://groups.msn.com/windowsscript/general.msnw?action=get_message&mview=0&ID_Message=12785&LastModified=4675525389838796327

    #290950

    Re: Error access denied in script

    And for strDefprinter I substitute that for printer1? I don’t know what strDefprinter refers to.

    So How would I say “printername1” in the script has to go to teh sales group.

    “printername2” to support.

    Maybe you already gave the answer but I don’t really get it yet.

    thx a lot for replying

    David

    Avatar
    Dumber
    Participant
    #196106

    Re: Error access denied in script

    I’m sure there are better ways, but this will work for example.

    If ingroup (“sales”) then
    WshNetwork.AddWindowsPrinterConnection(“\Server1printer1”)
    WshNetwork.SetDefaultPrinter “\Server1printer1”
    end if

    If ingroup (“Tech”) then
    WshNetwork.AddWindowsPrinterConnection(“\Server1printer2”)
    WshNetwork.SetDefaultPrinter “\Server1printer2”
    end if

    Private Function InGroup(strGroup)
    On Error Resume Next
    InGroup = False
    ‘Search strUserGroups for strGroup
    If Instr( 1, LCase( strUserGroups ), LCase( strGroup ), 1) Then InGroup = True
    End Function[/CODE][CODE]If ingroup (“sales”) then
    WshNetwork.AddWindowsPrinterConnection(“\Server1printer1”)
    WshNetwork.SetDefaultPrinter “\Server1printer1”
    end if

    If ingroup (“Tech”) then
    WshNetwork.AddWindowsPrinterConnection(“\Server1printer2”)
    WshNetwork.SetDefaultPrinter “\Server1printer2”
    end if

    Private Function InGroup(strGroup)
    On Error Resume Next
    InGroup = False
    ‘Search strUserGroups for strGroup
    If Instr( 1, LCase( strUserGroups ), LCase( strGroup ), 1) Then InGroup = True
    End Function[/CODE]

    #290952

    Re: Error access denied in script

    Thanks marcel this helps me!

    #290953

    Re: Error access denied in script

    mmm just one question. Is this also possible to do per computer group?

    Avatar
    rvalstar
    Member
    #286492

    Re: Error access denied in script

    So I went a Googling and found a couple of interesting things.

    This interested me most as it tests membership for computers and users:

    I think merged w/ what you have or bits of this:

    And you’ll have it.

    Here’s another one I found on “Default Printers and Roaming Profiles” (scroll down):

    It’s based on 2 articles which should be good background:

    Vrolijke Kerstmis

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.