Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Doesn' t anyone know??! ActiveX dll........

Status
Not open for further replies.

cturland

Programmer
Sep 25, 2000
66
GB
I've posted this a few times before but never had a reply, its still causing me problems!

I'm trying to access the available printers in an ActiveX dll on a web interface. This is a bit of sample code:

Function AvailPrinters() as String

dim PrintData as Printers
dim sPrinters$

For Each PrintData in Printers
sPrinters$ = Printdata.DeviceName & " " & Printdata.driverName & ","
Next

AvailPrinters = sPrinters$

End Function

When I call this function from a VB app it returns a comma separated string of all the printers available. I then tried to include this dll in a ASP page and it returns an error saying that it can't access the printers.

Not sure if this is important but when I call the API function 'GetUserName' in my VB app it returns my username but when I call it in Internet Explorer through my dll I get 'SYSTEM'.

I'm really stuck, I've also tried launching an exe that used the dll through an Cold Fusion page but still no luck.

Any help would be really appreciated,
Rgds,
Carl
 
I really doubt that you can get a list of printers hooked up to your web server through an ActiveX DLL. A basic web browser should never have that kind of permissions. Also, if you tried to print to it, it would print to a printer on the web server, not on the user's machine.

I think the reason is when you go through your web server it assigns you a special guest access to files stored in the website area of that server. Accessing the printers requires you to have an admin or specific user username that is not "guest" or "system". You could have your server (assuming NT) query you for a username and password. If you entered a real user on the NT computer, and then tried your DLL, it might let you work that, because then it knows who you are. Otherwise, you are just logged in as "guest" or "system" with no access to anything other than the web server files.

Why are you trying to print to a printer on your web server? Harold Blackorby
hblackorby@scoreinteractive.com
St. Louis, MO
 
I think you are trying to get a list of printers on the CLIENT machine (web browser) and send custom data to the client printer, correct?

In that case you will need to use client side VBScript, not .ASP code to query the printers.

You will need to instantiate the object with either an <OBJECT> tag or a createobject call. You'll also need to make sure the control is on the client machine.

IE 5 considers printing to be a security risk, so you will not be able to print w/out poping up a dialog box.


Have you considered just using Window.Print() ?

 
If you are using Windows 2000, try accessing the active directory structure....that will let you get at all entities connected to a Win2000 machine....you may have to poke around with permissions a bit...good luck
 
Hi all,

I've still got the problem!

I didn't explain myself properly in the first message. I need the client accesing the web page to be able to see and print to the printers that the server have access to. I know it sounds a bit strange but it is required! I've looked everywhere and it doesn't seem to have been done before......
 
You will need to look on Microsoft's site for information on printing from a service. I know it is available, I'm just not sure exactly where.

There are probably some registry changes you need to make so that printers are available for the IUSR_YOURMACHINE account.
 
Use WMI to get a lsit of printers on an iis server from a client machine.

1. create a new VB dll with the following code in a class file of your choice

Public Function EnumerateServerPrinters() As Variant

'reference WMI Scripting v1.2 library (c:\winnt\system32\wbem\wbemdisp.tlb)

' dimension variables
Dim PrinterEnumList() As Variant 'initialize the dynamic return array
Dim varWMIServices As SWbemServices
Dim varPrinterObject As SWbemObjectSet
Dim varPrinterFound As SWbemObject
Dim varPrinterProperty As SWbemProperty
Dim varNumofPrintersFound As Long
Dim varIteratePrinters As Long

' set objects
Set varWMIServices = GetObject(&quot;winmgmts:&quot;)
Set varPrinterObject = varWMIServices.InstancesOf(&quot;Win32_PrinterConfiguration&quot;)
varNumofPrintersFound = varPrinterObject.Count
varIteratePrinters = 0

If varNumofPrintersFound <> 0 Then
ReDim PrinterEnumList(varNumofPrintersFound) '0 based array = num of printers found
Else
Exit Function
End If


For Each varPrinterFound In varPrinterObject 'for each printer
For Each varPrinterProperty In varPrinterFound.Properties_ 'for each printer property
Select Case varPrinterProperty.Name
Case Is = &quot;DeviceName&quot; 'physical device name of printer
PrinterEnumList(varIteratePrinters) = varPrinterProperty.Value
End Select
Next
varIteratePrinters = varIteratePrinters + 1
Next

EnumerateServerPrinters = PrinterEnumList()

End Function

2. compile the dll and create a COM object on your server or just register the new dll on the server.

3. create an asp page to reference this new dll.

dim objMyNewDLL ' dimension COM object container
dim objPrinterList ' dimension COM object printer list container
dim objPrinterFound ' dimension printer found boolean
dim objIteratePrinterListing ' dimension loop iteration variable

objPrinterFound = False ' printer not found as default

set objMyNewDLL = Server.CreateObject(&quot;MyNewDLLName.MyNewClassName&quot;) ' instantiate server COM object
objPrinterList = objMyNewDLL.EnumerateServerPrinters ' get printer listing

if objPrinterList(0) = &quot;&quot; then ' first printer will not be NULL unless no printers defined
objPrinterFound = False ' no printers found
response.write &quot;Printer not found.&quot;
else
for objIteratePrinterListing = lbound(objPrinterList) to (ubound(objPrinterList)-1) ' iterate printer listing
response.write objPrinterList(objIteratePrinterListing) ' return the printer
next
end if


Hope this helps...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top