Script to complete!

Author Message
claudio

  • Total Posts : 11
  • Scores: 0
  • Reward points : 0
  • Joined: 4/14/2005
  • Location:
  • Status: offline
Script to complete! Monday, April 18, 2005 7:20 PM (permalink)
0
Please help me on this!
I need to make this script run

set objSession = ?
IPAddress = objSession.ClientAddress
If InStr(1, IPAddress, "192.168.3.", 1) <> 0 Then
MsgBox "place mappings here"
End If
 
#1
    claudio

    • Total Posts : 11
    • Scores: 0
    • Reward points : 0
    • Joined: 4/14/2005
    • Location:
    • Status: offline
    Re: Script to complete! Monday, April 18, 2005 7:46 PM (permalink)
    0
    Whats is wrong here?


    Set net = CreateObject("WScript.Network")
    IPAddress = objSession.ClientAddress
    If InStr(1, IPAddress, "10.16.17.", 1) <> 0 Then
    net.AddWindowsPrinterConnection "\\server\printer"
    End If
     
    #2
      Zifter

      • Total Posts : 315
      • Scores: 0
      • Reward points : 0
      • Joined: 1/5/2005
      • Location: Belgium
      • Status: offline
      Re: Script to complete! Monday, April 18, 2005 8:51 PM (permalink)
      0
      quote:
      Whats is wrong here?
      • You create a Network object and assign it to the variable "net", altough you never use this variable again (isn't actually an error)
      • You use the variable "objSession" as an object, but it is never created
      • (Assuming the variable "net" should have been "objSession") "ClientAddress" isn't a property of a Network object

      Here you can find an example of how to find the IP address: http://www.codeproject.com/vbscript/ipaddress.asp

      HTH

      edit: You do use the net variable later on to add a printer connection , I'm sorry, my fault
       
      #3
        Zifter

        • Total Posts : 315
        • Scores: 0
        • Reward points : 0
        • Joined: 1/5/2005
        • Location: Belgium
        • Status: offline
        Re: Script to complete! Monday, April 18, 2005 9:21 PM (permalink)
        0
        Alternatively you could retrieve the IP address like this:

        strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set IPConfigSet = objWMIService.ExecQuery _ ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE") For Each IPConfig in IPConfigSet If Not IsNull(IPConfig.IPAddress) Then For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress) WScript.Echo IPConfig.IPAddress(i) Next End If Next

        found [url="http://www.microsoft.com/technet/scriptcenter/scripts/network/client/list/nwlsvb01.mspx"]here[/url]


        HTH
         
        #4
          claudio

          • Total Posts : 11
          • Scores: 0
          • Reward points : 0
          • Joined: 4/14/2005
          • Location:
          • Status: offline
          Re: Script to complete! Tuesday, April 19, 2005 1:19 AM (permalink)
          0
          Ich changed it to the gateway! Now what I need is to change the script, that if the gateway ist for example "192.168.0.254" than msgbox "hello subnet 0" if "192.168.1.254 msbox "hello subnet 1". Could somebody please do that for me, I have no idea, how to compare the values...

          strComputer = "."
          Set objWMIService = GetObject("winmgmts:" _
          & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

          Set IPConfigSet = objWMIService.ExecQuery _
          ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")

          For Each IPConfig in IPConfigSet
          If Not IsNull(IPConfig.DefaultIPGateway) Then
          For i=LBound(IPConfig.DefaultIPGateway) to UBound(IPConfig.DefaultIPGateway)
          WScript.Echo IPConfig.DefaultIPGateway(i)
          Next
          End If
          Next


          Thanks Claudio


           
          #5
            Zifter

            • Total Posts : 315
            • Scores: 0
            • Reward points : 0
            • Joined: 1/5/2005
            • Location: Belgium
            • Status: offline
            Re: Script to complete! Tuesday, April 19, 2005 3:47 AM (permalink)
            0
            What you want to do is a common string manipulation. There are serveral solutions to get only a part of a string, but I think in this case the Split function is the easiest.
            The Split function will split a string (surprise) on the specified delimiter and puts each part in an array.
            Like this

            arrIP = Split(IPConfig.DefaultIPGateway(i),".") WScript.Echo arrIP(2)
            or in short

            WScript.Echo Split(IPConfig.DefaultIPGateway(i),".")(2)

            note: Arrays are zero-based

            HTH
             
            #6
              token

              • Total Posts : 1917
              • Scores: 0
              • Reward points : 0
              • Joined: 1/14/2005
              • Location:
              • Status: offline
              Re: Script to complete! Tuesday, April 19, 2005 10:24 AM (permalink)
              0
              What exactly do you intend to do now ? Getting the network portion of the IP address and then what ? Do you have a list of printers associated with this subnet ? If you could tell us EXACTLY what you have in mind, I could probably help a lot more.

               
              #7
                token

                • Total Posts : 1917
                • Scores: 0
                • Reward points : 0
                • Joined: 1/14/2005
                • Location:
                • Status: offline
                Re: Script to complete! Tuesday, April 19, 2005 2:20 PM (permalink)
                0
                The following code will map a (or a aet of) printers based on the third octet of the gateway ip of the local host. Modify and add the correct "\\server\printer" statements in the SELECT CASE statement in the mapPrinters subroutine.

                =================================================================
                Option Explicit

                mapPrinters(getSubnet)

                Function getSubnet
                Dim wmi, NICs, NIC, temp
                Set wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
                Set NICs = wmi.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=True")
                temp = ""
                For Each NIC In NICs
                If Not IsNull(NIC.DefaultIPGateway)Then
                temp = Split(NIC.DefaultIPGateway(0),".")(2)
                Exit For
                End If
                Next
                getSubnet = temp
                End Function

                Sub mapPrinters(subnet)
                Dim network
                Set network = CreateObject("WScript.Network")

                Select Case subnet
                Case 0
                network.AddWindowsPrinterConnection "\\server\printer1"
                network.AddWindowsPrinterConnection "\\server\printer2"
                Case 1
                network.AddWindowsPrinterConnection "\\server\printer3"
                network.AddWindowsPrinterConnection "\\server\printer4"
                End Select
                End Sub


                 
                #8
                  claudio

                  • Total Posts : 11
                  • Scores: 0
                  • Reward points : 0
                  • Joined: 4/14/2005
                  • Location:
                  • Status: offline
                  Re: Script to complete! Tuesday, April 19, 2005 5:55 PM (permalink)
                  0
                  What I exactly want is to map printers according to the clients default gateway. I have a list of all printers which should be mapped at logon when de default gateway of the client has a specific IP address.

                  GW: 172.18.32.254
                  \\server\printer13
                  \\server\printer206

                  GW: 10.16.17.254
                  \\server\printer128
                  \\server\printer34

                  GW: 10.48.2.254
                  \\server\printer131
                  \\server\printer563

                  GW: 192.168.8.254
                  \\server\printer65
                  \\server\printer22

                  GW: 192.168.100.254
                  \\server\printer452
                  \\server\printer232

                  etc. (around 100 different subnets...)

                  Thanks for your help! I think we (you) are very near to the solution...
                   
                  #9
                    jovius98

                    • Total Posts : 17
                    • Scores: 0
                    • Reward points : 0
                    • Joined: 4/19/2005
                    • Location:
                    • Status: offline
                    Re: Script to complete! Tuesday, April 19, 2005 10:11 PM (permalink)
                    0
                    How about this:

                    ' MapPrinters.vbs - Map user's printers depending on subnet
                    
                    Option Explicit
                    Dim dPrtLst
                    Set dPrtLst=CreateObject("Scripting.Dictionary")
                    
                    ' Specify the printer lists here
                    
                    dPrtLst.Add "172.18.32.254",   Array("\\server\printer13","\\server\printer206")
                    dPrtLst.Add "10.16.17.254",    Array("\\server\printer128","\\server\printer34")
                    dPrtLst.Add "10.48.2.254",     Array("\\server\printer131","\\server\printer563")
                    dPrtLst.Add "192.168.8.254",   Array("\\server\printer65","\\server\printer22")
                    dPrtLst.Add "192.168.100.254", Array("\\server\printer452","\\server\printer232")
                    
                    MapPrinters(getSubNet)
                    
                    Function GetSubnet
                    Dim WMI,NICs,NIC
                    Set WMI=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
                    Set NICs=WMI.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=True")
                    GetSubnet=""
                    For Each NIC In NICs
                    If Not IsNull(NIC.DefaultIPGateway)Then
                    GetSubnet=NIC.DefaultIPGateway(0)
                    Exit Function
                    End If
                    Next
                    End Function
                    
                    Sub MapPrinters(sSubNet)
                    Dim sPrtName,NET
                    If sSubNet<>"" Then
                    If dPrtLst.Exists(sSubNet) Then
                    Set NET=CreateObject("WScript.Network")
                    For Each sPrtName In dPrtLst.Item(sSubNet)
                    NET.AddWindowsPrinterConnection sPrtName
                    Next
                    End If
                    End If
                    End Sub
                    

                     
                    #10
                      claudio

                      • Total Posts : 11
                      • Scores: 0
                      • Reward points : 0
                      • Joined: 4/14/2005
                      • Location:
                      • Status: offline
                      Re: Script to complete! Tuesday, April 19, 2005 10:28 PM (permalink)
                      0
                      That's just PERFECT!!!!!!!!!!!!!!!!!!!!!!! Thank you very much!
                       
                      #11
                        token

                        • Total Posts : 1917
                        • Scores: 0
                        • Reward points : 0
                        • Joined: 1/14/2005
                        • Location:
                        • Status: offline
                        Re: Script to complete! Wednesday, April 20, 2005 8:19 AM (permalink)
                        0
                        hm.... That looked awfully like what I posted.

                        and you are welcome =)

                         
                        #12
                          token

                          • Total Posts : 1917
                          • Scores: 0
                          • Reward points : 0
                          • Joined: 1/14/2005
                          • Location:
                          • Status: offline
                          Re: Script to complete! Wednesday, April 20, 2005 8:25 AM (permalink)
                          0
                          hm.... That looked awfully like what I posted.

                          and you are welcome =)

                          However, if you decide to use what I posted, you will need change a couple of things.

                          Replace:

                          temp = Split(NIC.DefaultIPGateway(0),".")(2)

                          with:

                          temp = NIC.DefaultIPGateway(0)

                          and replace: Case 0

                          With:

                          Case "172.18.32.254" etc

                           
                          #13
                            claudio

                            • Total Posts : 11
                            • Scores: 0
                            • Reward points : 0
                            • Joined: 4/14/2005
                            • Location:
                            • Status: offline
                            Re: Script to complete! Tuesday, May 17, 2005 9:56 PM (permalink)
                            0
                            The script works fine, but how can I install the printers on the computer and not in the profile. There is a solution how to add network printers with a batch to the computer:

                            http://members.shaw.ca/bsanders/NetPrinterAllUsers.htm

                            How can I do this with vbs? How is the variable?

                            Thanks in advance!

                             
                            #14

                              Online Bookmarks Sharing: Share/Bookmark

                              Jump to:

                              Current active users

                              There are 0 members and 1 guests.

                              Icon Legend and Permission

                              • New Messages
                              • No New Messages
                              • Hot Topic w/ New Messages
                              • Hot Topic w/o New Messages
                              • Locked w/ New Messages
                              • Locked w/o New Messages
                              • Read Message
                              • Post New Thread
                              • Reply to message
                              • Post New Poll
                              • Submit Vote
                              • Post reward post
                              • Delete my own posts
                              • Delete my own threads
                              • Rate post

                              2000-2012 ASPPlayground.NET Forum Version 3.9