×
Siemens Industry Online Support
Siemens AG
Entry type: FAQ Entry ID: 92361, Entry date: 12/22/2010
(1)
Rate

How can I determine the name of the computer with a script and write it into a variable?

  • Entry
  • Associated product(s)

Instructions
Implement the following project functions in your WinCC project:

#include "apdefap.h"
void ComputerName(char* TagName)
{
#pragma code ("Kernel32.DLL");
BOOL GetComputerNameA(LPSTR Computername, LPDWORD size);
#pragma code();
char computer[16]; 
int size=16; //buffersize
GetComputerNameA(&computer[0], (LPDWORD)&size);
SetTagChar(TagName, computer);
}

The size of the variable "computer[" and "size"  depends on the length of the computer name. In this example, the length of the computer name is 15 characters. The total length of 16 characters results from the length of the computer name (15 characters) and the zero at the end of the string (1 character).

These functions can be called up in any actions whenever necessary. The parameter "TagName" represents the variable in which the computer name will be written. This is a variable of the type text variable with a 8-bit character set which needs to be configured manually in the variable container of WinCC as a project wide refreshed variable. If you attach this variable to a IO field in a WinCC server image, the computer name is displayed when calling this image. 

This function could be used to recognize a redundancy switch from the master to the standy server from the MultiClient. To achieve this, the computername has to be saved in a local text variable and then be displayed in a I/O field in a server image. 

Keywords
API call, DLL integration, redundancy switch
 

Security information
In order to protect technical infrastructures, systems, machines and networks against cyber threats, it is necessary to implement – and continuously maintain – a holistic, state-of-the-art IT security concept. Siemens’ products and solutions constitute one element of such a concept. For more information about cyber security, please visit
https://www.siemens.com/cybersecurity#Ouraspiration.