Getting "Logged in" User
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
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
> 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
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
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
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
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
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
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
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
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:
Timo
Edited by - freak on 31 July 2002 22:22:55
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:
That was using Win98se, using XP, the prog crashes.The operation being requested was not performed because the user has not logged on to the network. The specified service does not exist.
Timo
Edited by - freak on 31 July 2002 22:22:55
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Paul.

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
Until now I guessIt's the only way I've ever done it... and never had a problem.
PB - Registered PureBasic Coder

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
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
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 :
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
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 :
there is a pointer for the Length needed.So you have to write:LPTSTR lpBuffer, // address of name buffer
LPDWORD nSize // address of size of name buffer
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
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
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.
> 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.
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Re: Getting
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
Thank you for this work you shared.
Re: Getting


2017 (PB 5.6)
Getting "Logged in" User

Code: Select all
Debug UserName()