troubleshooting Question

VBScript create 2 arrays from data and act on differences?

Avatar of usslindstrom
usslindstromFlag for Japan asked on
VB Script
19 Comments1 Solution302 ViewsLast Modified:
Experts,

I have a bit of a challenge ahead of me in the folliowing:

I have a VBScript that runs against machines and queries a SQL Server for which printers it should install based on it's ComputerName/Room Number.  It's actually a very slick ordeal, and we're going to be implementing the code through group policy on each and every startup of a PC.  - And the scripts very first task each time it runs is to actually delete any network mapped printers accross the board on computers.

Right there, is where you can see a potential problem that's going to stem from running the script on startup, in that in it's current form it can take approximately 30 seconds to finish the process of installing printers (some units have 4 printers flagged for installation, so it must run through the installation on all of them individually).  - Even if it's the exact same 4 printers that have already been installed previously.

-------------------------

What I'd like to do, is change the way the script behaves completely - and have VB query the list of currently installed printers (script courtesy of "The Scripting Guys"  http://blogs.technet.com/b/heyscriptingguy/archive/2007/07/16/how-can-i-list-the-network-printers-for-the-logged-on-user.aspx).

Then hit SQL server for results and act on discrepancies (delete/add printers to the local computer).

Below is the code for acting on SQL (mostly pieced together by previous questions here on EE).  Would anybody be able to point me in a direction that I need to start looking in order to make this "dream" a reality?

As usual, ANY assistance that can be provided is way more than appreciated!


SQLServer = wshShell.ExpandEnvironmentStrings( "%SiteSQLServer%" )
        SQLDatabase = "Printers"


        Const adCmdStoredProc = 4, adVarChar = 200, adParamInput = 1

        Dim cn, cmd, rs

            Set cn = CreateObject("ADODB.Connection")
            Set cmd = CreateObject("ADODB.Command")

                cn.ConnectionString = "Provider=SQLOLEDB;Data Source=" & SQLServer & ";" & _
                                      "Trusted_Connection=Yes;Initial Catalog=" & SQLDatabase & ";"

            cn.CursorLocation = adUseClient
            cn.Open

        ComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )

            ComputerLocation = Split(ComputerName, "-")(0)
            ComputerRoomNumber = Split(ComputerName, "-")(1)


                Select Case ComputerType

                    Case "Administrative"
                        objLogFile.WriteLine "Processing global 'Administrative' group scoped printers..."
                        StoredProcedure = "SP_PrinterMap_Admin"
                    Case "Classroom"
                        objLogFile.WriteLine "Processing global 'Classroom' group scoped printers..."
                        StoredProcedure = "SP_PrinterMap_Classroom"
                    Case "Information Center"
                        objLogFile.WriteLine "Processing global 'Information Center' group scoped printers..."
                        StoredProcedure = "SP_PrinterMap_IC"
                    Case "Lab"
                        objLogFile.WriteLine "Processing global 'Lab' group scoped printers..."
                        StoredProcedure = "SP_PrinterMap_Lab"
                    Case "Notebook"
                        objLogFile.WriteLine "Processing global 'Notebook' group scoped printers..."
                        StoredProcedure = "SP_PrinterMap_Notebook"
                    Case "Netbook"
                        objLogFile.WriteLine "Processing global 'Netbook' group scoped printers..."
                        StoredProcedure = "SP_PrinterMap_Netbook"
                    Case "Teacher"
                        objLogFile.WriteLine "Processing global 'Teacher' group scoped printers..."
                        StoredProcedure = "SP_PrinterMap_Teacher"
                    Case "Utility"
                        objLogFile.WriteLine "Processing global 'Utility' group scoped printers..."
                        StoredProcedure = "SP_PrinterMap_Utility"
                    Case "Virtual School"
                        objLogFile.WriteLine "Processing global 'Virtual School' group scoped printers..."
                        StoredProcedure = "SP_PrinterMap_VirtualSchool"
                    Case Else
                        objLogFile.WriteLine "Processing without global group scoped printers..."
                        StoredProcedure = "SP_PrinterMap_Global"
                End Select

            With cmd
                Set .ActiveConnection = cn
                    .CommandText = StoredProcedure
                    .CommandType = adCmdStoredProc
                    .Parameters.Append .CreateParameter("@ComputerRoomNumber", adVarChar, adParamInput, 100, ComputerRoomNumber)
                    .Parameters.Append .CreateParameter("@ComputerName", adVarChar, adParamInput, 100, ComputerName)

                    Set rs = .Execute
            End With

            Set cmd = Nothing

            Do While Not rs.EOF			

            . . .   INSTALLING PRINTER SCRIPT  . . .
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 19 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 19 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros