403Webshell
Server IP : 127.0.0.1  /  Your IP : 216.73.216.109
Web Server : Apache/2.4.54 (Win64) OpenSSL/1.1.1q PHP/8.1.10
System : Windows NT DESKTOP-E5T4RUN 10.0 build 19045 (Windows 10) AMD64
User : SERVERWEB ( 0)
PHP Version : 8.1.10
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : OFF |  Perl : OFF |  Python : OFF |  Sudo : OFF |  Pkexec : OFF
Directory :  C:/Windows/SysWOW64/Printing_Admin_Scripts/es-ES/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : C:/Windows/SysWOW64/Printing_Admin_Scripts/es-ES/prnmngr.vbs
��'----------------------------------------------------------------------

'

' Copyright (c) Microsoft Corporation. All rights reserved.

'

' Abstract:

' prnmngr.vbs - printer script for WMI on Windows 

'     used to add, delete, and list printers and connections

'     also for getting and setting the default printer

'

' Usage:

' prnmngr [-adxgtl?][co] [-s server][-p printer][-m driver model][-r port]

'                       [-u user name][-w password]

'

' Examples:

' prnmngr -a -p "printer" -m "driver" -r "lpt1:"

' prnmngr -d -p "printer" -s server

' prnmngr -ac -p "\\server\printer"

' prnmngr -d -p "\\server\printer"

' prnmngr -x -s server

' prnmngr -l -s server

' prnmngr -g

' prnmngr -t -p "printer"

'

'----------------------------------------------------------------------



option explicit



'

' Debugging trace flags, to enable debug output trace message

' change gDebugFlag to true.

'

const kDebugTrace = 1

const kDebugError = 2

dim   gDebugFlag



gDebugFlag = false



'

' Operation action values.

'

const kActionUnknown           = 0

const kActionAdd               = 1

const kActionAddConn           = 2

const kActionDel               = 3

const kActionDelAll            = 4

const kActionDelAllCon         = 5

const kActionDelAllLocal       = 6

const kActionList              = 7

const kActionGetDefaultPrinter = 8

const kActionSetDefaultPrinter = 9



const kErrorSuccess            = 0

const KErrorFailure            = 1



const kFlagCreateOnly          = 2



const kNameSpace               = "root\cimv2"



'

' Generic strings

'

const L_Empty_Text                 = ""

const L_Space_Text                 = " "

const L_Error_Text                 = "Error"

const L_Success_Text               = "Correcto"

const L_Failed_Text                = "Error"

const L_Hex_Text                   = "0x"

const L_Printer_Text               = "Impresora"

const L_Operation_Text             = "Operaci�n"

const L_Provider_Text              = "Proveedor"

const L_Description_Text           = "Descripci�n"

const L_Debug_Text                 = "Depurar:"

const L_Connection_Text            = "Conexi�n"



'

' General usage messages

'

const L_Help_Help_General01_Text   = "Uso: prnmngr [-adxgtl?][c] [-s servidor][-p impresora][-m modelo controlador]"

const L_Help_Help_General02_Text   = "               [-r puerto][-u nombre usuario][-w contarse�a]"

const L_Help_Help_General03_Text   = "Argumentos:"

const L_Help_Help_General04_Text   = "-a     - agregar impresora local"

const L_Help_Help_General05_Text   = "-ac    - agregar conexi�n de impresora"

const L_Help_Help_General06_Text   = "-d     - eliminar impresora"

const L_Help_Help_General07_Text   = "-g     - obtener la impresora predeterminada"

const L_Help_Help_General08_Text   = "-l     - listar impresoras"

const L_Help_Help_General09_Text   = "-m     - modelo del controlador"

const L_Help_Help_General10_Text   = "-p     - nombre de la impresora"

const L_Help_Help_General11_Text   = "-r     - nombre del puerto"

const L_Help_Help_General12_Text   = "-s     - nombre del sevidor"

const L_Help_Help_General13_Text   = "-t     - establecer la impresora predeterminada"

const L_Help_Help_General14_Text   = "-u     - nombre de usuario"

const L_Help_Help_General15_Text   = "-w     - contrase�a"

const L_Help_Help_General16_Text   = "-x     - eliminar todas las impresoras"

const L_Help_Help_General17_Text   = "-xc    - eliminar todas las conexiones de impresoras"

const L_Help_Help_General18_Text   = "-xo    - eliminar todas las impresoras locales"

const L_Help_Help_General19_Text   = "-?     - muestra el uso del comando"

const L_Help_Help_General20_Text   = "Ejemplos:"

const L_Help_Help_General21_Text   = "prnmngr -a -p ""impresora"" -m ""controlador"" -r ""lpt1:"""

const L_Help_Help_General22_Text   = "prnmngr -d -p ""impresora"" -s servidor"

const L_Help_Help_General23_Text   = "prnmngr -ac -p ""\\servidor\impresora"""

const L_Help_Help_General24_Text   = "prnmngr -d -p ""\\servidor\impresora"""

const L_Help_Help_General25_Text   = "prnmngr -x -s servidor"

const L_Help_Help_General26_Text   = "prnmngr -xo"

const L_Help_Help_General27_Text   = "prnmngr -l -s servidor"

const L_Help_Help_General28_Text   = "prnmngr -g"

const L_Help_Help_General29_Text   = "prnmngr -t -p ""\\servidor\impresora"""



'

' Messages to be displayed if the scripting host is not cscript

'

const L_Help_Help_Host01_Text      = "Este script se debe ejecutar desde el s�mbolo del sistema por medio del comando CScript.exe."

const L_Help_Help_Host02_Text      = "Por ejemplo: CScript script.vbs argumentos"

const L_Help_Help_Host03_Text      = ""

const L_Help_Help_Host04_Text      = "Para establecer a CScript como la aplicaci�n predeterminada para ejecutar archivos .VBS, ejecute lo siguiente:"

const L_Help_Help_Host05_Text      = "     CScript //H:CScript //S"

const L_Help_Help_Host06_Text      = "Podr� entonces ejecutar ""script.vbs argumentos"" sin necesidad de agregar CScript antes del script."



'

' General error messages

'

const L_Text_Error_General01_Text  = "No se pudo determinar el host de scripting."

const L_Text_Error_General02_Text  = "No se puede analizar la l�nea de comandos."

const L_Text_Error_General03_Text  = "C�digo de error de Win32"



'

' Miscellaneous messages

'

const L_Text_Msg_General01_Text    = "Impresora agregada"

const L_Text_Msg_General02_Text    = "No se puede agregar la impresora"

const L_Text_Msg_General03_Text    = "Conexi�n de impresora agregada"

const L_Text_Msg_General04_Text    = "No se puede agregar la conexi�n de impresora"

const L_Text_Msg_General05_Text    = "Impresora eliminada"

const L_Text_Msg_General06_Text    = "No se puede eliminar impresora"

const L_Text_Msg_General07_Text    = "Intentando eliminar impresora"

const L_Text_Msg_General08_Text    = "No se pueden eliminar las impresoras"

const L_Text_Msg_General09_Text    = "N�mero de impresoras y conexiones locales enumeradas"

const L_Text_Msg_General10_Text    = "N�mero de impresoras y conexiones locales eliminadas"

const L_Text_Msg_General11_Text    = "No se pueden enumerar impresoras"

const L_Text_Msg_General12_Text    = "La impresora predeterminada es"

const L_Text_Msg_General13_Text    = "No se puede obtener la impresora predeterminada"

const L_Text_Msg_General14_Text    = "No se puede establecer la impresora predeterminada"

const L_Text_Msg_General15_Text    = "La impresora predeterminada es ahora"

const L_Text_Msg_General16_Text    = "N�mero de conexiones de impresora enumeradas"

const L_Text_Msg_General17_Text    = "N�mero de conexiones de impresora eliminadas"

const L_Text_Msg_General18_Text    = "N�mero de impresoras locales enumeradas"

const L_Text_Msg_General19_Text    = "N�mero de impresoras locales eliminadas"



'

' Printer properties

'

const L_Text_Msg_Printer01_Text    = "Nombre de servidor"

const L_Text_Msg_Printer02_Text    = "Nombre de impresora"

const L_Text_Msg_Printer03_Text    = "Nombre del recurso compartido"

const L_Text_Msg_Printer04_Text    = "Nombre de controlador"

const L_Text_Msg_Printer05_Text    = "Nombre del puerto"

const L_Text_Msg_Printer06_Text    = "Comentario"

const L_Text_Msg_Printer07_Text    = "Ubicaci�n"

const L_Text_Msg_Printer08_Text    = "Archivo separador"

const L_Text_Msg_Printer09_Text    = "Procesador de impresi�n"

const L_Text_Msg_Printer10_Text    = "Tipo de datos"

const L_Text_Msg_Printer11_Text    = "Par�metros"

const L_Text_Msg_Printer12_Text    = "Atributos"

const L_Text_Msg_Printer13_Text    = "Prioridad"

const L_Text_Msg_Printer14_Text    = "Prioridad predeterminada"

const L_Text_Msg_Printer15_Text    = "Hora de inicio"

const L_Text_Msg_Printer16_Text    = "Tiempo final"

const L_Text_Msg_Printer17_Text    = "Cuenta de trabajos"

const L_Text_Msg_Printer18_Text    = "N�mero medio de p�ginas por minuto"

const L_Text_Msg_Printer19_Text    = "Estado de la impresora"

const L_Text_Msg_Printer20_Text    = "Estado de impresora extendido"

const L_Text_Msg_Printer21_Text    = "Estado de error detectado"

const L_Text_Msg_Printer22_Text    = "Estado de error detectado extendido"





'

' Printer status

'

const L_Text_Msg_Status01_Text     = "Otros"

const L_Text_Msg_Status02_Text     = "Desconocido"

const L_Text_Msg_Status03_Text     = "Inactivo"

const L_Text_Msg_Status04_Text     = "Imprimiendo"

const L_Text_Msg_Status05_Text     = "Calentamiento"

const L_Text_Msg_Status06_Text     = "Impresi�n detenida"

const L_Text_Msg_Status07_Text     = "Sin conexi�n"

const L_Text_Msg_Status08_Text     = "Pausado"

const L_Text_Msg_Status09_Text     = "Error"

const L_Text_Msg_Status10_Text     = "Ocupado"

const L_Text_Msg_Status11_Text     = "No disponible"

const L_Text_Msg_Status12_Text     = "En espera"

const L_Text_Msg_Status13_Text     = "Procesando"

const L_Text_Msg_Status14_Text     = "Inicializando"

const L_Text_Msg_Status15_Text     = "Ahorro de energ�a"

const L_Text_Msg_Status16_Text     = "Eliminaci�n pendiente"

const L_Text_Msg_Status17_Text     = "E/S activa"

