Solved

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

Posted on 2004-09-10
14
936 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:evansong
  • 8
  • 6
14 Comments
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 12033556
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.
0
 

Author Comment

by:evansong
ID: 12040451
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
0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 12053054
Where are you writing information to in the Registry? Can you post the path and value
0
 

Author Comment

by:evansong
ID: 12057431
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
0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 12058345
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.

0
 

Author Comment

by:evansong
ID: 12093755
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
0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 12094770
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?
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:evansong
ID: 12097576
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
0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 12097648
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
0
 

Author Comment

by:evansong
ID: 12098295
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
0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 12099848
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.
0
 
LVL 51

Accepted Solution

by:
Julian Hansen earned 250 total points
ID: 12100042
Hi Even,

Here is some code on controlling a service in C#

public static void Main(string[] args)
{
   System.ServiceProcess.ServiceController myController = new System.ServiceProcess.ServiceController("Spooler");
   if (myController.CanStop)
   {
      myController.Stop () ;
      myController.Start () ;
   }
   else
   {
      System.Diagnostics.Debug.WriteLine( "Oops" ) ;
   }
}

For more info lookup the ServiceController class. The code above is modified from the following MSDN article

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskcreatingservicecontrollercomponentinstances.asp
0
 

Author Comment

by:evansong
ID: 12107786
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
0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 12109668
My pleasure Evan, glad to have been of assistance.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now