Page 1 of 1

Posted: Wed Jul 31, 2002 7:06 pm
by BackupUser
Restored from previous forum. Originally posted by tranquil.

Hi All!

I'm searching for a API Command that returnes the User that is aktive loged in Windows Network. (Administrator eg.)

Anyone knows that?


Mike

Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User

Posted: Wed Jul 31, 2002 7:46 pm
by BackupUser
Restored from previous forum. Originally posted by PB.

> I'm searching for a API Command that returnes the User that is aktive loged
> in Windows Network. (Administrator eg.)

Well it's supposed to be the GetUserName API, but both the following don't work
for me, so I don't know if it's some bug in PureBasic and/or in Windows...

u$=Space(255) : GetUserName_(u$,255) : Debug u$ ; Crashes PureBasic.
u$=Space(255) : GetUserName_(255,u$) : Debug u$ ; Returns empty string.

For the record, the first example above is the correct format according to the
Win32hlp documentation.

PB - Registered PureBasic Coder

Posted: Wed Jul 31, 2002 8:04 pm
by BackupUser
Restored from previous forum. Originally posted by tranquil.

Hi PB, you are right.

I'm sure you forgot the "@" in front of the @var$ but it does not work eigther. It seems to be a bug in PB. Fred?

Mike

Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User

Posted: Wed Jul 31, 2002 8:09 pm
by BackupUser
Restored from previous forum. Originally posted by PB.

> I'm sure you forgot the "@" in front of the @var$ but it does not work eigther.

I've never used "@" for API commands and they all work fine... what exactly is
the "@" for?


PB - Registered PureBasic Coder

Posted: Wed Jul 31, 2002 8:48 pm
by BackupUser
Restored from previous forum. Originally posted by freak.

API commands don't accept strings as values. Usually, you should work with
pointers. That's what the @ is for. If you put the @ in front, the API function
is called with the memory adress of the string as argument, not with the string itself.

It's funny that it worked for you without that.

Timo

Posted: Wed Jul 31, 2002 8:54 pm
by BackupUser
Restored from previous forum. Originally posted by PB.

> API commands don't accept strings as values.
> It's funny that it worked for you without that.

It's the only way I've ever done it... and never had a problem.


PB - Registered PureBasic Coder

Posted: Wed Jul 31, 2002 9:12 pm
by BackupUser
Restored from previous forum. Originally posted by freak.

Now, that's really funny, becourse if you take a look at the
Platform SDK, it's always written like this:

BOOL GetUserName(
LPTSTR lpBuffer, // name buffer
LPDWORD nSize // size of name buffer
);

And LPSTR means: Pointer to a NULL terminated string.

Maybe Purebasic replaces the string with its pointer at compilation time?

About the Command itself:
For me, it always returns 0, and GetLastError_() returns 1245, wich means:
The operation being requested was not performed because the user has not logged on to the network. The specified service does not exist.
That was using Win98se, using XP, the prog crashes.


Timo

Edited by - freak on 31 July 2002 22:22:55

Posted: Wed Jul 31, 2002 9:14 pm
by BackupUser
Restored from previous forum. Originally posted by Paul.
It's the only way I've ever done it... and never had a problem.

PB - Registered PureBasic Coder
Until now I guess :)
Works fine when you use it right...

Buffer.s=Space(256)
nSize.l=256
ret=GetUserName_(@Buffer,@nSize)
MessageRequester("",Buffer,0)


LPDWORD... you need a pointer to the size of the buffer, you can't enter it directly.



- Paul and Rings are thinking the same today... they both win a beer :)



Edited by - paul on 31 July 2002 22:24:38

Posted: Wed Jul 31, 2002 9:15 pm
by BackupUser
Restored from previous forum. Originally posted by Rings.

It works ever with string, coz Purebasic automaticaly use the pointer to the String.But that i snot true to needed longs......

If you read the api carefully you see that :
LPTSTR lpBuffer, // address of name buffer
LPDWORD nSize // address of size of name buffer
there is a pointer for the Length needed.So you have to write:

Length=255:u$=Space(Length) :GetUserName_(u$,@Length)
MessageRequester("Info",u$ ,0)

and it works perfect :)


Damm , Paul was faster :)


Edited by - Rings on 31 July 2002 22:17:08

Posted: Wed Jul 31, 2002 9:21 pm
by BackupUser
Restored from previous forum. Originally posted by freak.

> LPDWORD... you need a pointer to the size of the buffer, you can't enter it directly.

Found out now, too, but too late.

Man, is this kind a competition?
So this would be third place for me.

Timo

--

A debugged program is one for which you have not yet found the conditions that make it fail.

Posted: Wed Jul 31, 2002 11:19 pm
by BackupUser
Restored from previous forum. Originally posted by PB.

> Purebasic automaticaly use the pointer to the String.

Ah, so that's why it's always worked for me without the "@".


PB - Registered PureBasic Coder

Re: Getting

Posted: Thu Jun 29, 2017 2:13 pm
by Poplar

Code: Select all

EnableExplicit

Enumeration 
  #NameUnknown           = 0
  #NameFullyQualifiedDN  = 1
  #NameSamCompatible     = 2
  #NameDisplay           = 3
  #NameUniqueId          = 6
  #NameCanonical         = 7
  #NameUserPrincipal     = 8
  #NameCanonicalEx       = 9
  #NameServicePrincipal  = 10
  #NameDnsDomain         = 12
EndEnumeration 

Define UserName.s = Space(#MAX_PATH)
Define buf_size.l = 0 

; 需要注意的是,第一次调用GetUserNameEx,第二个参数为NULL,第三个参数一定要为0,否则出现内存访问错误。  
GetUserNameEx_(#NameSamCompatible, #Null, @buf_size)
GetUserNameEx_(#NameSamCompatible, UserName, @buf_size)
Debug UserName
__________________________________________________
Code tags added
03.07.2017
RSBasic

Re: Getting

Posted: Fri Jun 30, 2017 10:51 pm
by Olliv
Thank you for this work you shared.

Re: Getting

Posted: Sat Jul 01, 2017 7:21 am
by Marc56us
:arrow: Posted: Wed Jul 31, 2002 11:19 pm :mrgreen: 15 years !

2017 (PB 5.6)
Getting "Logged in" User :?:

Code: Select all

Debug UserName()