GetComputeName / GetUserName

GetComputeName / GetUserName

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

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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

Jugoslav
www.xeffort.com

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.

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.

Thanks, they both worked fine.

David

Leave a Comment

Please sign in to add a comment. Not a member? Join today