Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- alias -l get_printer_locator {
- :a
- if ($com(printer_locator)) .comclose printer_locator
- if ($com(printer_services)) .comclose printer_services
- if ($var(%r,1).local) return %r
- if ($com($2)) .comclose $2
- set -l %r
- .comopen printer_locator WbemScripting.SWbemLocator
- if ($comerr) goto a
- if (!$com(printer_locator,ConnectServer,3,dispatch* printer_services)) && ($comerr) goto a
- if (!$com(printer_services,ExecQuery,3,bstr,Select * from $1,dispatch* $2)) && ($comerr) goto a
- if ($com($2,Count,3)) %r = $com($2).result
- goto a
- }
- alias get_printers {
- set -l %com get_printers
- set -l %n $get_printer_locator(Win32_Printer,%com)
- if (!%n) {
- if ($com(%com)) .comclose %com
- return
- }
- if ($hget(%com)) hfree %com
- hmake %com
- set -l %x 1
- :l
- if (WINPRINT != $comval(%com,%x,PrintProcessor)) hadd %com %x $comval(%com,%x,Default) $comval(%com,%x,Name)
- inc %x
- if (%x <= %n) goto l
- .comclose %com
- if ($isid) return $hget(%com,0).item
- }
- alias print_file {
- set -l %r $false
- if (!$isfile($1)) goto end
- set -l %cmd notepad /PT $qt($1) $qt($2)
- set -l %id $ticks $+ $rand(1111,9999)
- if ($com(pid_shell $+ %id)) .comclose pid_shell $+ %id
- .comopen pid_shell $+ %id WScript.Shell
- if ($comerr) goto end
- if (!$com(pid_shell $+ %id,Run,1,bstr,%cmd,int,0,bool,false)) goto end
- %r = $true
- :end
- if ($com(pid_shell $+ %id)) .comclose pid_shell $+ %id
- return %r
- }
- alias exemplo_printers {
- if ($get_printers) {
- set -l %x $v1
- while %x {
- tokenize 32 $hget(get_printers,%x).data
- echo -a Padrão: $1 Nome: $2-
- dec %x
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement