Link to home
Start Free TrialLog in
Avatar of monroea
monroea

asked on

How to create a printer share through VB...

I have a VB application I am writing that is two parts:

1. The first of the application will share the default printer with a specific name. (pending)

2. The second part of the app will net use that shared printer and map it to LPT1. (completed)

The issue I have, is that I have not been able to programmatically share the default printer. I need to create a share on the local machine for that printer and then Net Use it on LPT1 so an old in -house designed app which only prints to LPT1 can continue to limp along. I have tried using the netapi32.dll and am not versed enough in the API calls to make it work.

I need some sample code that will allow me to share a printer object on a local PC. Any ideas?

Aaron Monroe
Avatar of twalgrave
twalgrave

Avatar of monroea

ASKER

That looks right twalgrave, but what would the printer object name be?

Let's say the name of the printer in the printers folder is HP LaserJet; how would I share that object? Would it just be "\\computername\HP Laserjet"? Also, if that is the way you would share a printer object, how would I find out the printer object name? Is is just the name of the object in the printers folder? The same type of structure as normal folders; \\computername\foldername?

Sorry for the additional questions.

MonroeA
Sorry for taking so long, the email notifs were down.

No problem on the additional Qs
I believe you name the share what you'd like to name it.  we have printers called goofy, etc.

In VB, you can get the names of printers through the printers collection

    Dim oPrinter As Printer
    For Each oPrinter In Printers
        MsgBox oPrinter.DeviceName & " - " & oPrinter.DriverName
    Next
Avatar of monroea

ASKER

Thanks so much for the help twalgrave. I have the part of using the printer object written already and am able to get the names of the printer and what port it is on. What I still have left to do is if the default printer is not on LPT1 then share the printer. The issue I am having is trying to share the printer programmatically.

Everything you have shown me I know will work, I just need to know what to put for the "folder". If you look at the link you provided, the message box shows some input requirements for sharing an object. I have the machine name, the share name, the comments and password, I am just not sure what to put for the folder line. If I put in the printer name it doesn't work. The only thing I need now to complete this project is how to obtain the name I can use to share the printer object with. I try the printer name and I get an error 123.

So I guess my only question left is what part of the printer collection or what other object collection will allow me to share the printer? If I have a folder path in that line it works just fine. I just need to know what needs to go there for a printer in order to share the printer.

Again thanks for all of the help so far and the timely responses.

MonroeA
Avatar of monroea

ASKER

Thanks so much for the help twalgrave. I have the part of using the printer object written already and am able to get the names of the printer and what port it is on. What I still have left to do is if the default printer is not on LPT1 then share the printer. The issue I am having is trying to share the printer programmatically.

Everything you have shown me I know will work, I just need to know what to put for the "folder". If you look at the link you provided, the message box shows some input requirements for sharing an object. I have the machine name, the share name, the comments and password, I am just not sure what to put for the folder line. If I put in the printer name it doesn't work. The only thing I need now to complete this project is how to obtain the name I can use to share the printer object with. I try the printer name and I get an error 123.

So I guess my only question left is what part of the printer collection or what other object collection will allow me to share the printer? If I have a folder path in that line it works just fine. I just need to know what needs to go there for a printer in order to share the printer.

Again thanks for all of the help so far and the timely responses.

MonroeA
I don't have the capabilities to test this out as I only have a local printer attached.  Have you tried passing an empty string into the folder name i.e. ""?

The only other thing that I found when doing a registry search is this:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\Brother MFC8600/9650 series   This location has a registry entry called Share Name.  When I shared my printer, that sharename appeared in the registry value of Share Name.  On my other non-shared printers, the Share Name exists, but does not have a value.  This may be of use to you, I don't know because I can't test it out.

Avatar of monroea

ASKER

Thanks! I will try that out and let you know.

MonroeA
Avatar of monroea

ASKER

Thanks again twalgrave but that did not work either. I found a few places in the registry when it shows a share name and switch them all but there seems to a place where there is a flag that says the printer is shared or not and until that is flipped the share names don't show.

Still gonna keep digging. I think I'm almost there...

MonroeA
the dsspooler node under the printer in the registry also has a share name.  May want to try setting that also
should read PrintShareName
Avatar of monroea

ASKER

I am going to close this question since I have not been able to solve the issue yet.

MonroeA
monroea,
The way you close out a question is to either accept an answer(which I understand you do not want to do) or to post a zero-point question in the Community Support/Cleanup topic area asking for a delete/refund.  Remember to copy the link URL to this question and put it in the comment section of the refund request.  If you have further questions on this process, drop a line here and I will answer them.  Thanks for keeping Experts Exchange clean.

Moderators,
Once a request for refund is made, no need for the 72 hour waiting period as I'm the only one to have answered.  Work your magic.
Avatar of monroea

ASKER

Thanks for the info twalgrave.

As an FYI I have actually found a solution to the issue and you are welcome to add it to your information banks; There is an additional dll added to the Windows 2000 Resource Supplement Kit called prnadmin.dll which will allow you to programmatically share a printer through WSH. That plus what I already had codded, solved the issue.

Thanks for all of the help!
Glad to hear you found a solution!  Thanks for sharing it with us.  

Have a great day!
Avatar of Éric Moreau
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
PAQ/Refund.
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
emoreau
EE Cleanup Volunteer
I concur
ASKER CERTIFIED SOLUTION
Avatar of DigitalXtreme
DigitalXtreme

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial