Leaked source code of windows server 2003
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.

132 lines
3.6 KiB

  1. '----------------------------------------------------------------------
  2. ' pubprn.vbs - publish printers from a non Windows 2000 server into Windows 2000 DS
  3. '
  4. '
  5. ' Arguments are:-
  6. ' server - format server
  7. ' DS container - format "LDAP:\\CN=...,DC=...."
  8. '
  9. '
  10. ' Copyright (c) Microsoft Corporation 1997
  11. ' All Rights Reserved
  12. '----------------------------------------------------------------------
  13. '--- Begin Error Strings ---
  14. Dim L_PubprnUsage1_text
  15. Dim L_PubprnUsage2_text
  16. Dim L_PubprnUsage3_text
  17. Dim L_PubprnUsage4_text
  18. Dim L_PubprnUsage5_text
  19. Dim L_PubprnUsage6_text
  20. Dim L_GetObjectError1_text
  21. Dim L_GetObjectError2_text
  22. Dim L_PublishError1_text
  23. Dim L_PublishError2_text
  24. Dim L_PublishError3_text
  25. Dim L_PublishSuccess1_text
  26. L_PubprnUsage1_text = "Usage: [cscript] pubprn.vbs server ""LDAP://OU=..,DC=..."""
  27. L_PubprnUsage2_text = " server is a Windows server name (e.g.: Server) or UNC printer name (\\Server\Printer)"
  28. L_PubprnUsage3_text = " ""LDAP://CN=...,DC=..."" is the DS path of the target container"
  29. L_PubprnUsage4_text = ""
  30. L_PubprnUsage5_text = "Example 1: pubprn.vbs MyServer ""LDAP://CN=MyContainer,DC=MyDomain,DC=Company,DC=Com"""
  31. L_PubprnUsage6_text = "Example 2: pubprn.vbs \\MyServer\Printer ""LDAP://CN=MyContainer,DC=MyDomain,DC=Company,DC=Com"""
  32. L_GetObjectError1_text = "Error: Path "
  33. L_GetObjectError2_text = " not found."
  34. L_GetObjectError3_text = "Error: Unable to access "
  35. L_PublishError1_text = "Error: Pubprn cannot publish printers from "
  36. L_PublishError2_text = " because it is running Windows 2000, or later."
  37. L_PublishError3_text = "Failed to publish printer "
  38. L_PublishError4_text = "Error: "
  39. L_PublishSuccess1_text = "Published printer: "
  40. '--- End Error Strings ---
  41. set Args = Wscript.Arguments
  42. if args.count < 2 then
  43. wscript.echo L_PubprnUsage1_text
  44. wscript.echo L_PubprnUsage2_text
  45. wscript.echo L_PubprnUsage3_text
  46. wscript.echo L_PubprnUsage4_text
  47. wscript.echo L_PubprnUsage5_text
  48. wscript.echo L_PubprnUsage6_text
  49. wscript.quit(1)
  50. end if
  51. ServerName= args(0)
  52. Container = args(1)
  53. on error resume next
  54. Set PQContainer = GetObject(Container)
  55. if err then
  56. wscript.echo L_GetObjectError1_text & Container & L_GetObjectError2_text
  57. wscript.quit(1)
  58. end if
  59. on error goto 0
  60. if left(ServerName,1) = "\" then
  61. PublishPrinter ServerName, ServerName, Container
  62. else
  63. on error resume next
  64. Set PrintServer = GetObject("WinNT://" & ServerName & ",computer")
  65. if err then
  66. wscript.echo L_GetObjectError3_text & ServerName & ": " & err.Description
  67. wscript.quit(1)
  68. end if
  69. on error goto 0
  70. For Each Printer In PrintServer
  71. if Printer.class = "PrintQueue" then PublishPrinter Printer.PrinterPath, ServerName, Container
  72. Next
  73. end if
  74. sub PublishPrinter(UNC, ServerName, Container)
  75. Set PQ = WScript.CreateObject("OlePrn.DSPrintQueue.1")
  76. PQ.UNCName = UNC
  77. PQ.Container = Container
  78. on error resume next
  79. PQ.Publish(2)
  80. if err then
  81. if err.number = -2147024772 then
  82. wscript.echo L_PublishError1_text & Chr(34) & ServerName & Chr(34) & L_PublishError2_text
  83. wscript.quit(1)
  84. else
  85. wscript.echo L_PublishError3_text & Chr(34) & UNC & Chr(34) & "."
  86. wscript.echo L_PublishError4_text & err.Description
  87. end if
  88. else
  89. wscript.echo L_PublishSuccess1_text & PQ.Path
  90. end if
  91. Set PQ = nothing
  92. end sub