473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Can anyone convert this VBS to VB.net?

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
1 1845
Rabbit
12,516 Expert Mod 8TB
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

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

Similar topics

8
by: Sachi | last post by:
Hi, Can anyone convert for me this Vb.bet code into C#? I am trying to convert example a sample from MSDN article. Static types() As Type = {GetType(String), GetType(Byte), _ GetType(Int16),...
7
by: Charles Law | last post by:
Can anyone convert the following C++ interface definition to VB.NET? I have had a go, but I cannot make the Load function work and the IsDirty function gives an error (Object not set to an...
6
by: yxq | last post by:
Hello Can anyone convert the vb6 code to vb.net? Thank you! ************************************************************** Const SPACE = 5 Const BAR_WIDTH = 50 Public GraphPoints(0 To 99) As...
2
by: yxq | last post by:
Hello, I found there are some date formats in the email header, for example: Fri, 23 Sep 2005 08:51:56 +0800 Sat, 17 Sep 2005 09:08:07 Wed Oct 19 13:40:23 2005 19 Oct 2005 13:40:23 +0000...
6
by: Allen | last post by:
I can't figure this out. Can anyone convert this to VB? byte * p = (byte *)(void *)Scan0;
1
by: Lou Civitella | last post by:
I have found code that Recycles the Application Pool but it was written in VBScript can anyone convert this for me to VB.Net? Thanks! 'Appendix B: Application Pool Recycle script - Save as...
5
by: karmalax | last post by:
public static string Somme(string T) { string text1 = ""; double num5 = Strings.Len(T) + 1; int num3 = 7;
0
ANGELSDAGGER
by: ANGELSDAGGER | last post by:
mySql = Insert new row in Last5 Where row = 1 mySql2 = Update (new row just created) in Last5 while value (the variable containing the username) is True. I'm using VB.NET and an Access database...
1
by: IZZI | last post by:
I have this Pascal code. Can anyone convert it to C code for me, plz? Im a newbie in programming. Thanks a lot. const maxsize=100; type DICTIONARY=record last:integer data:...
4
by: waterfall | last post by:
can anyone convert java code to C#?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.