Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.1 KiB

  1. // AddPrint.cpp : Implementation of COlePrivKSApp and DLL registration.
  2. #include "stdafx.h"
  3. #include "OlePrn.h"
  4. #include "AddPrint.h"
  5. STDMETHODIMP CAddPrint::AddPrinterConnection(BSTR lpPrinterName)
  6. {
  7. HRESULT hr = CanIAddPrinterConnection();
  8. if (FAILED(hr))
  9. return hr;
  10. if (::AddPrinterConnection(lpPrinterName))
  11. return S_OK;
  12. else
  13. return (SetScriptingError(CLSID_AddPrint,
  14. IID_IAddPrint,
  15. GetLastError()));
  16. }
  17. STDMETHODIMP CAddPrint::DeletePrinterConnection(BSTR lpPrinterName)
  18. {
  19. HRESULT hr = CanIDeletePrinterConnection( lpPrinterName );
  20. if (FAILED(hr))
  21. return hr;
  22. if (::DeletePrinterConnection(lpPrinterName))
  23. return S_OK;
  24. else
  25. return (SetScriptingError(CLSID_AddPrint,
  26. IID_IAddPrint,
  27. GetLastError()));
  28. }
  29. HRESULT CAddPrint::CanIAddPrinterConnection(void) {
  30. DWORD dwPolicy;
  31. HRESULT hr = GetActionPolicy(URLACTION_JAVA_PERMISSIONS, dwPolicy);
  32. if (SUCCEEDED(hr)) {
  33. hr = (dwPolicy == URLPOLICY_JAVA_MEDIUM ||
  34. dwPolicy == URLPOLICY_JAVA_LOW ||
  35. dwPolicy == URLPOLICY_ALLOW) ? S_OK : E_ACCESSDENIED;
  36. }
  37. return hr;
  38. }
  39. HRESULT CAddPrint::CanIDeletePrinterConnection(BSTR pbstrPrinter) {
  40. DWORD dwPolicy;
  41. LPTSTR lpszPrinter = NULL;
  42. HRESULT hr = GetActionPolicy(URLACTION_JAVA_PERMISSIONS, dwPolicy);
  43. USES_CONVERSION;
  44. if (SUCCEEDED(hr)) {
  45. switch(dwPolicy) {
  46. case URLPOLICY_JAVA_LOW:
  47. case URLPOLICY_ALLOW:
  48. hr = S_OK;
  49. break;
  50. case URLPOLICY_JAVA_MEDIUM:
  51. lpszPrinter = OLE2T( pbstrPrinter );
  52. hr = PromptUser(COlePrnSecurity::DeletePrinterConnection, lpszPrinter );
  53. hr = SUCCEEDED(hr) ?
  54. (HRESULT_CODE(hr) == S_OK ? S_OK : E_FAIL) :
  55. hr;
  56. break;
  57. default:
  58. hr = E_ACCESSDENIED;
  59. }
  60. }
  61. return hr;
  62. }