const L_Text_Msg_Status18_Text     = "Alimentaci�n manual"

const L_Text_Msg_Status19_Text     = "Sin errores"

const L_Text_Msg_Status20_Text     = "Falta papel"

const L_Text_Msg_Status21_Text     = "No hay papel"

const L_Text_Msg_Status22_Text     = "Falta t�ner"

const L_Text_Msg_Status23_Text     = "Sin t�ner"

const L_Text_Msg_Status24_Text     = "Puerta abierta"

const L_Text_Msg_Status25_Text     = "Atascado"

const L_Text_Msg_Status26_Text     = "Servicio solicitado"

const L_Text_Msg_Status27_Text     = "Bandeja de salida llena"

const L_Text_Msg_Status28_Text     = "Problema con el papel"

const L_Text_Msg_Status29_Text     = "No se puede imprimir la p�gina"

const L_Text_Msg_Status30_Text     = "Intervenci�n del usuario requerida"

const L_Text_Msg_Status31_Text     = "Memoria insuficiente"

const L_Text_Msg_Status32_Text     = "Servidor desconocido"



'

' Debug messages

'

const L_Text_Dbg_Msg01_Text        = "En la funci�n AddPrinter"

const L_Text_Dbg_Msg02_Text        = "En la funci�n AddPrinterConnection"

const L_Text_Dbg_Msg03_Text        = "En la funci�n DelPrinter"

const L_Text_Dbg_Msg04_Text        = "En la funci�n DelAllPrinters"

const L_Text_Dbg_Msg05_Text        = "En la funci�n ListPrinters"

const L_Text_Dbg_Msg06_Text        = "En la funci�n GetDefaultPrinter"

const L_Text_Dbg_Msg07_Text        = "En la funci�n SetDefaultPrinter"

const L_Text_Dbg_Msg08_Text        = "En la funci�n ParseCommandLine"



main



'

' Main execution starts here

'

sub main



    dim iAction

    dim iRetval

    dim strServer

    dim strPrinter

    dim strDriver

    dim strPort

    dim strUser

    dim strPassword



    '

    ' Abort if the host is not cscript

    '

    if not IsHostCscript() then



        call wscript.echo(L_Help_Help_Host01_Text & vbCRLF & L_Help_Help_Host02_Text & vbCRLF & _

                          L_Help_Help_Host03_Text & vbCRLF & L_Help_Help_Host04_Text & vbCRLF & _

                          L_Help_Help_Host05_Text & vbCRLF & L_Help_Help_Host06_Text & vbCRLF)



        wscript.quit



    end if



    '

    ' Get command line parameters

    '

    iRetval = ParseCommandLine(iAction, strServer, strPrinter, strDriver, strPort, strUser, strPassword)



    if iRetval = kErrorSuccess then



        select case iAction



            case kActionAdd

                 iRetval = AddPrinter(strServer, strPrinter, strDriver, strPort, strUser, strPassword)



            case kActionAddConn

                 iRetval = AddPrinterConnection(strPrinter, strUser, strPassword)



            case kActionDel

                 iRetval = DelPrinter(strServer, strPrinter, strUser, strPassword)



            case kActionDelAll

                 iRetval = DelAllPrinters(kActionDelAll, strServer, strUser, strPassword)



            case kActionDelAllCon

                 iRetval = DelAllPrinters(kActionDelAllCon, strServer, strUser, strPassword)



            case kActionDelAllLocal

                 iRetval = DelAllPrinters(kActionDelAllLocal, strServer, strUser, strPassword)



            case kActionList

                 iRetval = ListPrinters(strServer, strUser, strPassword)



            case kActionGetDefaultPrinter

                 iRetval = GetDefaultPrinter(strUser, strPassword)



            case kActionSetDefaultPrinter

                 iRetval = SetDefaultPrinter(strPrinter, strUser, strPassword)



            case kActionUnknown

                 Usage(true)

                 exit sub



            case else

                 Usage(true)

                 exit sub



        end select



    end if



end sub



'

' Add a printer with minimum settings. Use prncnfg.vbs to

' set the complete configuration of a printer

'

function AddPrinter(strServer, strPrinter, strDriver, strPort, strUser, strPassword)



    on error resume next



    DebugPrint kDebugTrace, L_Text_Dbg_Msg01_Text

    DebugPrint kDebugTrace, L_Text_Msg_Printer01_Text & L_Space_Text & strServer

    DebugPrint kDebugTrace, L_Text_Msg_Printer02_Text & L_Space_Text & strPrinter

    DebugPrint kDebugTrace, L_Text_Msg_Printer04_Text & L_Space_Text & strDriver

    DebugPrint kDebugTrace, L_Text_Msg_Printer05_Text & L_Space_Text & strPort



    dim oPrinter

    dim oService

    dim iRetval



    if WmiConnect(strServer, kNameSpace, strUser, strPassword, oService) then



        set oPrinter = oService.Get("Win32_Printer").SpawnInstance_



    else



        AddPrinter = kErrorFailure



        exit function



    end if



    oPrinter.DriverName = strDriver

    oPrinter.PortName   = strPort

    oPrinter.DeviceID   = strPrinter



    oPrinter.Put_(kFlagCreateOnly)



    if Err.Number = kErrorSuccess then



        wscript.echo L_Text_Msg_General01_Text & L_Space_Text & strPrinter



        iRetval = kErrorSuccess



    else



        wscript.echo L_Text_Msg_General02_Text & L_Space_Text & strPrinter & L_Space_Text & L_Error_Text _

                     & L_Space_Text & L_Hex_Text & hex(Err.Number) & L_Space_Text & Err.Description



        '

        ' Try getting extended error information

        '

        call LastError()



        iRetval = kErrorFailure



    end if



    AddPrinter = iRetval



