VBA/VBS check if printer is installed

Here is a quick code snippet to determine if a printer is installed on a Microsoft Windows system;

MsgBox printerExists("Microsoft XPS Document Writer")

Function printerExists(str)
    printerExists = False
    Dim objWMIService
    Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")

    Dim colPrinters
    Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer")

    Dim objPrinter
    For Each objPrinter In colPrinters
        If objPrinter.Name = str Then
            printerExists = True
            Exit For
        End If
    Next
End Function

Get the parameters/arguments being called to an executable

Lets say you have some program ‘A’ that has no documentation and no help files but is being executed by some program ‘B’. You want to run program ‘A’ is individually, but you need to know what parameters/arguments are being passed from program ‘B’.

The following executable will help. Replace program ‘A’ (temporarily) with the following executable. Once program ‘B’ executes this new program, the parameters will be displayed in a message box.

Download getparams.exe

Source code below;

    Public Sub main()
        Dim msg As String = vbNullString

        Dim separators As String = " "
        Dim commands As String = Microsoft.VisualBasic.Command()
        Dim str() As String = commands.Split(separators.ToCharArray)

        Dim i As Long

        For i = 0 To UBound(str)
            msg = msg & str(i).ToString & vbCr
        Next

        MsgBox(msg)
    End Sub