By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,990 Members | 2,138 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,990 IT Pros & Developers. It's quick & easy.

Can anyone convert this VBS to VB.net?

P: 1
Know nothing about VB and started a my first IT job and was asked my my boss to convert this to .net. Any help would be greatly appreciated.


Expand|Select|Wrap|Line Numbers
  1. ' VBScript Source File 
  2. '
  3. ' NAME: LISTPROXYADDRESSES.VBS
  4. ' VERSION: 1.1
  5. ' AUTHOR: Bharat Suneja , Bharat Suneja  --> Modified By: Kevin Reed
  6. ' CREATE DATE  : 5/06/2004
  7. ' LAST MODIFIED : 5/19/2011
  8. '==================================================================================================
  9. ' COMMENT: 
  10. '   
  11. '==================================================================================================
  12.  
  13. 'Security
  14. Dim objADSysInfo : Set objADSysInfo = CreateObject("ADSystemInfo") 
  15. Dim objUser : Set objUser = GetObject("LDAP://" & objADSysInfo.UserName) 
  16. if objUser.givenname & " " & objuser.sn <> "Jonathan Salina" Then
  17. wscript.echo "Unauthorized User Detected!" & VbCrlf & "The Program Will Now Close"
  18. wscript.quit
  19. end if
  20.  
  21.  
  22.  
  23.  
  24. 'Set up constant for deleting values from multivalued attribute memberOf
  25.  
  26. Const ADS_PROPERTY_NOT_FOUND  = &h8000500D
  27. Const ADS_UF_ACCOUNTDISABLE = 2                       'For UserAccountControl
  28. Const strX400Search = "X400"
  29. '______________________________________________________
  30.  
  31. 'Set RootDSE
  32. Set objRootDSE = GetObject("LDAP://rootDSE")
  33. strDomain = objRootDSE.Get("defaultNamingContext")
  34. strADPath = "LDAP://" & strDomain
  35. 'wscript.Echo strADPath
  36. Set objDomain = GetObject(strADPath)
  37. 'wscript.echo "objDomain: " & objDomain.distinguishedName
  38.  
  39. 'Setup ADODB connection
  40. Set objConnection = CreateObject("ADODB.Connection")
  41. objConnection.Open "Provider=ADsDSOObject;"
  42. Set objCommand = CreateObject("ADODB.Command")
  43. objCommand.ActiveConnection = objConnection
  44. objCommand.Properties("Page Size") = 5000
  45.  
  46. 'Execute search command to look for Contacts & Groups
  47.     objCommand.CommandText = _
  48.       "<" & strADPath & ">" & ";(&(|(objectClass=contact)(objectClass=group))(mail=*))" & ";distinguishedName,displayName,mail,proxyAddresses;subtree"
  49.  
  50.     'Execute search to get Recordset
  51.     Set objRecordSet = objCommand.Execute
  52.  
  53.  
  54.         'Start procedure
  55.  
  56.     'strResult = strResult & VbCrLf & "Domain: " & strDomain
  57. 'THESE ARE UNEEDED
  58.     'strResult = strResult & VbCrlf &  "#Total Records Found (other accounts): " & objRecordSet.RecordCount & VbCrlf
  59.     AddressCount = 0
  60.  
  61.  
  62. '*************************************
  63. 'Begin second query for users
  64. varDisabledCounter = 0                  
  65.  
  66. 'Execute search command to look for user
  67.     objCommand.CommandText = _
  68.       "<" & strADPath & ">" & ";(&(objectClass=user)(mail=*))" & ";distinguishedName,displayName,mail,proxyAddresses;subtree"
  69.  
  70.     'Execute search to get Recordset
  71.     Set objRecordSet = objCommand.Execute
  72.  
  73.  
  74.         strResult = strResult & "Name" & "," & "Email" & VbCrLf
  75.  
  76.        While Not objRecordSet.EOF 'Iterate through the search results
  77.             strUserDN = objRecordSet.Fields("distinguishedName")     'Get User's distinguished name from Recordset into a string
  78.         strUserDN=Replace(strUserDN,"/","\/") 
  79.             set objUser= GetObject("LDAP://"& strUserDN & "")         'Use string to bind to user object
  80.  
  81.  
  82.             If objUser.AccountDisabled = FALSE Then                    'If User account disabled, then skip          
  83.  
  84.  
  85.  
  86.                        strResult = strResult & objUser.givenName & " " & objUser.sn & ","
  87.                        strResult = strResult & objUser.mail
  88.                        'arrProxyAddresses = objRecordSet.Fields("proxyAddresses")
  89.                        'If IsArray(objRecordSet.Fields("proxyAddresses")) Then
  90.                        'strResult = strResult & VbCrLf & "Proxy Addresses" 
  91.  
  92.                           'For Each ProxyAddress in arrProxyAddresses
  93.                             'Sub: Check X400
  94.                              'If InStr(ProxyAddress, strX400Search) <> 0 Then 
  95.                             '    'Wscript.Echo "#This was an x400"
  96.                             ' Else
  97.                             '     strResult = strResult & VbCrlf &  proxyAddress
  98.                                '  AddressCount = AddressCount + 1
  99.                              ' End If   'Ends loop for X400 address
  100.                          ' Next
  101.                            '   Else
  102.                                 '  strResult = strResult & VbCrLf &  "#Object does not have proxy addresses"
  103.                          ' End If
  104.                               strResult = strResult &  VbCrLf
  105.  
  106.           End If   'End check for disabled user 
  107.  
  108.      objRecordSet.MoveNext 
  109. Wend  'End second query for users
  110.  
  111.  
  112. 'strResult = "Users, Groups & Contacts" & VbCrLf & "-------------------------" & VbCrLf & strResult
  113. 'strResult = strResult & VbCrLf & "Disabled Users" & VbCrLf & "-------------------------" & VbCrLf & strResult2
  114.  
  115. 'Output to a text file
  116. Set objFileSystem = CreateObject("Scripting.FileSystemObject")
  117. Set objOutputFile = objFileSystem.CreateTextFile("C:\Email List.csv")
  118. objOutputFile.Write strResult
  119.  
  120. LF=chr(10)
  121. WScript.Echo "Done - Please Check C:\Email List.csv to see your file."& LF & LF & "If you have any questions please contact Kevin Reed"
  122.  
Nov 28 '12 #1
Share this Question
Share on Google+
1 Reply


Rabbit
Expert Mod 10K+
P: 12,383
This is not a code writing service but if you post what you've tried along with any error messages you get, we can guide you to a solution.
Nov 28 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.