Hello,
Is there any possibility to get the hostname of the system on which the sv32 process is executed, without using VBA?
- System variable?
- SCADA Basic verb SYSTEM?
- Calling a WinApi function from SCADA Basic?
Hi Armin,
I think you could adapt easily this code in Scada Basic
http://spreadsheetpage.com//tip/retrieving_the_computer_name_or_logged_in_user_name/
But why don't you want using VBA on StartupComplete event? More easy...
nico
But why don't you want using VBA on StartupComplete event? More easy...
For security reason the usage of VBA is strictly forbidden in the IT environment of this corporation.
That's a good reason!!
Well, then I guess the resulting SCADA Basic script would somewhat look like this:
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX API Declarations
DECLARE FUNCTION GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer AS STR, nSize AS Long) AS LONG; 'Computername
DECLARE FUNCTION GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As STR, nSize As Long) AS LONG; 'WindowsUser
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
SUB GetHostname()
DIM ComputerName AS STR;
DIM ComputerNameLen AS LONG;
DIM Result AS LONG;
ComputerNameLen = 256;
ComputerName = STRING(256," ");
Result = GetComputerName(ComputerName, ComputerNameLen);
PRINT(Result);
END SUB
But the code above crashes PcVue. Any idea how I may retrieve the underlying LPString from a SCADA Basic string variable..?
EDIT: Created SPR #64793 for follow-up.
For your information, the SPR #64793 is now closed.
Please see below the corrected SCADA Basis code:
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
'API Declarations
DECLARE FUNCTION GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer AS LONG, nSize AS Long) AS LONG;
Declare Function GetLastError Lib "kernel32" () As Long;
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
SUB Main()
DIM ComputerNameBuf AS LONG;
DIM ComputerName AS STR;
DIM ComputerNameLen AS LONG;
DIM ComputerNameLenResultBuf AS LONG;
DIM Result AS LONG;
DIM ErrorCode AS LONG;
ComputerNameLen = 256;
ComputerNameBuf = Alloc_Buffer(ComputerNameLen);
ComputerNameLenResultBuf = Alloc_Buffer(32);
Put_Buffer(ComputerNameLenResultBuf, 0, ComputerNameLen);
Result = GetComputerName(ComputerNameBuf, ComputerNameLenResultBuf);
Print("GetComputerName() successful: ", Result);
if (Result == 0) then
ErrorCode = GetLastError();
Print("ERROR: ", ErrorCode);
else
ComputerNameLen = Lget_Buffer(ComputerNameLenResultBuf, 0);
ComputerName = CGet_Buffer(ComputerNameBuf, 0, ComputerNameLen, 1);
Print("Computer Name Length: ", ComputerNameLen);
Print("Computer Name: ", ComputerName);
end if
Free_Buffer(ComputerNameBuf);
Free_Buffer(ComputerNameLenResultBuf);
END SUB
Hello, The "hostname" command in DOS or Powershel gives you the requested informationl


