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

System UDFs

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

UDF-GetUserName

Keywords: 	 UDF-GetUserName

Get the current logged on user:
#DefineFunction GetUserName()
   dllname=strcat(dirwindows(1),"Advapi32.DLL")
   bufsize=100
   PTRBB=BinaryAlloc(bufsize) ; allocate a memory buffer of n bytes
   PTRNAM=BinaryAlloc(4)
   BinaryPoke4(PTRNAM,0,bufsize)
   DllCall(dllname, long:"GetUserNameA", lpbinary:PTRBB, lpbinary:PTRNAM)
   BinaryEODSet(PTRBB,100) ; set the end of 
   username=BinaryPeekStr(PTRBB, 0, 100)
   BinaryFree(PTRBB) 
   BinaryFree(PTRNAM)
   return (username)
#EndFunction

userid=GetUserName()
Message("Userid",userid)




Article ID:   W15326
File Created: 2002:09:05:13:51:20
Last Updated: 2002:09:05:13:51:20