end function



'

' Add a printer connection

'

function AddPrinterConnection(strPrinter, strUser, strPassword)



    on error resume next



    DebugPrint kDebugTrace, L_Text_Dbg_Msg02_Text



    dim oPrinter

    dim oService

    dim iRetval

    dim uResult



    '

    ' Initialize return value

    '

    iRetval = kErrorFailure



    '

    ' We connect to the local server

    '

    if WmiConnect("", kNameSpace, strUser, strPassword, oService) then



        set oPrinter = oService.Get("Win32_Printer")



    else



        AddPrinterConnection = kErrorFailure



        exit function



    end if



    '

    ' Check if Get was successful

    '

    if Err.Number = kErrorSuccess then



        '

        ' The Err object indicates whether the WMI provider reached the execution

        ' of the function that adds a printer connection. The uResult is the Win32

        ' error code returned by the static method that adds a printer connection

        '

        uResult = oPrinter.AddPrinterConnection(strPrinter)



        if Err.Number = kErrorSuccess then



            if uResult = kErrorSuccess then



                wscript.echo L_Text_Msg_General03_Text & L_Space_Text & strPrinter



                iRetval = kErrorSuccess



            else



                wscript.echo L_Text_Msg_General04_Text & L_Space_Text & L_Text_Error_General03_Text _

                             & L_Space_text & uResult



            end if



        else



            wscript.echo L_Text_Msg_General04_Text & L_Space_Text & strPrinter & L_Space_Text _

                         & L_Error_Text & L_Space_Text & L_Hex_Text & hex(Err.Number) & L_Space_Text _

                         & Err.Description



        end if



    else



        wscript.echo L_Text_Msg_General04_Text & L_Space_Text & strPrinter & L_Space_Text _

                     & L_Error_Text & L_Space_Text & L_Hex_Text & hex(Err.Number) & L_Space_Text _

                     & Err.Description



    end if



    AddPrinterConnection = iRetval



end function



'

' Delete a printer or a printer connection

'

function DelPrinter(strServer, strPrinter, strUser, strPassword)



    on error resume next



    DebugPrint kDebugTrace, L_Text_Dbg_Msg03_Text

    DebugPrint kDebugTrace, L_Text_Msg_Printer01_Text & L_Space_Text & strServer

    DebugPrint kDebugTrace, L_Text_Msg_Printer02_Text & L_Space_Text & strPrinter



    dim oService

    dim oPrinter

    dim iRetval



    iRetval = kErrorFailure



    if WmiConnect(strServer, kNameSpace, strUser, strPassword, oService) then



        set oPrinter = oService.Get("Win32_Printer.DeviceID='" & strPrinter & "'")



    else



        DelPrinter = kErrorFailure



        exit function



    end if



    '

    ' Check if Get was successful

    '

    if Err.Number = kErrorSuccess then



        oPrinter.Delete_



        if Err.Number = kErrorSuccess then



            wscript.echo L_Text_Msg_General05_Text & L_Space_Text & strPrinter



            iRetval = kErrorSuccess



        else



            wscript.echo L_Text_Msg_General06_Text & L_Space_Text & strPrinter & L_Space_Text _

                         & L_Error_Text & L_Space_Text & L_Hex_Text & hex(Err.Number) _

                         & L_Space_Text & Err.Description



            '

            ' Try getting extended error information

            '

            call LastError()



        end if



    else



        wscript.echo L_Text_Msg_General06_Text & L_Space_Text & strPrinter & L_Space_Text _

                     & L_Error_Text & L_Space_Text & L_Hex_Text & hex(Err.Number) _

                     & L_Space_Text & Err.Description



        '

        ' Try getting extended error information

        '

        call LastError()



    end if



    DelPrinter = iRetval



end function



'

' Delete all local printers and connections on a machine

'

