Fog Creek Software
Discussion Board




Printers collection in VB

I've just been upgrading a bit of VB code to run as a standalone service. It seems to be okay until it tries to print anything, at which point it fails because the VB Printers collection is empty.

What does this collection map down to in the Win32 world? I'm running my service as the LocalSystem account without any access to UI - does this make a difference? If I swap to running as an Administrator account, it all works fine. Also I've enabled all printers to give Everyone rights to print, manage printers, and manage documents.

Better than being unemployed...
Tuesday, March 18, 2003

Can you have the service logon with a user account (not LocalSystem) that has access to the local printer?
(change account in Services-logon tab).
Might be OK depending on your security requirements.

Just me (Sir to you)
Tuesday, March 18, 2003

Hmm. I thought for some reason the service would get killed when you logged out - but it doesn't.

Works fine running as a normal user. I think the only requirement we have is that the server box can run without anybody being logged in.

Ta.

Better than being unemployed...
Tuesday, March 18, 2003

Another option (not recommended) it to manually copy the registry entries for the printers from another account to the local system.

google it if needed - can't find the bookmark now.

tekumse
Tuesday, March 18, 2003

The first option when you add a printer in Windows is whether you want to add a local or network printer. Make sure you install all your printers as local.

Tony E
Tuesday, March 18, 2003

>> "What does this collection map down to in the Win32 world? I'm running my service as the LocalSystem account without any access to UI - does this make a difference? If I swap to running as an Administrator account, it all works fine."

Check out the API functions EnumPrinters, OpenPrinter, AddPrinter, GetPrinter, SetPrinter.  Also look at the PRINTER_INFO_X structures.  You should be able to find information about printer access rights there.

Dave B.
Tuesday, March 18, 2003

The local system account (for services) does NOT have network access rights, and cannot access network printers, network shares, UNC paths, etc. Most printers in a business environment are network printers, it's unusual to have a printer connected to a server's local LPT port.

A service can use an account other than the local system account and it will continue running even when nobody is logged in (as you have discovered). However, you will need to keep the password synchronized - if the password is changed for the user account, you will also need to update the password entry in the service properties.

Also, in general, beware of printing from a service - some printer drivers (probably mostly older printers now) have a nasty habit of displaying a dialog box for some types of printer errors (especially if the printer is unreachable on the network), and this will hang a service since there is no way to respond to the dialog (because the service does not have a visible or interactive desktop).

Philip Dickerson
Tuesday, March 18, 2003

*  Recent Topics

*  Fog Creek Home