Announcement

Collapse
No announcement yet.

Adding a printer connection from an untrusted domain

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

  • Adding a printer connection from an untrusted domain

    Hi,

    I have an unusual requirement which I simply do not know if its possible to acheive without a manual approach.

    Our company has a sizeable enterprise domain, lets call this Domain1. I manage another domain for our showroom, lets call this Domain2. The two domains are on the same physical network but are untrusted. There is network connectivity between them as you can share files etc so long as you have logon credentials.

    What I hope to be able to do (without having to goto each users laptop and manually add queues) is to create a script which when run from a user on Domain1's laptop will create printer connections for various print shares on Domain2.

    I have used a VB script with AddPrinterConnection but of course it does not complete because without providing a logon for Domain2 the script cannot complete. As such, is there a way that within a script that I can add the Domain login credentials so the AddPrinterConnection argument will work?

    Or, is there another way to get the same result?

    Thanks in advance!

  • #2
    Re: Adding a printer connection from an untrusted domain

    maybe something like,
    Code:
    -
    Code:
    Const HIDDEN_WINDOW = 12
    
    strPrnSrv = "192.168.10.20"
    strPrinter = "PrinterShareName"
    
    strComputer = "."
    Set objWMIService = GetObject( _
        "winmgmts:{impersonationLevel=Impersonate}!\\" _
        & strComputer & "\root\cimv2")
    
    ' Use alternate credentials for Inter-Process Communication
    Set objConfig = objWMIService.Get("Win32_ProcessStartup").SpawnInstance_
    objConfig.ShowWindow = HIDDEN_WINDOW
    errReturn = objWMIService.Get("win32_process").Create _
       ("net.exe use \\" & strPrnSrv & " /user:" _
       & "otherdomain\user ""#[email protected]#"" " _
       & "/persistent:no", null, objConfig, intProcessID)
    
    Set objPrinter = objWMIService.Get("Win32_Printer")
    errReturn = objPrinter.AddPrinterConnection _
        ("\\" & strPrnSrv & "\" & strPrinter)
    /Rems
    Last edited by Rems; 29th July 2011, 17:13.

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: Adding a printer connection from an untrusted domain

      Thats weird, I tried to reply to this thread but it disappeared..... maybe I'm going mad :S

      Rems, thanks very much this script is great. I wonder if you could help develop it a little futher as I have tried to modify it slightly with no success.

      I would need to be able to add multiple printers from multiple servers, for example I would want the script to be able to add say the following connections;

      \\server1\printer1
      \\server1\printer2
      \\server2\printer3
      \\server2\printer4
      \\server3\printer5
      \\server4\printer6

      Can your script accomodate that?

      Thanks in advance

      Adam

      Comment


      • #4
        Re: Adding a printer connection from an untrusted domain

        Originally posted by Adam_231 View Post
        I would need to be able to add multiple printers from multiple servers, for example I would want the script to be able to add say the following connections;

        \\server1\printer1
        \\server1\printer2
        \\server2\printer3
        \\server2\printer4
        \\server3\printer5
        \\server4\printer6

        Can your script accomodate that?

        Thanks in advance

        Adam
        It would be something like this,
        (in this sample credentials are passed to the subroutine for each server. If you'd use the same credentials for all servers you could also just enter the credentials once in de sub routine)
        Code:
        Const HIDDEN_WINDOW = 12
        
        strComputer = "."
        Set objWMIService = GetObject( _
            "winmgmts:{impersonationLevel=Impersonate}!\\" _
            & strComputer & "\root\cimv2")
        
        Set objPrinter = objWMIService.Get("Win32_Printer")
        
        ' Use alternate credentials for Inter-Process Communication
        Dim objConfig
        Set objConfig = objWMIService.Get("Win32_ProcessStartup").SpawnInstance_
        objConfig.ShowWindow = HIDDEN_WINDOW
        
        strPrnSrv1 = "192.168.10.20"
        ConnectTo strPrnSrv1, "otherdomain\user", "#[email protected]#"
        
        strPrnSrv2 = "192.168.10.21"
        ConnectTo strPrnSrv2, "otherdomain\user", "#[email protected]#"
        
        strPrnSrv3 = "192.168.10.22"
        ConnectTo strPrnSrv3, "otherdomain\user", "#[email protected]#"
        
        strPrnSrv4 = "192.168.10.23"
        ConnectTo strPrnSrv4, "otherdomain\user", "#[email protected]#"
        
        AddPrinter strPrnSrv1, "printer1"
        AddPrinter strPrnSrv1, "printer2"
        
        AddPrinter strPrnSrv2, "printer3"
        AddPrinter strPrnSrv2, "printer4"
        
        AddPrinter strPrnSrv3, "printer5"
        
        AddPrinter strPrnSrv4, "printer6"
        
        
        Sub ConnectTo(sHost, sUser, sPass)
           Dim intProcessID, errReturn
           errReturn = objWMIService.Get("win32_process").Create _
              ("net.exe use \\" & sHost & " /user:" _
              & sUser & " """ & sPass & """ " _
              & "/persistent:no", null, objConfig, intProcessID)
        End Sub
        
        Sub AddPrinter(sHost, sPrinter)
           Dim errReturn
           errReturn = objPrinter.AddPrinterConnection _
               ("\\" & sHost & "\" & sPrinter)
        End Sub
        /Rems

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment


        • #5
          Re: Adding a printer connection from an untrusted domain

          Rems,

          I can't thank you enough for your help with this. In the case that I use the script you've provided below I would create one script per user and distribute for them to use, in other words there would only be one user/password per script.

          Please excuse my ignorance as I am really only 'trying' to learn about scripting but I don't really understand about entering the credentials once in the sub routine.

          Another thought I had is that when I created the user account in the showroom domain I used the same user account name as they use in the enterprise domain. For example, if the user logs onto the enterprise domain as bob.jones in the showroom domain their account is also bob.jones . I wondered if there is some fancy scripting that can be done to pull the username from their currnet windows session so as not to have to write it in the script? As a side note, each users password for the showroom environment is the same, so in other words if the username value can be taken from the windows session then I would in effect only need one version of the script rather than several individual versions.

          Again, thanks very much for all your help

          Adam

          Comment


          • #6
            Re: Adding a printer connection from an untrusted domain

            Originally posted by Adam_231 View Post
            * entering the credentials once in the sub routine.
            * when I created the user account in the showroom domain I used the same user account name as they use in the enterprise domain.

            I wondered if there is some fancy scripting that can be done to pull the username from their currnet windows session so as not to have to write it in the script? As a side note, each users password for the showroom environment is the same, so in other words if the username value can be taken from the windows session then I would in effect only need one version of the script rather than several individual versions.
            Code:
            Const HIDDEN_WINDOW = 12
            
            DIM objWMIService, objPrinter, strUserName, objConfig
            
            strComputer = "."
            Set objWMIService = GetObject( _
                "winmgmts:{impersonationLevel=Impersonate}!\\" _
                & strComputer & "\root\cimv2")
            
            Set objPrinter = objWMIService.Get("Win32_Printer")
            
            Set objNetwork = WScript.CreateObject("WScript.Network") 
            strUserName = objNetwork.UserName
            
            ' Use alternate credentials for Inter-Process Communication
            Set objConfig = objWMIService.Get("Win32_ProcessStartup").SpawnInstance_
            objConfig.ShowWindow = HIDDEN_WINDOW
            
            strPrnSrv1 = "192.168.10.20"
            ConnectTo strPrnSrv1
            
            strPrnSrv2 = "192.168.10.21"
            ConnectTo strPrnSrv2
            
            strPrnSrv3 = "192.168.10.22"
            ConnectTo strPrnSrv3
            
            strPrnSrv4 = "192.168.10.23"
            ConnectTo strPrnSrv4
            
            AddPrinter strPrnSrv1, "printer1"
            AddPrinter strPrnSrv1, "printer2"
            
            AddPrinter strPrnSrv2, "printer3"
            AddPrinter strPrnSrv2, "printer4"
            
            AddPrinter strPrnSrv3, "printer5"
            
            AddPrinter strPrnSrv4, "printer6"
            
            
            Sub ConnectTo(sHost)
               Dim intProcessID, errReturn
               errReturn = objWMIService.Get("win32_process").Create _
                  ("net.exe use \\" & sHost & " /user:otherdomain\" _
                  & strUserName & " ""#[email protected]#"" " _
                  & "/persistent:no", null, objConfig, intProcessID)
            End Sub
            
            Sub AddPrinter(sHost, sPrinter)
               Dim errReturn
               errReturn = objPrinter.AddPrinterConnection _
                   ("\\" & sHost & "\" & sPrinter)
            End Sub
            Enter the actual password and the domain name in the sub routine.

            /Rems

            This posting is provided "AS IS" with no warranties, and confers no rights.

            __________________

            ** Remember to give credit where credit's due **
            and leave Reputation Points for meaningful posts

            Comment


            • #7
              Re: Adding a printer connection from an untrusted domain

              Way hey!

              I'm so happy with this, honestly thanks so very much!

              Now all I want to do is package it as an .exe to complete, any suggestions on a freeware program for this task?

              Comment


              • #8
                Re: Adding a printer connection from an untrusted domain

                Also, how do you leave reputation points?

                Comment


                • #9
                  Re: Adding a printer connection from an untrusted domain

                  Hit the ying yang symbol above a helpful post to leave reputation points.
                  ** Remember to give credit where credit is due and leave reputation points where appropriate **

                  Comment

                  Working...
                  X