0
Votes
Undo
  1. Andy Preman
  2. PowerBuilder
  3. Monday, 22 February 2021 14:45 PM UTC

Hello,

How do I get the FQDN of the computer I am running on.  There is a Windows function GetComputerNameEXA, however it uses an enumerated datatype, from which I gathered is not supported in Powerbuilder.

I am looking to get something like 'mycomputer.mydomain.com'

Does anyone have any suggestions?

Thanks,

Andy

Accepted Answer
John Fauss Accepted Answer Pending Moderation
  1. Monday, 22 February 2021 17:08 PM UTC
  2. PowerBuilder
  3. # Permalink
2
Votes
Undo

Hi, Andy -

First, I suggest you use the GetComputerNameExW (Unicode) flavor of this API function instead of the ANSI flavor.

This API function uses a value of the COMPUTER_NAME_FORMAT enumeration, which the online Win API documentation shows is defined as follows:

typedef enum _COMPUTER_NAME_FORMAT {
  ComputerNameNetBIOS,
  ComputerNameDnsHostname,
  ComputerNameDnsDomain,
  ComputerNameDnsFullyQualified,
  ComputerNamePhysicalNetBIOS,
  ComputerNamePhysicalDnsHostname,
  ComputerNamePhysicalDnsDomain,
  ComputerNamePhysicalDnsFullyQualified,
  ComputerNameMax
} COMPUTER_NAME_FORMAT;

As Roland points out, an enumeration is a whole-number series that begins at zero. Thus, ComputerNameNetBIOS = 0, ComputerNameDnsHostName = 1, ComputerNameDnsDomain = 2, etc.

I believe an enumerated data type in C/C++ is equivalent to a Long in PB. Therefore, the external function declaration in PB should be something like:

FUNCTION Boolean GetComputerNameEx ( &
   Long      NameType, &
   String    lpBuffer, &
   REF ULong nSize &
) LIBRARY "kernel32.dll" ALIAS FOR "GetComputerNameExW"

You must pre-load the string argument with a sufficient string of space characters prior to calling this Windows API function. Typically, this is done via a PowerScript statement such as:

ls_buffer = Space(256)   // example

Make sure you load a sufficient number of spaces to handle the longest value that the API function can return (refer to the Win API documentation).

Here is the URL for the Microsoft online documentation on this API function:

https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getcomputernameexw

HTH

Regards, John

Comment
John,



That worked perfectly.



Thanks for the help,



Andy
  1. Andy Preman
  2. Monday, 22 February 2021 17:44 PM UTC
You're welcome! If you wouldn't mind, please mark this question as resolved? Thanks.
  1. John Fauss
  2. Monday, 22 February 2021 19:46 PM UTC
And please mark which answer is correct.
  1. Armeen Mazda @Appeon
  2. Monday, 22 February 2021 20:14 PM UTC
There are no comments made yet.
Andy Preman Accepted Answer Pending Moderation
  1. Monday, 22 February 2021 16:58 PM UTC
  2. PowerBuilder
  3. # 1
0
Votes
Undo

Roland,

Thanks for the reply.  So how would I define the 'GetComputerNameEXA' function in 'Global External Functions'?

Andy

Comment
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Monday, 22 February 2021 16:33 PM UTC
  2. PowerBuilder
  3. # 2
0
Votes
Undo

An enumeration is a number starting at zero for the first value.

Comment
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.