It is sometimes necessary to get the Computer Name of the target system. This is actually really simple. It’s just a function call.
Here’s a code snippet:
The GetEnvVar() function will retrieve the value of any environment variable, but in this case it is getting the local computer name. Notice that if the function fails, a default name is supplied. But you may want to display an error message.