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.

Simple LookupAccountName Example

I've been scouring the internet for a simple example of the LookupAccountName
function to retrieve a user's SID. All of the ones that I have found are
complex and confusing. All I need is the SID. Does anyone have a SIMPLE
VB.NET (or C#) example of retrieving the SID by using the LookupAccountName
function?

Nov 21 '05 #1
1 6715
After searching for a long time, I found an easy way to get a local user's
SID in string format. To do so in VB.NET, do the following:

1. Import the Interop Services namespace:

- Imports System.Runtime.InteropServices

2. Declare the ConvertSidToStringSid function:

- Private Declare Auto Function ConvertSidToStringSid Lib "advapi32.dll"
(ByVal bSID As IntPtr, <System.Runtime.InteropServices.In(),
System.Runtime.InteropServices.Out(),
System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.UnmanagedType.LPTStr)> ByRef SIDString As String) As Integer

3. Call the ConvertSidToStringSid function:

- Dim strSID As String = ""
Dim intSuccess As Integer

Dim user As New
System.DirectoryServices.DirectoryEntry("WinNT://Machine/User")

Dim sidBytes As Byte() = CType(user.Properties("objectsid").Value,
Byte())
Dim sidPtr As IntPtr =
System.Runtime.InteropServices.Marshal.AllocHGloba l(sidBytes.Length)
System.Runtime.InteropServices.Marshal.Copy(sidByt es, 0, sidPtr,
sidBytes.Length)
intSuccess = ConvertSidToStringSid(sidPtr, strSID)

txtSID.Text = strSID.Trim()

I hope this helps some people. It felt like pulling teeth finding this and
I'm glad I finally found a solution.
Nov 21 '05 #2

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

Similar topics

2
by: James Baker | last post by:
I have a very simple query that gets a few records from a database. I need to take this, turn it into XML and post it to a client's website via VBScript. I was able to find an example of...
3
by: Grace Tsai | last post by:
Hi, I am a beginner of XML. I got a simple example as follows: <?xml version="1.0" encoding="ISO-8859-1"?> <note> <to>Tove</to> <from>Jani</from>
0
by: Mick Hardy | last post by:
Hi, Has anyone seen this weird behaviour or have any suggestions or can anyone reproduce it? The history: I converted a large third party DB from 97 to XP and it uses the...
6
by: Tomas Nilsson | last post by:
Working code below (paying back to the groups :) /Tomas Class SidFunctions Enum SID_NAME_USE SidTypeUser = 1 SidTypeGroup
3
by: Dave | last post by:
I am trying to create a couple of event and a memory mapped file for interprocess communication that have security settings such that they can be used between any two users. I have found some...
7
by: Ivan Marsh | last post by:
Hey Folks, I'm having a heck of a time wrapping mind around AJAX. Anyone know of a simple, straight-forward example for pulling a simple query from mysql with PHP using AJAX? As I...
1
by: Ronald S. Cook | last post by:
I'm new to Windows Communication Foundation (WCF) and needing a very simple VB.NET code example or walkthrough so I can create my first solution. If anyone knows a link or two, I would greatly...
3
by: writser | last post by:
hey all, For my study I'm writing a simple threaded webcrawler and I am trying to do this in python. But somehow, using threads causes IDLE to crash on Windows XP (with the latest python...
2
by: imoon | last post by:
Hello I'm looking for a simple ticker example. Text is updated and that must be shown after it is posted. So it must be dynamic and fast. Anyone got an idea how to do that? complete desktop...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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...

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.