I used to call GetComputerObjectName(NameUniqueId, ...) to get an Active Directory ID of local machine. Trying to get same functionality in .NET, does it exist, or is p-invoke the best way to achieve this goal?
I wanted NameUniqueId, not NetBIOS name
galets
2009-03-04 20:48:12
Sorry, I can't find how you might do this without pinvoke.
Jay Riggs
2009-03-06 05:55:30
A:
Had to P-Invoke...
[DllImport("secur32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern bool GetComputerObjectName(int nameFormat, StringBuilder lpNameBuffer, ref int lpnSize);
public static string GetComputerObjectName()
{
const int NameUniqueId = 6;
var lpBuffer = new StringBuilder(260);
var bufferLength = lpBuffer.Capacity;
if (!GetComputerObjectName(NameUniqueId, lpBuffer, ref bufferLength))
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
return lpBuffer.ToString();
}
galets
2009-04-03 21:46:38