LOBO Valued Contributor
Joined: 14 Mar 2002 Posts: 241 Location: Wilmington, Delaware, USA
|
Posted: Tue Mar 18, 2003 7:11 pm Post subject: Pull printers from registry |
|
|
This example is from a program I am working on and uses both MT.dll & VDSLists.dll as I took this out of a program I am working on.
Code: |
Rem ===========================================================================
Rem Example using of pulling printers from registry
Rem By LOBO
Rem This code uses MT.dll & VDSLists.dll
Rem Thought this might help someone
Rem Feel free to use code how you like
Rem ===========================================================================
directory change,@path(%0)
external vdslists.dll
external mt.dll
OPTION SCALE,96
option fieldsep,@chr(44)
option decimalsep,.
extlist fieldsep,|
Title New
DIALOG CREATE,Printers from registry example,-1,0,433,161,class printerexample
DIALOG ADD,MENU,File,Exit
DIALOG ADD,BUTTON,Run,112,88,64,24,Run
DIALOG ADD,BUTTON,Exit,112,288,64,24,Exit
extlist window,#printerexample
extlist add,style,style1,Arial,8,B,,
extlist distance,4
extlist add,collist,printlist,15,0,424,96,Printer Name|165@cr()Printer Port|165@cr()Default|90,style1
extlist add,status,status,16,140@cr()135@cr()158,,style1
DIALOG SHOW
goto timer
:Evloop
wait event,1
goto @event()
:timer
extlist set,status,@datetime(mmm d"," yyyy h:nn ampm )@cr()Printers: %%nprinters@cr()Example by: LOBO"
goto evloop
:RunBUTTON
list create,2
if @equal(@mt(os,platform),2)
gosub nt
else
gosub 9x
end
gosub printers
goto evloop
:ExitBUTTON
:ExitMENU
:Close
exit
Rem ------------ Sub Routines ---------------------
:9x
LIST REGKEYS,2,LOCAL,System\CurrentControlSet\Control\Print\Printers
parse "%%defpname",@regread(LOCAL,Software\Microsoft\Windows\CurrentVersion\Windows,Device)
exit
:nt
LIST REGKEYS,2,LOCAL,System\CurrentControlSet\Control\Print\Printers
LIST REGKEYS,2,CURUSER,Printers\Connections
parse "%%defpname",@regread(CURUSER,Software\Microsoft\Windows NT\CurrentVersion\Windows,Device)
exit
:printers
%%nprinters = @count(2)
if @equal(%%nprinters,-1)
extlist list,add,printlist,No printers were found in the registry@tab()@tab()
else
%%start = 0
repeat
%%pnetwork = 0
LIST SEEK,2,%%start
%%prntname = @item(2)
%%prntport = @regread(LOCAL,System\CurrentControlSet\Control\Print\Printers\%%prntname,Port)
rem checks for network printer in registry and changes , in entries to \
if @equal(@substr(%%prntname,1,2),@chr(44)@chr(44))
%%pnetwork = @succ(%%pnetwork)
%%Line = %%prntname
%%Step = 1
Repeat
%C = @Substr(%%Line,%%Step,%%Step)
If @Equal(%C,",")
%%Line = @strdel(%%Line,%%Step,%%Step)
%%Line = @strins(%%Line,%%Step,\)
End
%%Step = @Succ(%%Step)
Until @Equal(%%Step,@Len(%%Line))
end
if @equal(%%pnetwork,1)
%%prntname = %%Line
%%prntport = %%Line
end
if @equal(%%defpname,%%prntname)
extlist list,add,printlist,%%prntname@tab()%%prntport@tab()yes
else
extlist list,add,printlist,%%prntname@tab()%%prntport@tab()
end
%%start = @succ(%%start)
until @equal(%%nprinters,%%start)
end
exit
|
Regards,
Mark |
|