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.

171 lines
4.3 KiB

  1. '
  2. ' Example usage of ICloneSecurityPrincipal::AddSidHistory
  3. '
  4. ' Copyright (c) 1999 Microsoft Corporation
  5. option explicit
  6. const SCRIPT_FILENAME = "sidhist.vbs"
  7. const SCRIPT_SOURCE_NAME = __FILE__
  8. const SCRIPT_DATE = __DATE__
  9. const SCRIPT_TIME = __TIME__
  10. const ARG_COUNT = 6
  11. ' command line parameters
  12. Dim srcDC ' source domain controller
  13. Dim srcDom ' source domain
  14. Dim srcSam ' source principal SAM name
  15. Dim dstDC ' destination controller
  16. Dim dstDom ' destination domain
  17. Dim dstSam ' destination principal SAM name
  18. If wscript.arguments.count <> ARG_COUNT Then
  19. PrintUsage
  20. End If
  21. Dim args()
  22. ReDim args(0)
  23. args(0) = ""
  24. Dim i
  25. For i = 0 to wscript.arguments.count - 1
  26. ReDim Preserve args(i)
  27. args(i) = wscript.arguments.item(i)
  28. Next
  29. srcDC = GetArgValue("srcdc", args)
  30. srcDom = GetArgValue("srcdom", args)
  31. srcSam = GetArgValue("srcsam", args)
  32. dstDC = GetArgValue("dstdc", args)
  33. dstDom = GetArgValue("dstdom", args)
  34. dstSam = GetArgValue("dstsam", args)
  35. If CheckForBadArgs(args) Then
  36. wscript.echo "Unknown command-line arguments specified"
  37. PrintUsage
  38. End If
  39. ' Create the COM object implementing ICloneSecurity Principal
  40. Dim clonepr
  41. Set clonepr = CreateObject("DSUtils.ClonePrincipal")
  42. On Error Resume Next
  43. ' Connect to the source and destination domain controllers
  44. clonepr.Connect srcDC, srcDom, dstDC, dstDom
  45. If Err.Number then
  46. DumpErr
  47. wscript.quit(0)
  48. Else
  49. wscript.echo "Connected"
  50. End If
  51. ' Add the SID of the source principal to the sid history of the destination
  52. ' principal.
  53. clonepr.AddSidHistory srcSam, dstSam, 0
  54. If Err.Number then
  55. DumpErr
  56. wscript.quit(0)
  57. Else
  58. wscript.echo "Success"
  59. End If
  60. wscript.quit(0)
  61. Function GetArgValue(argName, args())
  62. Dim a
  63. Dim v
  64. Dim iLenArgName
  65. Dim x
  66. Dim iArgCount
  67. Dim fullArgName
  68. fullArgName = "/" & argName & ":"
  69. iArgCount = Ubound(args)
  70. ' Get the length of the argname we are looking for
  71. iLenArgName = Len(fullArgName)
  72. GetArgValue = "" ' default to nothing
  73. For x = 0 To iArgCount
  74. If Len(args(x)) >= iLenArgName Then
  75. a = Mid(args(x), 1, iLenArgName)
  76. If UCase(a) = UCase(fullArgName) Then
  77. ' erase it so we can look for unknown args later
  78. v = args(x)
  79. args(x) = ""
  80. If Len(v) > iLenArgName Then
  81. GetArgValue = Mid(v, iLenArgName + 1)
  82. Exit Function
  83. Else
  84. GetArgValue = ""
  85. Exit Function
  86. End If
  87. End If
  88. End If
  89. Next
  90. End Function
  91. Function CheckForBadArgs(args())
  92. For i = 0 to UBound(args)
  93. If Len(args(i)) > 0 Then
  94. CheckForBadArgs = 1
  95. Exit Function
  96. End If
  97. Next
  98. CheckForBadArgs = 0
  99. End Function
  100. Sub PrintUsage
  101. Echo "Usage: cscript " & SCRIPT_FILENAME & " /srcdc:<dcname> /srcdom:<domain>"
  102. Echo "/srcsam:<name> /dstdc:<dcname> /dstdom:<domain> /dstsam:<name>"
  103. Echo ""
  104. Echo "Parameters:"
  105. Echo " /srcdc - source domain controller NetBIOS computer name (without leading \\)"
  106. Echo ""
  107. Echo " /srcdom - source domain NetBIOS name"
  108. Echo ""
  109. Echo " /srcsam - source principal SAM name"
  110. Echo ""
  111. Echo " /dstdc - destination domain controller NetBIOS computer name (without "
  112. Echo " leading \\)"
  113. Echo " This script must be run on the machine indicated here."
  114. Echo ""
  115. Echo " /dstdom - destination domain DNS name"
  116. Echo ""
  117. Echo " /dstsam - destination principal SAM name"
  118. Echo ""
  119. Echo SCRIPT_DATE & " " & SCRIPT_TIME
  120. wscript.quit(0)
  121. End Sub
  122. Sub DumpErr
  123. wscript.echo "Error 0x" & CStr(Hex(Err.Number)) & " occurred."
  124. wscript.echo "Error Description: " & Err.Description
  125. wscript.echo "Error HelpContext: " & Err.HelpContext
  126. wscript.echo "Error HelpFile : " & Err.HelpFile
  127. wscript.echo "Error Source : " & Err.Source
  128. Err.Clear
  129. End Sub
  130. sub Echo(byref message)
  131. wscript.echo message
  132. end sub