473,405 Members | 2,444 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,405 software developers and data experts.

Please Help me Convert This VB60 Code

Hi All,

Could you please help me convert this code so that it will run in VB.NET
Thank You
Mark Hollander

Private Type USER_INFO
Name As String
Comment As String
UserComment As String
FullName As String
End Type

Private Type USER_INFO_API
Name As Long
Comment As Long
UserComment As Long
FullName As Long
End Type
Private Declare Function NetUserEnum Lib "netapi32" _
(lpServer As Any, ByVal Level As Long, _
ByVal Filter As Long, lpBuffer As Long, _
ByVal PrefMaxLen As Long, EntriesRead As Long, _
TotalEntries As Long, ResumeHandle As Long) As Long

Private Declare Function NetApiBufferFree Lib "netapi32" _
(ByVal pBuffer As Long) As Long

Private Declare Sub CopyMem Lib "kernel32" Alias _
"RtlMoveMemory" (pTo As Any, uFrom As Any, _
ByVal lSize As Long)

Private Declare Function lstrlenW Lib "kernel32" _
(ByVal lpString As Long) As Long

Private Const NERR_Success As Long = 0&
Private Const ERROR_MORE_DATA As Long = 234&

Private Const FILTER_TEMP_DUPLICATE_ACCOUNT As Long = &H1&
Private Const FILTER_NORMAL_ACCOUNT As Long = &H2&
Private Const FILTER_PROXY_ACCOUNT As Long = &H4&
Private Const FILTER_INTERDOMAIN_TRUST_ACCOUNT As Long = &H8&
Private Const FILTER_WORKSTATION_TRUST_ACCOUNT As Long = &H10&
Private Const FILTER_SERVER_TRUST_ACCOUNT As Long = &H20&

Public Function GetUsers(UserNames() As String, Optional ServerName As
String = "") As Boolean

'PURPOSE: Get LoginNames of all users on the domain and
'save in a string array

'PARAMETERS: UserNames(): Empty String array, passed byref,
'to hold user names

'ServerName (Optional): Set to "" if you want user
'names for current machine, otherwise, set to the server
'you want (e.g., Domain Controller Name)

'RETURNS: True if successful, false otherwise

'EXAMPLE:
'Dim sUsers() As String
'dim lCtr as long
'GetUsers sUsers, "MyDomainController"

'OR FOR LOCAL MACHINE

'GetUsers sUsers

'For lCtr = LBound(sUsers) To UBound(sUsers)
' Debug.Print sUsers(lCtr)
'Next

'NOTES: WINDOWS NT/2000 only
Dim lptrStrBuffer As Long
Dim lRet As Long
Dim lUsersRead As Long
Dim lTotalUsers As Long
Dim lHnd As Long
Dim etUserInfo As USER_INFO_API
Dim bytServerName() As Byte
Dim lElement As Long
Dim Users() As USER_INFO 'This function
'is designed to return a string of username
'but optionally, you can change it to
'get this array of the UDT, which
'will provide more information
'about each user
Dim i As Long

ReDim Users(0) As USER_INFO
ReDim UserNames(0) As String

If Trim(ServerName) = "" Then
'Local users
bytServerName = vbNullString
Else
'Check the syntax of the ServerName string
If InStr(ServerName, "\\") = 1 Then
bytServerName = ServerName & vbNullChar
Else
bytServerName = "\\" & ServerName & vbNullChar
End If
End If
lHnd = 0

Do
'Begin enumerating users
If Trim(ServerName) = "" Then
lRet = NetUserEnum(vbNullString, 10, _
FILTER_NORMAL_ACCOUNT, lptrStrBuffer, 1, _
lUsersRead, lTotalUsers, lHnd)
Else
lRet = NetUserEnum(bytServerName(0), 10, _
FILTER_NORMAL_ACCOUNT, lptrStrBuffer, 1, _
lUsersRead, lTotalUsers, lHnd)
End If

