1. Avory Rose Pastoral
  2. PowerBuilder
  3. Thursday, 7 March 2024 23:59 PM UTC

Hi,

 

I'm using PowerBuilder 12.5 Classic and want to retrieve the username/computer name of the client upon login.

 

I have tried some scripts, but none of them are working. I need help with this. Any suggestions would be very much appreciated.

Thank you.

Avory Rose Pastoral Accepted Answer Pending Moderation
  1. Tuesday, 12 March 2024 04:13 AM UTC
  2. PowerBuilder
  3. # 1

Hi I have managed to resolve the error now my problem is how can I display the result in login window.

Comment
  1. John Fauss
  2. Wednesday, 13 March 2024 02:21 AM UTC
I can't even begin to respond, as you have supplied so little information. Are you displaying these pieces of information as (read-only) text in the login window, or in input fields (such as single-line edit controls), or in a data entry-type of DataWindow? What is the big picture that you are wanting to accomplish? Please supply some context. Please also provide some idea of your level of expertise with PB.

And, in order to manage expectations, I will let you know now that I cannot write the code for you... that is NOT what we do here. A code snippet (like what was provided earlier to illustrate a point or technique) is one thing and I was happy to provide that in my previous response, but coding solutions for you is what paid consultants are for.
  1. Helpful 1
  1. Avory Rose Pastoral
  2. Wednesday, 13 March 2024 03:13 AM UTC
Thanks for your help. Glad to share with you that everything is working now. :) Thank you so much
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Friday, 8 March 2024 03:50 AM UTC
  2. PowerBuilder
  3. # 2

Hi, Avory - 

You'll need two external function declarations, one for each of the two Windows API functions that will need to be called. If you have never declared and used an external function, here is some online help that may help (it's for PB 2022 R3, but external function declarations work the same in PB 12.5):

    https://docs.appeon.com/pb2022r3/application_techniques/Using_external_functions.html#Declaring_external_functions

Define the two external function declarations in the window or user object that will be finding and setting these two values:

FUNCTION Boolean GetComputerName ( &
   REF String       lpBuffer, &
   REF UnsignedLong nSize &
   ) LIBRARY "kernel32.dll" ALIAS FOR "GetComputerNameW"

FUNCTION Boolean GetUserName ( &
   REF String       lpBuffer, &
   REF UnsignedLong nSize &
   ) LIBRARY "advapi32.dll" ALIAS FOR "GetUserNameW"

Create a window/object function to invoke each API function:

// Function of_GetComputerName() Returns String

// No. of characters (not including the terminating null).
Constant UnsignedLong MAX_COMPUTERNAME_LENGTH = 31

Boolean	lb_rc
ULong   lul_size
String 	ls_name

// Pre-allocate space in a string that will receive the computer's name
lul_size = MAX_COMPUTERNAME_LENGTH
ls_name  = Space(lul_size)
lul_size = lul_size + 1 // Add 1 for the null character that ends each string.

// Obtain the name of the computer via a Windows API function.
// This API function returns True if successful.
lb_rc = This.GetComputerName(ls_name,lul_size)

If Not lb_rc Then
   Return ''
End If

Return ls_name
// Function of_GetUserName() Returns String

// No. of characters (not includeing the terminating null) in the user's name.
Constant UnsignedLong MAX_USERNAME_LENGTH = 255

boolean	lb_rc
ulong   lul_size = MAX_USERNAME_LENGTH
string 	ls_name

// Pre-allocate space in a string that will receive the user's ID/name.
ls_name = Space(lul_size)
lul_size = lul_size + 1  // Add 1 for the null character that ends each string.

// Obtain the user's name via a Windows API function.
// This API function returns True if successful.
lb_rc = This.GetUserName(ls_name,lul_size)

If Not lb_rc Then
   Return ""
End If

Return ls_name

Best regards, John

Comment
  1. Avory Rose Pastoral
  2. Tuesday, 12 March 2024 04:05 AM UTC
Hello,



I have created a function of_getcomputername and of_getusername both are having Unknown function name: of_getcomputername and of_getusername error.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.