Want more features on Pastebin? Sign Up, it's FREE!
Guest

setlocalPCdescriptionfromAD

By: mikeroberts on Nov 15th, 2012  |  syntax: VB.NET  |  size: 1.53 KB  |  views: 99  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Const ADS_SCOPE_SUBTREE = 2
  2. On Error Resume Next
  3.  
  4. strComputer = "."
  5. Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  6.  
  7. Set colOSes = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
  8. For Each objOS in colOSes
  9.   strComputerName = objOS.CSName
  10. Next
  11.  
  12. Set objConnection = CreateObject("ADODB.Connection")
  13. Set objCommand =   CreateObject("ADODB.Command")
  14. objConnection.Provider = "ADsDSOObject"
  15. objConnection.Open "Active Directory Provider"
  16.  
  17. Set objCommand.ActiveConnection = objConnection
  18. objCommand.CommandText = "Select ADsPath From " & "'LDAP://DC=yourdomain,DC=com' Where objectClass='computer'" & " and Name = '" & strComputerName & "'"  
  19. objCommand.Properties("Page Size") = 1000
  20. objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
  21. Set objRecordSet = objCommand.Execute
  22. objRecordSet.MoveFirst
  23.  
  24. Do Until objRecordSet.EOF
  25.     Set objComputer = GetObject(objRecordSet.Fields("ADsPath").Value)
  26.     objProperty = objComputer.Get("Description")
  27.     If (Err.Number <> 0) Then
  28.         objProperty = "_No AD Description"
  29.     End if
  30.     Const HKEY_LOCAL_MACHINE = &H80000002
  31.     strThisMachine = "."
  32.     Set objRegistry = GetObject ("winmgmts:\\" & strThisMachine & "\root\default:StdRegProv")
  33.     strKeyPath = "System\CurrentControlSet\Services\lanmanserver\parameters"
  34.     strValueName = "srvcomment"
  35.     strDescription = objProperty
  36.     objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strDescription
  37.     objRecordSet.MoveNext
  38. Loop
clone this paste RAW Paste Data