'Populate UserInfo Structure
'If lRet = ERROR_MORE_DATA Then

' If lUsersRead 1 that why th for construct

For i = 0 To lUsersRead - 1
CopyMem etUserInfo, ByVal lptrStrBuffer + Len(etUserInfo) *
i, Len(etUserInfo)
If Users(0).Name = "" Then
lElement = 0
Else
lElement = UBound(Users) + 1
End If
'ReDim Preserve UserNames(lElement)
ReDim Preserve Users(lElement) As USER_INFO

'data of interest
Users(lElement).Name = PtrToString(etUserInfo.Name)

'If lRet = ERROR_MORE_DATA Then -- i removed because i lost the last
'entry while the result is NERR_Success

'Other stuff you can get, but not
'returned by this function
'modify this function if you are interested

Users(lElement).Comment = PtrToString(etUserInfo.Comment)
Users(lElement).UserComment =
PtrToString(etUserInfo.UserComment)
Users(lElement).FullName = PtrToString(etUserInfo.FullName)
ReDim Preserve UserNames(lElement)
UserNames(lElement) = Users(lElement).Name
Next

If lptrStrBuffer Then
Call NetApiBufferFree(lptrStrBuffer)
End If
DoEvents
If lRet = NERR_Success Then Exit Do
Loop While lRet = ERROR_MORE_DATA
GetUsers = True
Exit Function
ErrHandler:
On Error Resume Next
Call NetApiBufferFree(lptrStrBuffer)
End Function

Private Function PtrToString(lpString As Long) As String
'Convert a windows pointer to a VB string
Dim bytBuffer() As Byte
Dim lLen As Long

If lpString Then
lLen = lstrlenW(lpString) * 2
If lLen Then
ReDim bytBuffer(0 To (lLen - 1)) As Byte
CopyMem bytBuffer(0), ByVal lpString, lLen
PtrToString = bytBuffer
End If
End If
End Function

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #1
1 2280
"Mark Hollander" <ma**@atcom.co.za> wrote in message
news:uA**************@TK2MSFTNGP10.phx.gbl...
Hi All,

Could you please help me convert this code so that it will run in VB.NET


[...]

Does this not upgrade via the VB.NET upgrade wizard? That would presumably
be a better place to start than posting the code to the newsgroup. If that
doesn't work then post the problems you're having so that people can help
try to solve them.

--

(O)enone
Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Chiller | last post by:
I'm now getting close to finishing my Distance class. In the code below I have included a number of overload operators that test for equality etc. I've also added more code in the TEST_DISTANCE...
5
by: john | last post by:
Here is the short story of what i'm trying to do. I have a 4 sided case labeling printer setting out on one of our production lines. Now then i have a vb.net application that sends data to this...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
3
by: ricolee99 | last post by:
Hi everyone, I have a problem that i have been trying to solve for awhile. I'm given a code where the purpose is to create a general dataset mapper. Given any dataset, i have a class,...
14
by: bbawa1 | last post by:
It says invalid expression term && protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if...
0
by: rahul gupta | last post by:
hi all i got stucked in 1 problem.i am getting err (java.text.ParseException: Unparseable date: "2007-06-29 11:34:59.0") on this line--utilDate = format.parse(convert); code is...
5
by: JohnSmith70 | last post by:
I'm trying to add two values. When adding money it very simple when its 50p+20p=70p. But if I add £1 then I face a problem because 70+1=71 wrong. So I tried to enter £1 as 100p so I have 170p. But...
11
by: ankitmathur | last post by:
Hi, I'm trying to overcome a situation whereby I have to search through 4-5 columns and produce the results with an order by according to the values matched in these columns. Example: My...
1
by: DarkGiank | last post by:
Hi, im new to csharp and im trying to create a class that can change the application database without no rewriting all connection code... but cause some reason it is not working... it tells me that...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.