function DelAllPrinters(kAction, strServer, strUser, strPassword)



    on error resume next



    DebugPrint kDebugTrace, L_Text_Dbg_Msg04_Text



    dim Printers

    dim oPrinter

    dim oService

    dim iResult

    dim iTotal

    dim iTotalDeleted

    dim strPrinterName

    dim bDelete

    dim bConnection

    dim strTemp



    if WmiConnect(strServer, kNameSpace, strUser, strPassword, oService) then



        set Printers = oService.InstancesOf("Win32_Printer")



    else



        DelAllPrinters = kErrorFailure



        exit function



    end if



    if Err.Number <> kErrorSuccess then



        wscript.echo L_Text_Msg_General11_Text & L_Space_Text & L_Error_Text & L_Space_Text _

                     & L_Hex_Text & hex(Err.Number) & L_Space_Text & Err.Description



        DelAllPrinters = kErrorFailure



        exit function



    end if



    iTotal = 0

    iTotalDeleted = 0



    for each oPrinter in Printers



        strPrinterName = oPrinter.DeviceID



        bConnection = oPrinter.Network



        if kAction = kActionDelAll then



            bDelete = 1



            iTotal = iTotal + 1



        elseif kAction = kActionDelAllCon and bConnection then



            bDelete = 1



            iTotal = iTotal + 1



        elseif kAction = kActionDelAllLocal and not bConnection then



            bDelete = 1



            iTotal = iTotal + 1



        else



            bDelete = 0



        end if



        if bDelete = 1 then



            if bConnection then



                strTemp = L_Space_Text & L_Connection_Text & L_Space_Text



            else



                strTemp = L_Space_Text



            end if



            '

            ' Delete printer instance

            '

            oPrinter.Delete_



            if Err.Number = kErrorSuccess then



                wscript.echo L_Text_Msg_General05_Text & strTemp & oPrinter.DeviceID



                iTotalDeleted = iTotalDeleted + 1



            else



                wscript.echo L_Text_Msg_General06_Text & strTemp & strPrinterName _

                             & L_Space_Text & L_Error_Text & L_Space_Text & L_Hex_Text _

                             & hex(Err.Number) & L_Space_Text & Err.Description



                '

                ' Try getting extended error information

                '

                call LastError()



                '

                ' Continue deleting the rest of the printers despite this error

                '

                Err.Clear



            end if



        end if



    next



    wscript.echo L_Empty_Text



    if kAction = kActionDelAll then



        wscript.echo L_Text_Msg_General09_Text & L_Space_Text & iTotal

        wscript.echo L_Text_Msg_General10_Text & L_Space_Text & iTotalDeleted



    elseif kAction = kActionDelAllCon then



        wscript.echo L_Text_Msg_General16_Text & L_Space_Text & iTotal

        wscript.echo L_Text_Msg_General17_Text & L_Space_Text & iTotalDeleted



    elseif kAction = kActionDelAllLocal then



        wscript.echo L_Text_Msg_General18_Text & L_Space_Text & iTotal

        wscript.echo L_Text_Msg_General19_Text & L_Space_Text & iTotalDeleted



    else



    end if



    DelAllPrinters = kErrorSuccess



end function



'

' List the printers

'

function ListPrinters(strServer, strUser, strPassword)



    on error resume next



    DebugPrint kDebugTrace, L_Text_Dbg_Msg05_Text



    dim Printers

    dim oService

    dim oPrinter

    dim iTotal



    if WmiConnect(strServer, kNameSpace, strUser, strPassword, oService) then



        set Printers = oService.InstancesOf("Win32_Printer")



    else



        ListPrinters = kErrorFailure



        exit function



    end if



    if Err.Number <> kErrorSuccess then



        wscript.echo L_Text_Msg_General11_Text & L_Space_Text & L_Error_Text & L_Space_Text _

                     & L_Hex_Text & hex(Err.Number) & L_Space_Text & Err.Description



        ListPrinters = kErrorFailure



        exit function



    end if



    iTotal = 0



    for each oPrinter in Printers



        iTotal = iTotal + 1



        wscript.echo L_Empty_Text

        wscript.echo L_Text_Msg_Printer01_Text & L_Space_Text & strServer

        wscript.echo L_Text_Msg_Printer02_Text & L_Space_Text & oPrinter.DeviceID

        wscript.echo L_Text_Msg_Printer03_Text & L_Space_Text & oPrinter.ShareName

        wscript.echo L_Text_Msg_Printer04_Text & L_Space_Text & oPrinter.DriverName

        wscript.echo L_Text_Msg_Printer05_Text & L_Space_Text & oPrinter.PortName

        wscript.echo L_Text_Msg_Printer06_Text & L_Space_Text & oPrinter.Comment

        wscript.echo L_Text_Msg_Printer07_Text & L_Space_Text & oPrinter.Location

        wscript.echo L_Text_Msg_Printer08_Text & L_Space_Text & oPrinter.SepFile

        wscript.echo L_Text_Msg_Printer09_Text & L_Space_Text & oPrinter.PrintProcessor

        wscript.echo L_Text_Msg_Printer10_Text & L_Space_Text & oPrinter.PrintJobDataType

        wscript.echo L_Text_Msg_Printer11_Text & L_Space_Text & oPrinter.Parameters

        wscript.echo L_Text_Msg_Printer12_Text & L_Space_Text & CSTR(oPrinter.Attributes)

        wscript.echo L_Text_Msg_Printer13_Text & L_Space_Text & CSTR(oPrinter.Priority)

        wscript.echo L_Text_Msg_Printer14_Text & L_Space_Text & CStr(oPrinter.DefaultPriority)



        if CStr(oPrinter.StartTime) <> "" and CStr(oPrinter.UntilTime) <> "" then



            wscript.echo L_Text_Msg_Printer15_Text & L_Space_Text & Mid(Mid(CStr(oPrinter.StartTime), 9, 4), 1, 2) & "h" & Mid(Mid(CStr(oPrinter.StartTime), 9, 4), 3, 2)

            wscript.echo L_Text_Msg_Printer16_Text & L_Space_Text & Mid(Mid(CStr(oPrinter.UntilTime), 9, 4), 1, 2) & "h" & Mid(Mid(CStr(oPrinter.UntilTime), 9, 4), 3, 2)



        end if



        wscript.echo L_Text_Msg_Printer17_Text & L_Space_Text & CStr(oPrinter.Jobs)

        wscript.echo L_Text_Msg_Printer18_Text & L_Space_Text & CStr(oPrinter.AveragePagesPerMinute)

        wscript.echo L_Text_Msg_Printer19_Text & L_Space_Text & PrnStatusToString(oPrinter.PrinterStatus)

        wscript.echo L_Text_Msg_Printer20_Text & L_Space_Text & ExtPrnStatusToString(oPrinter.ExtendedPrinterStatus)

        wscript.echo L_Text_Msg_Printer21_Text & L_Space_Text & DetectedErrorStateToString(oPrinter.DetectedErrorState)

        wscript.echo L_Text_Msg_Printer22_Text & L_Space_Text & ExtDetectedErrorStateToString(oPrinter.ExtendedDetectedErrorState)



        Err.Clear



    next



    wscript.echo L_Empty_Text

    wscript.echo L_Text_Msg_General09_Text & L_Space_Text & iTotal



    ListPrinters = kErrorSuccess



