Link to home
Start Free TrialLog in
Avatar of evansong
evansong

asked on

Is there a way to initial registry information without rebooting the machine?

My application add values to registry and the printer prints cover page only if I reboot the machine..  Is there a way to reload the registry info directly into printer?
I figure it has to do with "rundll32 printui.dll,PrintUIEntry" and i went through all the parameters but found none for refreshing the information of registry or setting separator page filename.
I can't think of any other way to solve this problem but to get help from guru here!

Thank you,

Evan
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

You need to use the DEVMODE functions.

Refer to the API DocumentProperties, GetPrinter, SetPrinter.

Basically what you do is retrive the DEVMODE structure using the GetPrinter function. You make changes to it and then write the DEVMODE back with SetPrinter and DocumentProperties.

Shout if you need more help. It might also help if you post a little more detail on exactly what your application is doing and what you want it to do.
Avatar of evansong
evansong

ASKER

I read through DEVMODE function.. and it looked like the setting for printer stays only with the application itself.  What I need is, a way to modify or set the printer setting(for all windows applications) to be changed so that it prints cover(banner) page that contains User name and date(tihs part is done and working).  I don't want the user to reboot their machine; because when you reference a filename value directly into printer's separator page field box instead of adding a value directly to registry, it prints cover page.  However, if I add filename directly to registry, I will have to reboot the machine in order for computer to print a cover page.
Help,

Thanx.

Evan
Where are you writing information to in the Registry? Can you post the path and value
Hi Julian :)

First of all, thank you  :)
First one that I write into is in

Key -> [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\HP LaserJet 4/4M Plus PS 600]
String Value name -> "Separator File"
String Value Data -> "C:\\WINDOWS\\system32\\pscript.sep"

The second one is in,

Key -> [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\HP LaserJet 4/4M Plus PS 600\DsSpooler]
String Value name -> "printSeparatorFile"
String Value Data -> "C:\\WINDOWS\\system32\\pscript.sep"

but then, I also notice the "changeID" (a binary value) which locates in both 4M Plus PS 600 and DsSpooler changes whenever I change some setting in Control Panel -> Printers -> HP LaserJet 4/4M Plus PS 600.
And so, I was wondering if this "changeID" was to keep tracks of changes and refresh printer setting somehow.   The only problem is that it looks though the "changeID" value is random and I wasn't able to find the pattern of number.  Also, I have this strong feeling that this seperator file is changed through "rundll32 printui.dll,PrintUIEntry".
But how?

Any thoughts?

Thank you again,

Evan
Hi Evan,

Ok, I don't have an exact answer for you - there is a lot of digging to do here - which is not a problem as I am in the middle of a fairly intensive project involving code around printers and printing so all the research is sort of in line with what I am doing.

If printui.dll does do what you want then it is doing it through some API documented or not so there must be a way of doing it in your app.

Have you tried this

GetPrinter ( ...) to get all the current settings
make your registry change with normal API functions
DocumentProperties ( ... ) with the parameters you got from the GetPrinter and with options not to show the dialog.
SetPrinter ( ... ) with the parameters you got from the GetPrinter

I suspect this will cause the print processor to refresh itself from the registry.

Another thing you could try (although I doubt this will work - if it does let me know) is to send a WM_SETTINGCHANGE message with the HWND_BROADCAST window handle. This should tell all windows to refresh their setting info but I have found it does not work in all instances.

Hi Julian,

Well, I figured the problem out.  It was "changeID" and to I restart the printing service and in the process, the printer refresh itself.  However, my real problem now is.... how am I going to show a total number of page in "separator page" if separator page (either Postscript or PCL) does not have total page option.  Any idea?

Thanx

Evan
Hi Even,

Retarting the service will do the trick, however, it is not ideal especially if you want to run this solution in an environment where users are locked down.

I was just wondering (I have not actually done this before) would it not be easier to do the following.

Instead of changing the value in the registry - instead keep the name constant and just change the contents the name is pointing to.

i.e. call the seperator page SEPPAGE.TXT or whattever and then when this needs to change change the actual contents on the disk rather than changing the registry setting and restarting the service. You could even configure this by user by storing the file on a user specific drive (say U: is the users home drive then path would be U:\SEPPAGE.TXT or something) that way each user can have their own separator page.

- would this work?
Hi Julian

I am so glad someone is paying attention to my problem :)
First of all, what do you mean by users being locked down?  Can you be more specific on this with examples...  If what you say is true, it is something I haven't thought about and I should consider your alternative solution.  Although, I think you are little confuse about my original problem.  When the user install "print service" applicaiton, the application asks for user name, and password and when it matches the application automatically installs the network printer and generates proper separator page for the user.  My problem was assigning separator page in Printer's property -> Advanced -> Separator Page... (SEPPAGE.TXT for instance).
I hope this clearfy my problem.

Thanx again,

Evan
Hi Evan,

Lockdown refers to configuration settings (profiles and security) that limit the ability of users to make changes to the desktop that could result in instability. The level of lockdown differs depending on the requirements of the implementor but usually would include removing access to the system registry (HKEY_LOCAL_MACHINE) for everything but reading, disabling user ability to start and stop services or change the startup mode of services etc. Lockdown is a generic term refering to the process of securing a workstation from unauthorised change.

Back to your problem

I think I am still trying to understand exactly what it is you are trying to do. My initial impression was that you were trying to dynamically change the separator page based on some condition during a user session. From your last post it seems that you are trying to do a configuration change - what is still not clear is if you have to do this only once per user or everytime the user logs on or based on some other criteria.

My solution above was based on the assumption that you did a once off install of the printer (With separator page specified) and that you needed to change the separator at some points during a user session. From the latest information I have it seems that this solution will not suite your requirements.

If you can clarify when the printer install takes place and how often (once off, at logon etc) I will see if I can think of something more in line with what you are trying to do.

Julian
Hi Julian :>

Well, the installtion takes place only once per user/computer and user can uninstall the application if they want to.    Also, thank you for nice explanation of lockdown; however, I don't think I would have to worry about this part... yet.
I am unsure whether I should be coding this with system language since all I have to do is execute "net stop spooler" before I modify the registry and then turn back on printer spooler by executing "net start spooler".  It would be nice to know how to stop spooler by coding (either in C# or VB.NET).  Do you know how to do this?  If you do, I will give you the points and close this question :)

Many thanx,

Evan
Hi Evan,

I have written code to stop and start services in C++ - I am in the process of migrating a lot of this code to .Net - give me a day and I will post a link or some code.

If the starting and stopping of the service works for you then go for it. I will continue to look for an alternative though as for our purposes (which seem to have some overlap with yours) we cannot stop and start services. If I find anything I will let you know.
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

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
Thank you Julian,

I am at work right now, but I went through the link you post and I found it to be very useful for project I am working on.
Thank you so much :)

Evan
My pleasure Evan, glad to have been of assistance.