Script Help (Full Version)

All Forums >> [Scripting Technologies] >> VB Script



Message


jeffmacl -> Script Help (6/4/2008 10:15:13 AM)

I am new to vb and need help with a script. This appears to work except it does not get the sid information. I'm not sure what to change to get it.

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
intRow = 2
objExcel.Cells(1, 1).Value = "AccountExpirationDate"
objExcel.Cells(1, 2).Value = "BadPasswordAttempts"
objExcel.Cells(1, 3).Value = "Description"
objExcel.Cells(1, 4).Value = "FullName"
objExcel.Cells(1, 5).Value = "HomeDirDrive"
objExcel.Cells(1, 6).Value = "HomeDirectory"
objExcel.Cells(1, 7).Value = "LastLogin"
objExcel.Cells(1, 8).Value = "LastLogoff"
objExcel.Cells(1, 9).Value = "LoginHours"
objExcel.Cells(1, 10).Value = "LoginScript"
objExcel.Cells(1, 11).Value = "LoginWorkstations"
objExcel.Cells(1, 12).Value = "MaxLogins"
objExcel.Cells(1, 13).Value = "MaxPasswordAge"
objExcel.Cells(1, 14).Value = "MaxStorage"
objExcel.Cells(1, 15).Value = "MinPasswordAge"
objExcel.Cells(1, 16).Value = "MinPasswordLength"
objExcel.Cells(1, 17).Value = "Name"
objExcel.Cells(1, 18).Value = "objectSid"
objExcel.Cells(1, 19).Value = "Parameters"
objExcel.Cells(1, 20).Value = "PasswordAge"
objExcel.Cells(1, 21).Value = "PasswordExpired"
objExcel.Cells(1, 22).Value = "PasswordHistoryLength"
objExcel.Cells(1, 23).Value = "PrimaryGroupID"
objExcel.Cells(1, 24).Value = "Profile"
objExcel.Cells(1, 25).Value = "UserFlags"
On Error Resume Next
Set Fso = CreateObject("Scripting.FileSystemObject")
strDomainName = InputBox("Enter Domain Name To Query")
Set objDomain = GetObject("WinNT://" & strDomainName)
objDomain.Filter = Array("user")
For Each objItem in objDomain
objExcel.Cells(intRow, 1).Value = objItem.AccountExpirationDate
objExcel.Cells(intRow, 2).Value = objItem.BadPasswordAttempts
objExcel.Cells(intRow, 3).Value = objItem.Description
objExcel.Cells(intRow, 4).Value = objItem.FullName
objExcel.Cells(intRow, 5).Value = objItem.HomeDirDrive
objExcel.Cells(intRow, 6).Value = objItem.HomeDirectory
objExcel.Cells(intRow, 7).Value = objItem.LastLogin
objExcel.Cells(intRow, 8).Value = objItem.LastLogoff
objExcel.Cells(intRow, 9).Value = objItem.LoginHours
objExcel.Cells(intRow, 10).Value = objItem.LoginScript
objExcel.Cells(intRow, 11).Value = objItem.LoginWorkstations
objExcel.Cells(intRow, 12).Value = objItem.MaxLogins
objExcel.Cells(intRow, 13).Value = objItem.MaxPasswordAge
objExcel.Cells(intRow, 14).Value = objItem.MaxStorage
objExcel.Cells(intRow, 15).Value = objItem.MinPasswordAge
objExcel.Cells(intRow, 16).Value = objItem.MinPasswordLength
objExcel.Cells(intRow, 17).Value = objItem.Name
objExcel.Cells(intRow, 18).Value = objItem.objectSid
objExcel.Cells(intRow, 19).Value = objItem.Parameters
objExcel.Cells(intRow, 20).Value = objItem.PasswordAge
objExcel.Cells(intRow, 21).Value = objItem.PasswordExpired
objExcel.Cells(intRow, 22).Value = objItem.PasswordHistoryLength
objExcel.Cells(intRow, 23).Value = objItem.PrimaryGroupID
objExcel.Cells(intRow, 24).Value = objItem.Profile
objExcel.Cells(intRow, 25).Value = objItem.UserFlags
intRow = intRow + 1
Next
Set objDomain = Nothing
objExcel.Range("A1:Y1").Select
objExcel.Selection.Interior.ColorIndex = 19
objExcel.Selection.Font.ColorIndex = 11
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit




akaplan -> RE: Script Help (6/4/2008 10:30:30 AM)


' Retrieve SID and convert to hex string, then to decimal string.
arrSid = objItem.objectSid
strSidHex = OctetToHexStr(arrSid)
strSidDec = HexStrToDecStr(strSidHex)

Function OctetToHexStr(arrbytOctet)
   'Mueller
   ' Function to convert OctetString (byte array) to Hex string.
   Dim k
   OctetToHexStr = ""
   For k = 1 To Lenb(arrbytOctet)
   OctetToHexStr = OctetToHexStr _
   & Right("0" & Hex(Ascb(Midb(arrbytOctet, k, 1))), 2)
   Next
End Function

Function HexStrToDecStr(strSid)
   'Mueller
   ' Function to convert hex Sid to decimal (SDDL) Sid.
   Dim arrbytSid, lngTemp, j
   
   ReDim arrbytSid(Len(strSid)/2 - 1)
   For j = 0 To UBound(arrbytSid)
   arrbytSid(j) = CInt("&H" & Mid(strSid, 2*j + 1, 2))
   Next
  
   HexStrToDecStr = "S-" & arrbytSid(0) & "-" _
   & arrbytSid(1) & "-" & arrbytSid(8)
  
   lngTemp = arrbytSid(15)
   lngTemp = lngTemp * 256 + arrbytSid(14)
   lngTemp = lngTemp * 256 + arrbytSid(13)
   lngTemp = lngTemp * 256 + arrbytSid(12)
  
   HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp)
  
   lngTemp = arrbytSid(19)
   lngTemp = lngTemp * 256 + arrbytSid(18)
   lngTemp = lngTemp * 256 + arrbytSid(17)
   lngTemp = lngTemp * 256 + arrbytSid(16)
  
   HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp)
  
   lngTemp = arrbytSid(23)
   lngTemp = lngTemp * 256 + arrbytSid(22)
   lngTemp = lngTemp * 256 + arrbytSid(21)
   lngTemp = lngTemp * 256 + arrbytSid(20)
  
   HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp)
  
   lngTemp = arrbytSid(25)
   lngTemp = lngTemp * 256 + arrbytSid(24)
   HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp)
End Function




jeffmacl -> RE: Script Help (6/4/2008 11:35:05 AM)

That doesn't seem to work either. I think the problem is what it is querying to get the SID, objItem.objectSid.




akaplan -> RE: Script Help (6/4/2008 12:38:02 PM)

I have always used the LDAP interface, but checked the docs and WinNT is supported. Try starting with this instead:

arrSid = objItem.Get("objectSID")

Alan





Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.3125