Software Archive
Read-only legacy content
17061 Discussions

GetComputeName / GetUserName

davidgraham
Beginner
964 Views
I am trying to use the GetComputerName / GetUserName functions but I get an error when I run them - the parameters must be wrong.

Does anyone have a example of using these functions, or is there a better way to get the Computer Name / User Name?

Thanks, David
0 Kudos
4 Replies
Jugoslav_Dujic
Valued Contributor II
964 Views
It's fishy declaration of GetComputerName / GetUserName in ADVAPI32.f90 and KERNEL32.f90. The docs say that nSize argument is actually, speaking in fortran terms, INTENT(INOUT), i.e. it's a pointer to an integer, not integer-by-value. Thus, it would be more natural that the fortran declaration has !DEC$ATTRIBUTES REFERENCE:: nSize

Workaround for that is to pass LOC(nSize) argument, not nSize:

 
CHARACTER(40):: sUser 
 
nSize=40 
bSt=GetUserName(sUser,LOC(nSize)) 


Jugoslav
0 Kudos
sabalan
New Contributor I
964 Views
INTEGER*4 Result

CHARACTER*(As long as needed) UserName, CompName

Result = GETENVQQ("USERNAME", UserName)
Result = GETENVQQ("COMPUTERNAME", CompName)

USERNAME and COMPUTERNAME are true for W2K. Enter SET at command line to see what they are called in your OS.

Sabalan.
0 Kudos
sabalan
New Contributor I
964 Views
USE DFLIB

INTEGER*4 Result

CHARACTER*(As long as needed) UserName, CompName

Result = GETENVQQ("USERNAME", UserName)

Result = GETENVQQ("COMPUTERNAME", CompName)

USERNAME and COMPUTERNAME are true for W2K. Enter SET at command line to see what they are called in your OS.

Sabalan.
0 Kudos
davidgraham
Beginner
964 Views
Thanks, they both worked fine.

David
0 Kudos
Reply