المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : what are the dependencies or settings required for browser for supporting ManagementO



C# Programming
05-20-2009, 08:42 AM
I Had to cancel the printing given.
For this I had used

Code Snippet: Sandeep Aparajit playing around with the System.Management.Net namespace.

#region CancelPrintJob

///
/// Cancel the print job. This functions accepts the job number.
/// An exception will be thrown if access denied.
///
/// int: Job number to cancel printing for.
/// bool: true if cancel successfull, else false.
public bool CancelPrintJob(int printJobID)
{
// Variable declarations.
bool isActionPerformed = false ;
string searchQuery;
String jobName;
char [] splitArr;
int prntJobID;
ManagementObjectSearcher searchPrintJobs;
ManagementObjectCollection prntJobCollection;
try
{
// Query to get all the queued printer jobs.
searchQuery = "SELECT * FROM Win32_PrintJob" ;
// Create an object using the above query.
searchPrintJobs = new ManagementObjectSearcher(searchQuery);
// Fire the query to get the collection of the printer jobs.
prntJobCollection = searchPrintJobs.Get();

// Look for the job you want to delete/cancel.
foreach (ManagementObject prntJob in prntJobCollection)
{
jobName = prntJob.Properties["Name" ].Value.ToString();
// Job name would be of the format [Printer name], [Job ID]
splitArr = new char [1];
splitArr[0] = Convert.ToChar("," );
// Get the job ID.
prntJobID = Convert.ToInt32(jobName.Split(splitArr)[1]);
// If the Job Id equals the input job Id, then cancel the job.
if (prntJobID == printJobID)
{
// Performs a action similar to the cancel
// operation of windows print console
prntJob.Delete();
isActionPerformed = true ;
break ;
}
}
return isActionPerformed;
}
catch (Exception sysException)
{
// Log the exception.
return false ;
}
}

#endregion CancelPrintJob







The code line prntJob.Delete() is not executing in other PC's which had .Net framework and all other things same as my Syatem.

What may be the problem? Can anyone say something to solve this?