Announcement

Collapse
No announcement yet.

Error access denied in script

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error access denied in script

    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("\\Server1\ printer1")
    WshNetwork.AddWindowsPrinterConnection("\\Server1\ printer2")
    WshNetwork.AddWindowsPrinterConnection("\\Server1\ printer3")
    WshNetwork.AddWindowsPrinterConnection("\\Server1\ printer4")
    WshNetwork.AddWindowsPrinterConnection("\\Server1\ printer5")
    WshNetwork.AddWindowsPrinterConnection("\\Server1\ printer6")
    WshNetwork.AddWindowsPrinterConnection("\\Server1\ printer7")
    WshNetwork.AddWindowsPrinterConnection("\\Server1\ printer8")
    WshNetwork.AddWindowsPrinterConnection("\\Server1\ printer9")

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

  • #2
    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?
    Cheers,

    Rick

    ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

    2006-2099 R Valstar. This post is offered "as is" for discussion purposes only with no express or implied warranty of any kind including, but not limited to, correctness or fitness for use. Nothing herein shall be construed as advice. Attempting any activity based on information in this post is done at your own risk.

    Comment


    • #3
      Re: Error access denied in script

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


      Tom
      For my own and your protection, I do not provide support by private message under any circumstances. All such messages will be deleted and ignored.

      Anything you say will be misquoted and used against you

      Comment


      • #4
        Re: Error access denied in script

        Good catch.
        Cheers,

        Rick

        ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

        2006-2099 R Valstar. This post is offered "as is" for discussion purposes only with no express or implied warranty of any kind including, but not limited to, correctness or fitness for use. Nothing herein shall be construed as advice. Attempting any activity based on information in this post is done at your own risk.

        Comment


        • #5
          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?

          Comment


          • #6
            Re: Error access denied in script

            something like this:

            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
            see here for more details:
            http://groups.msn.com/windowsscript/...25389838796327
            Marcel
            Technical Consultant
            Netherlands
            http://www.phetios.com
            http://blog.nessus.nl

            MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
            "No matter how secure, there is always the human factor."

            "Enjoy life today, tomorrow may never come."
            "If you're going through hell, keep going. ~Winston Churchill"

            Comment


            • #7
              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

              Comment


              • #8
                Re: Error access denied in script

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

                Code:
                If ingroup ("sales") then
                WshNetwork.AddWindowsPrinterConnection("\\Server1\printer1")
                 WshNetwork.SetDefaultPrinter "\\Server1\printer1"
                end if
                
                If ingroup ("Tech") then
                WshNetwork.AddWindowsPrinterConnection("\\Server1\printer2")
                 WshNetwork.SetDefaultPrinter "\\Server1\printer2"
                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
                Marcel
                Technical Consultant
                Netherlands
                http://www.phetios.com
                http://blog.nessus.nl

                MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
                "No matter how secure, there is always the human factor."

                "Enjoy life today, tomorrow may never come."
                "If you're going through hell, keep going. ~Winston Churchill"

                Comment


                • #9
                  Re: Error access denied in script

                  Thanks marcel this helps me!

                  Comment


                  • #10
                    Re: Error access denied in script

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

                    Comment


                    • #11
                      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
                      Cheers,

                      Rick

                      ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

                      2006-2099 R Valstar. This post is offered "as is" for discussion purposes only with no express or implied warranty of any kind including, but not limited to, correctness or fitness for use. Nothing herein shall be construed as advice. Attempting any activity based on information in this post is done at your own risk.

                      Comment

                      Working...
                      X