end function



'

' Get the default printer

'

function GetDefaultPrinter(strUser, strPassword)



    on error resume next



    DebugPrint kDebugTrace, L_Text_Dbg_Msg06_Text



    dim oService

    dim oPrinter

    dim iRetval

    dim oEnum



    iRetval = kErrorFailure



    '

    ' We connect to the local server

    '

    if WmiConnect("", kNameSpace, strUser, strPassword, oService) then



        set oEnum    = oService.ExecQuery("select DeviceID from Win32_Printer where default=true")



    else



        SetDefaultPrinter = kErrorFailure



        exit function



    end if



    if Err.Number = kErrorSuccess then



         for each oPrinter in oEnum



            wscript.echo L_Text_Msg_General12_Text & L_Space_Text & oPrinter.DeviceID



         next



         iRetval = kErrorSuccess



    else



        wscript.echo L_Text_Msg_General13_Text & L_Space_Text & L_Error_Text & L_Space_Text _

                     & L_Hex_Text & hex(Err.Number) & L_Space_Text & Err.Description



    end if



    GetDefaultPrinter = iRetval



end function



'

' Set the default printer

'

function SetDefaultPrinter(strPrinter, strUser, strPassword)



    'on error resume next



    DebugPrint kDebugTrace, L_Text_Dbg_Msg07_Text



    dim oService

    dim oPrinter

    dim iRetval

    dim uResult



    iRetval = kErrorFailure



    '

    ' We connect to the local server

    '

    if WmiConnect("", kNameSpace, strUser, strPassword, oService) then



        set oPrinter = oService.Get("Win32_Printer.DeviceID='" & strPrinter & "'")



    else



        SetDefaultPrinter = kErrorFailure



        exit function



    end if



    '

    ' Check if Get was successful

    '

    if Err.Number = kErrorSuccess then



        '

        ' The Err object indicates whether the WMI provider reached the execution

        ' of the function that sets the default printer. The uResult is the Win32

        ' error code of the spooler function that sets the default printer

        '

        uResult = oPrinter.SetDefaultPrinter



        if Err.Number = kErrorSuccess then



            if uResult = kErrorSuccess then



                wscript.echo L_Text_Msg_General15_Text & L_Space_Text & strPrinter



                iRetval = kErrorSuccess



            else



                wscript.echo L_Text_Msg_General14_Text & L_Space_Text _

                             & L_Text_Error_General03_Text& L_Space_Text & uResult



            end if



        else



            wscript.echo L_Text_Msg_General14_Text & L_Space_Text & L_Error_Text & L_Space_Text _

                         & L_Hex_Text & hex(Err.Number) & L_Space_Text & Err.Description



        end if



    else



        wscript.echo L_Text_Msg_General14_Text & L_Space_Text & L_Error_Text & L_Space_Text _

                     & L_Hex_Text & hex(Err.Number) & L_Space_Text & Err.Description



        '

        ' Try getting extended error information

        '

        call LastError()



    end if



    SetDefaultPrinter = iRetval



end function



'

' Converts the printer status to a string

'

function PrnStatusToString(Status)



    dim str



    str = L_Empty_Text



    select case Status



        case 1

            str = str + L_Text_Msg_Status01_Text + L_Space_Text



        case 2

            str = str + L_Text_Msg_Status02_Text + L_Space_Text



        case 3

            str = str + L_Text_Msg_Status03_Text + L_Space_Text



        case 4

            str = str + L_Text_Msg_Status04_Text + L_Space_Text



        case 5

            str = str + L_Text_Msg_Status05_Text + L_Space_Text



        case 6

            str = str + L_Text_Msg_Status06_Text + L_Space_Text



        case 7

            str = str + L_Text_Msg_Status07_Text + L_Space_Text



    end select



    PrnStatusToString = str



end function



'

' Converts the extended printer status to a string

'

function ExtPrnStatusToString(Status)



    dim str



    str = L_Empty_Text



    select case Status



        case 1

            str = str + L_Text_Msg_Status01_Text + L_Space_Text



        case 2

            str = str + L_Text_Msg_Status02_Text + L_Space_Text



        case 3

            str = str + L_Text_Msg_Status03_Text + L_Space_Text



        case 4

            str = str + L_Text_Msg_Status04_Text + L_Space_Text



        case 5

            str = str + L_Text_Msg_Status05_Text + L_Space_Text



        case 6

            str = str + L_Text_Msg_Status06_Text + L_Space_Text



        case 7

            str = str + L_Text_Msg_Status07_Text + L_Space_Text



        case 8

            str = str + L_Text_Msg_Status08_Text + L_Space_Text



        case 9

            str = str + L_Text_Msg_Status09_Text + L_Space_Text



        case 10

            str = str + L_Text_Msg_Status10_Text + L_Space_Text



        case 11

            str = str + L_Text_Msg_Status11_Text + L_Space_Text



        case 12

            str = str + L_Text_Msg_Status12_Text + L_Space_Text



        case 13

            str = str + L_Text_Msg_Status13_Text + L_Space_Text



        case 14

            str = str + L_Text_Msg_Status14_Text + L_Space_Text



        case 15

            str = str + L_Text_Msg_Status15_Text + L_Space_Text



        case 16

            str = str + L_Text_Msg_Status16_Text + L_Space_Text



        case 17

            str = str + L_Text_Msg_Status17_Text + L_Space_Text



        case 18

            str = str + L_Text_Msg_Status18_Text + L_Space_Text



    end select



    ExtPrnStatusToString = str



