samelamin
asked on
pausing a job
Dear experts
I am plying about with the WMI settings on C++
What i am trying to do is resume a paused job. However I cant do it with the SetJob command
It deletes the job but it doesnt resume
On both i am getting a result of 1 which indicates Setjob occured successfully
any idea how to fix this
I have set the printer to pause using SetPrinter
if thats the reason for my problems how do i pause a print job if the default settings of a printer are not set to pause?
I am plying about with the WMI settings on C++
What i am trying to do is resume a paused job. However I cant do it with the SetJob command
It deletes the job but it doesnt resume
On both i am getting a result of 1 which indicates Setjob occured successfully
any idea how to fix this
I have set the printer to pause using SetPrinter
if thats the reason for my problems how do i pause a print job if the default settings of a printer are not set to pause?
INT MonitorPrinter(char *pPrinter)
{
int iIndex = 0;
DWORD dwNeeded, dwRet, dwPrinterStatus;
HANDLE hPrinter=NULL;
HANDLE hWait;
JOB_INFO_2 *pJobs=NULL;
int iJobs, iTempIndex;
int jobid=4;
int c;
// int id1=atoi(id);
PRINTER_DEFAULTS pd;
pd.pDatatype = NULL;
pd.pDevMode = NULL;
pd.DesiredAccess = PRINTER_ALL_ACCESS;
if(!OpenPrinter(pPrinter,&hPrinter,&pd))
{
DisplayError("OpenPrinter Failed");
return FALSE;
}
GetJobs(hPrinter,
&pJobs, /* Pointer to be filled. */
&iJobs, /* Count of jobs filled. */
&dwPrinterStatus); /* Print Queue status. */
for (iIndex = 0; iIndex < iJobs; iIndex++)
{
int check =pJobs[iIndex].JobId;
//if (id1 == check)
{
char *user="working";
pJobs[0].pUserName=user;
// pJobs[0].pStatus=JOB_STATUS_PRINTING;
printf("Username is %s\n", pJobs[0].pUserName);
c = SetJob(hPrinter, pJobs[iIndex].JobId, 2, (LPBYTE) pJobs,JOB_CONTROL_RESUME);
printf("Result is %d\n",c);
}
}
return (0);
}
ASKER
Ive tried that too
Its why i changed it to JOB_CONTROL_RESUME, and ive updated the code
Its why i changed it to JOB_CONTROL_RESUME, and ive updated the code
Hi samelamin,
is the job still deleted with 'JOB_CONTROL_RESUME'? Is it the same if you don't set a user name? What is 'GetJobs'? Is it a function you wrote? Seems not to be a GDI function ...
ZOPPO
is the job still deleted with 'JOB_CONTROL_RESUME'? Is it the same if you don't set a user name? What is 'GetJobs'? Is it a function you wrote? Seems not to be a GDI function ...
ZOPPO
ASKER
It is yes
GetJobs will fill the Job_INFO_2 structure with the given jobs in the printer.
What is odd is i am using SetPrinter to change the default settings to pause, but when i print to it the job status is just "Ready" instead of paused
Even if i set aprint job to pause using the windows console and use SETJOB to change it to resume it still does not work
Ami not pausing the printer properly?
GetJobs will fill the Job_INFO_2 structure with the given jobs in the printer.
What is odd is i am using SetPrinter to change the default settings to pause, but when i print to it the job status is just "Ready" instead of paused
Even if i set aprint job to pause using the windows console and use SETJOB to change it to resume it still does not work
Ami not pausing the printer properly?
if (command==1)
{
SetPrinter(hPrinter, 0, NULL, PRINTER_CONTROL_PAUSE);
printf("Setting printer %s to pause\n",Printer);
}
else if(command==2)
{
SetPrinter(hPrinter, 0, NULL, PRINTER_CONTROL_RESUME);
printf("Setting printer %s to resume\n",Printer);
I'm not sure if I understand correctly, but if so I think you mix up printer and job status - if the printer is PAUSED a new job may even be READY - pausing and resuming the job won't do anything as long as the printer is PAUSED.
ASKER
I thought so
So how do i set the printer to be paused to allow all jobs given to it to be paused?
So how do i set the printer to be paused to allow all jobs given to it to be paused?
ASKER
IF i understand your comment Zoppe the underlying setting for a printer should be resume.
Given that how do i set all jobs given to it to be paused?
Given that how do i set all jobs given to it to be paused?
Hm - I'm not sure if there's an easy way - only thing I can think of is to set the printer to PAUSED, then set all jobs to be PAUSED, the re-set the printer to READY ... but thus you cannot ensure that i.e. a new printer job is started while the printer is READY - maybe there are ways to somehow implement that your app gets notified if a new print job is started, but unfortunateley I haven't such deep knowledge of the print/spooler stuff ...
ASKER
I did that too but what i thought was once i set the printer to ready all the jobs will resume
ASKER
OK i have a question
How do i pause a printer, because it isnt really paused its shown as ready, how do i make the status change to paused
Also Zoppo I tried your solution unfortunately when i pause a printer then print
the moment i change it to resume it resumes the first job in the queue
So it doesnt allow me to choose when i want to resume the job.
How do i pause a printer, because it isnt really paused its shown as ready, how do i make the status change to paused
Also Zoppo I tried your solution unfortunately when i pause a printer then print
the moment i change it to resume it resumes the first job in the queue
So it doesnt allow me to choose when i want to resume the job.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for this
But this will toggle the pause, when you toggle the resume do all jobs start resuming or do they stay paused?>
But this will toggle the pause, when you toggle the resume do all jobs start resuming or do they stay paused?>
ASKER
Yup it starts resuming everything as soon as i toggle it back so thats not going to work
When the printer's state is resumed using this code only those jobs which aren't paused start printing - the paused ones still keep as 'Paused' in the job list ...
ASKER
oh I think i get you
You mean i have to:
1) Toggle printer to pause
2) print document then set status to pause
3)resume the printer
Is that what you mean?
You mean i have to:
1) Toggle printer to pause
2) print document then set status to pause
3)resume the printer
Is that what you mean?
Yes, exactly - changing printer's state doesn't anyhow affect the job's states, so you have to control them both ...
ASKER
OK when i set a jobs status to pause it still doesnt chage its actual status from ready to pause
here is how i am changing the status
here is how i am changing the status
c = SetJob(hPrinter, pJobs[iIndex].JobId, 2, (LPBYTE) pJobs,JOB_CONTROL_PAUSE);
ASKER
Got it working
It was due to the fact i had pJobs refrenced. It should be NULL
Anyways thank you Zoppo
Its annoying to switch it to paused,print document and pause it, then again resume the printer
But oh well thank you
It was due to the fact i had pJobs refrenced. It should be NULL
Anyways thank you Zoppo
Its annoying to switch it to paused,print document and pause it, then again resume the printer
But oh well thank you
Fine, I'm glad I could help you so far. But, as told, there might be better solutions which I just don't know - i.e. there's a "Print Monitor API" which might give you the ability to intercept print-spooler calls, but I simply don't know if this can be used for your purpose since I never used it.
BTW: Are the print jobs started by your application or by third party applications? If it's yours you should be able to simply start the jobs in a resumed state ...
Have a nice day,
best regards,
ZOPPO
BTW: Are the print jobs started by your application or by third party applications? If it's yours you should be able to simply start the jobs in a resumed state ...
Have a nice day,
best regards,
ZOPPO
ASKER
Well for testing purposes im just printing Test Pages so i suppose it is me who starts them
But in future it may be started by someone else but my application will always have admin rights
But in future it may be started by someone else but my application will always have admin rights
Open in new window