News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Restarting Print Spooler

Started by rjthecarguy, August 22, 2011, 01:04:44 AM

Previous topic - Next topic

rjthecarguy

I have an application that makes changes to the registry entries of selected printers.  Once those changes are made I would like the app to restart the Print Spool Service.  I can't seem to open a service.  The handle returned in EAX passes the NULL test but GetLastError() tells me the handle is invalid when I try to open the service with OpenService.  This is the snippet that's been kicking my butt.

I have searched the forum and MS documentation and still can't figure it out.  Any help would be greatly appreciated!

         
invoke OpenSCManager, NULL,NULL, SC_MANAGER_ALL_ACCESS
.if eax != NULL
      mov hSCManager, eax
             
      invoke OpenService,addr hSCManager,addr szSpooler,SERVICE_ALL_ACCESS
        .if eax != NULL
        invoke MessageBox, NULL,CTEXT("Service Open"), CTEXT("Message"), MB_OK
        .else
        invoke GetLastError
        mov edi, eax
        invoke FormatMessage,FORMAT_MESSAGE_FROM_SYSTEM, NULL,edi,0,ADDR errorMsg,512,NULL
       
        invoke MessageBox, NULL,CTEXT("ERROR!"), CTEXT("Message"), MB_OK
        .endif
        .endif




dedndave

invoke OpenService,addr hSCManager,addr szSpooler,SERVICE_ALL_ACCESS

it wants the handle, not the address of the handle...

try this
invoke OpenService,hSCManager,addr szSpooler,SERVICE_ALL_ACCESS

actually, the handle happens to be in EAX, so this is more efficient...
invoke OpenService,eax,addr szSpooler,SERVICE_ALL_ACCESS

rjthecarguy


georgewalker

Each time I reboot my printer spooler stops and I have to restart it.. Is there any solution for this issue or is it like it is mandatory to do so..

dedndave

you can control system services with the Services Manager, an Administrative Tool
you must be signed in with Administrator privileges

if you cannot locate Administrative Tools in the Control Panel or on the Start Menu...
right-click on the Taskbar - Properties
Start Menu tab
Customize button
Advanced tab
in the "Start menu items" box, locate "System Administrative Tools" (usually at the bottom of the list)
select an option that other than "Don't display this item"
OK
Apply
OK

in Administrative Tools - Services
at the bottom, i usually select the Standard display mode tab
scroll down to Print Spooler and double-click on it
Startup type: Automatic
Apply
OK
close Services
reboot