end function



'

' Converts the detected error state to a string

'

function DetectedErrorStateToString(Status)



    dim str



    str = L_Empty_Text



    select case Status



        case 0

            str = str + L_Text_Msg_Status02_Text + L_Space_Text



        case 1

            str = str + L_Text_Msg_Status01_Text + L_Space_Text



        case 2

            str = str + L_Text_Msg_Status01_Text + L_Space_Text



        case 3

            str = str + L_Text_Msg_Status20_Text + L_Space_Text



        case 4

            str = str + L_Text_Msg_Status21_Text + L_Space_Text



        case 5

            str = str + L_Text_Msg_Status22_Text + L_Space_Text



        case 6

            str = str + L_Text_Msg_Status23_Text + L_Space_Text



        case 7

            str = str + L_Text_Msg_Status24_Text + L_Space_Text



        case 8

            str = str + L_Text_Msg_Status25_Text + L_Space_Text



        case 9

            str = str + L_Text_Msg_Status07_Text + L_Space_Text



        case 10

            str = str + L_Text_Msg_Status26_Text + L_Space_Text



        case 11

            str = str + L_Text_Msg_Status27_Text + L_Space_Text



    end select



    DetectedErrorStateToString = str



end function



'

' Converts the extended detected error state to a string

'

function ExtDetectedErrorStateToString(Status)



    dim str



    str = L_Empty_Text



    select case Status



        case 0

            str = str + L_Text_Msg_Status02_Text + L_Space_Text



        case 1

            str = str + L_Text_Msg_Status01_Text + L_Space_Text



        case 2

            str = str + L_Text_Msg_Status01_Text + L_Space_Text



        case 3

            str = str + L_Text_Msg_Status20_Text + L_Space_Text



        case 4

            str = str + L_Text_Msg_Status21_Text + L_Space_Text



        case 5

            str = str + L_Text_Msg_Status22_Text + L_Space_Text



        case 6

            str = str + L_Text_Msg_Status23_Text + L_Space_Text



        case 7

            str = str + L_Text_Msg_Status24_Text + L_Space_Text



        case 8

            str = str + L_Text_Msg_Status25_Text + L_Space_Text



        case 9

            str = str + L_Text_Msg_Status07_Text + L_Space_Text



        case 10

            str = str + L_Text_Msg_Status26_Text + L_Space_Text



        case 11

            str = str + L_Text_Msg_Status27_Text + L_Space_Text



        case 12

            str = str + L_Text_Msg_Status28_Text + L_Space_Text



        case 13

            str = str + L_Text_Msg_Status29_Text + L_Space_Text



        case 14

            str = str + L_Text_Msg_Status30_Text + L_Space_Text



        case 15

            str = str + L_Text_Msg_Status31_Text + L_Space_Text



        case 16

            str = str + L_Text_Msg_Status32_Text + L_Space_Text



    end select



    ExtDetectedErrorStateToString = str



end function



'

' Debug display helper function

'

sub DebugPrint(uFlags, strString)



    if gDebugFlag = true then



        if uFlags = kDebugTrace then



            wscript.echo L_Debug_Text & L_Space_Text & strString



        end if



        if uFlags = kDebugError then



            if Err <> 0 then



                wscript.echo L_Debug_Text & L_Space_Text & strString & L_Space_Text _

                             & L_Error_Text & L_Space_Text & L_Hex_Text & hex(Err.Number) _

                             & L_Space_Text & Err.Description



            end if



        end if



    end if



end sub



'

' Parse the command line into its components

'

function ParseCommandLine(iAction, strServer, strPrinter, strDriver, strPort, strUser, strPassword)



    on error resume next



    DebugPrint kDebugTrace, L_Text_Dbg_Msg08_Text



    dim oArgs

    dim iIndex



    iAction = kActionUnknown

    iIndex  = 0



    set oArgs = wscript.Arguments



    while iIndex < oArgs.Count



        select case oArgs(iIndex)



            case "-a"

                iAction = kActionAdd



            case "-ac"

                iAction = kActionAddConn



            case "-d"

                iAction = kActionDel



            case "-x"

                iAction = kActionDelAll



            case "-xc"

                iAction = kActionDelAllCon



            case "-xo"

                iAction = kActionDelAllLocal



            case "-l"

                iAction = kActionList



            case "-g"

                iAction = kActionGetDefaultPrinter



            case "-t"

                iAction = kActionSetDefaultPrinter



            case "-s"

                iIndex = iIndex + 1

                strServer = RemoveBackslashes(oArgs(iIndex))



            case "-p"

                iIndex = iIndex + 1

                strPrinter = oArgs(iIndex)



            case "-m"

                iIndex = iIndex + 1

                strDriver = oArgs(iIndex)



            case "-u"

                iIndex = iIndex + 1

                strUser = oArgs(iIndex)



            case "-w"

                iIndex = iIndex + 1

                strPassword = oArgs(iIndex)



            case "-r"

                iIndex = iIndex + 1

                strPort = oArgs(iIndex)



            case "-?"

                Usage(true)

                exit function



            case else

                Usage(true)

                exit function



        end select



        iIndex = iIndex + 1



    wend



    if Err = kErrorSuccess then



        ParseCommandLine = kErrorSuccess



    else



        wscript.echo L_Text_Error_General02_Text & L_Space_Text & L_Error_Text & L_Space_Text _

                     & L_Hex_Text & hex(Err.Number) & L_Space_text & Err.Description



        ParseCommandLine = kErrorFailure



    end if



