From: Rick on 14 Sep 2005 16:38 Does anyone know how in the hell (do I sound frustrated? or what) how I can delete the default printer. (programatically) I want to programatically delete the default printer just as if you would right click on the default printer ICON in the Printers dialog box and select the delete option. I have tried all Win32 W2K API routines which make some sort of sense to accomplish this; DeletePrinter, DeletePrinterDriverEx, etc. but to know avail. There seems to be very little historical clammering on this subject and not much written on the subject. If anyone can point me to a website, recommend a book, or directly help, it would greatly be appreciated. Thanks. Rick
From: Kellie Fitton on 14 Sep 2005 18:47 Hi, Try this approach to delete the default printer: GetDefaultPrinter() OpenPrinter() DeletePrinter() Now, you need to pass the completed PRINTER_DEFAULTS structure with the DesiredAccess field SET to PRINTER_ACCESS_ADMINISTER. in other words, you need to be loggedOn as an administrator, to have the access rights to delete the default printer. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/prntspol_910y.asp http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/prntspol_0hma.asp http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/prntspol_9qnm.asp http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/prntspol_42eq.asp Hope these information helps, Kellie.
From: Rick on 14 Sep 2005 20:19 Kellie, Thanks so much for getting back to me. The only thing I was doing different from your suggestion was NOT calling GetDefautPrinter() (because I already knew it) so I added the call and got the same results. It appears the last call to DeletePrinter() fails with a System Error 5 which is ERROR_ACCESS_DENIED. I am already logged in as the administrator so I don't understand why I am being denied access. In any event I will follow up on your idea of setting the PRINTER_ACCESS_ADMINISTRATOR. I'll check to see what API calls I need to make. Any other suggestions or comments you have are welcome. Thanks - Rick void DeleteNVPrinter(LPTSTR pPrinterName) { BOOL bRet; char s[80]; HANDLE hPrinter = NULL; DWORD dwCount; char lpPrinterName[50] ; dwCount = 50; bRet = GetDefaultPrinter(&lpPrinterName[0], &dwCount); if (!bRet) { sprintf(s,"GetDefaultPrinter Operation Failed %08X", GetLastError() ); logErrorToFile(s); } bRet = OpenPrinter(lpPrinterName, &hPrinter, NULL); if (!bRet) { sprintf(s,"OpenPrinter Operation Failed %08X", GetLastError() ); logErrorToFile(s); } bRet = DeletePrinter( hPrinter ); // Returns system error 5; ERROR_ACCESS_DENIED if (!bRet) { sprintf(s,"DeletePrinter Operation Failed %08X", GetLastError() ); logErrorToFile(s); } }
|
Pages: 1 Prev: CreateFile with unicode (Hungarian) filenames Next: Sysevent |