WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Microsoft Client
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

UDF -GetUserNameEx

This UDF uses the GetUserNameEx Windows API function to retrieve an assortment of different available user names for those people looking for forms of the users name other than what the wntGetUser function in the Win32 NT Extender returns. It can be useful to get a user name without loading an extender, or to look up user names sometimes handy with ADSI.
;  NameUnknown = 0, 
;  NameFullyQualifiedDN = 1, 
;  NameSamCompatible = 2, 
;  NameDisplay = 3, 
;  NameUniqueId = 6, 
;  NameCanonical = 7, 
;  NameUserPrincipal = 8, 
;  NameCanonicalEx = 9, 
;  NameServicePrincipal = 10, 
;  NameDnsDomain = 12
;
;BOOLEAN GetUserNameEx(
;  EXTENDED_NAME_FORMAT NameFormat,
;  LPTSTR lpNameBuffer,
;  PULONG nSize
;);


#DefineFunction GetUserNameEx(type)
  dll=StrCat(DirWindows(1),"secur32.dll")
  bbsize=1000
  bb=BinaryAlloc(bbsize)
  BinaryEodSet(bb,bbsize)
  bbs=BinaryAlloc(4)
  BinaryPoke4(bbs,0,bbsize)
  DllCall(dll,long:"GetUserNameExA",long:type,lpbinary:bb,lpbinary:bbs)
  retval=BinaryPeekStr(bb,0,bbsize)
  BinaryFree(bb)
  BinaryFree(bbs)
  Return(retval)
#EndFunction


;demo
For xx=0 To 12
   uname=GetUserNameEx(xx)
   Message("Name code type = %xx%",uname)
Next

Message("All","Done")


Article ID:   W16039
File Created: 2004:03:30:15:42:26
Last Updated: 2004:03:30:15:42:26