end  function



'

' Display command usage.

'

sub Usage(bExit)



    wscript.echo L_Help_Help_General01_Text

    wscript.echo L_Help_Help_General02_Text

    wscript.echo L_Help_Help_General03_Text

    wscript.echo L_Help_Help_General04_Text

    wscript.echo L_Help_Help_General05_Text

    wscript.echo L_Help_Help_General06_Text

    wscript.echo L_Help_Help_General07_Text

    wscript.echo L_Help_Help_General08_Text

    wscript.echo L_Help_Help_General09_Text

    wscript.echo L_Help_Help_General10_Text

    wscript.echo L_Help_Help_General11_Text

    wscript.echo L_Help_Help_General12_Text

    wscript.echo L_Help_Help_General13_Text

    wscript.echo L_Help_Help_General14_Text

    wscript.echo L_Help_Help_General15_Text

    wscript.echo L_Help_Help_General16_Text

    wscript.echo L_Help_Help_General17_Text

    wscript.echo L_Help_Help_General18_Text

    wscript.echo L_Help_Help_General19_Text

    wscript.echo L_Empty_Text

    wscript.echo L_Help_Help_General20_Text

    wscript.echo L_Help_Help_General21_Text

    wscript.echo L_Help_Help_General22_Text

    wscript.echo L_Help_Help_General23_Text

    wscript.echo L_Help_Help_General24_Text

    wscript.echo L_Help_Help_General25_Text

    wscript.echo L_Help_Help_General26_Text

    wscript.echo L_Help_Help_General27_Text

    wscript.echo L_Help_Help_General28_Text

    wscript.echo L_Help_Help_General29_Text



    if bExit then



        wscript.quit(1)



    end if



end sub



'

' Determines which program is being used to run this script.

' Returns true if the script host is cscript.exe

'

function IsHostCscript()



    on error resume next



    dim strFullName

    dim strCommand

    dim i, j

    dim bReturn



    bReturn = false



    strFullName = WScript.FullName



    i = InStr(1, strFullName, ".exe", 1)



    if i <> 0 then



        j = InStrRev(strFullName, "\", i, 1)



        if j <> 0 then



            strCommand = Mid(strFullName, j+1, i-j-1)



            if LCase(strCommand) = "cscript" then



                bReturn = true



            end if



        end if



    end if



    if Err <> 0 then



        wscript.echo L_Text_Error_General01_Text & L_Space_Text & L_Error_Text & L_Space_Text _

                     & L_Hex_Text & hex(Err.Number) & L_Space_Text & Err.Description



    end if



    IsHostCscript = bReturn



end function



'

' Retrieves extended information about the last error that occurred

' during a WBEM operation. The methods that set an SWbemLastError

' object are GetObject, PutInstance, DeleteInstance

'

sub LastError()



    on error resume next



    dim oError



    set oError = CreateObject("WbemScripting.SWbemLastError")



    if Err = kErrorSuccess then



        wscript.echo L_Operation_Text            & L_Space_Text & oError.Operation

        wscript.echo L_Provider_Text             & L_Space_Text & oError.ProviderName

        wscript.echo L_Description_Text          & L_Space_Text & oError.Description

        wscript.echo L_Text_Error_General03_Text & L_Space_Text & oError.StatusCode



    end if



end sub



'

' Connects to the WMI service on a server. oService is returned as a service

' object (SWbemServices)

'

function WmiConnect(strServer, strNameSpace, strUser, strPassword, oService)



    on error resume next



    dim oLocator

    dim bResult



    oService = null



    bResult  = false



    set oLocator = CreateObject("WbemScripting.SWbemLocator")



    if Err = kErrorSuccess then



        set oService = oLocator.ConnectServer(strServer, strNameSpace, strUser, strPassword)



        if Err = kErrorSuccess then



            bResult = true



            oService.Security_.impersonationlevel = 3



            '

            ' Required to perform administrative tasks on the spooler service

            '

            oService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege"



            Err.Clear



        else



            wscript.echo L_Text_Msg_General11_Text & L_Space_Text & L_Error_Text _

                         & L_Space_Text & L_Hex_Text & hex(Err.Number) & L_Space_Text _

                         & Err.Description



        end if



    else



        wscript.echo L_Text_Msg_General10_Text & L_Space_Text & L_Error_Text _

                     & L_Space_Text & L_Hex_Text & hex(Err.Number) & L_Space_Text _

                     & Err.Description



    end if



    WmiConnect = bResult



end function



'

' Remove leading "\\" from server name

'

function RemoveBackslashes(strServer)



    dim strRet



    strRet = strServer



    if Left(strServer, 2) = "\\" and Len(strServer) > 2 then



        strRet = Mid(strServer, 3)



    end if



    RemoveBackslashes = strRet



end function


Youez - 2016 - github.com/yon3zu
LinuXploit