Get hostname of the system running PcVue

7 Posts
3 Users
0 Likes
62 Views
(@admin_doc72)
Posts: 493
Member Admin
Topic starter
 

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?

 
Posted : 28/06/2018 5:24 pm
n.kunzer
(@n-kunzerarcinfo-com)
Posts: 1236
Member Moderator
 

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

 
Posted : 29/06/2018 7:59 am
(@admin_doc72)
Posts: 493
Member Admin
Topic starter
 

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.

 
Posted : 02/07/2018 11:51 am
n.kunzer
(@n-kunzerarcinfo-com)
Posts: 1236
Member Moderator
 

That's a good reason!!

 
Posted : 02/07/2018 12:10 pm
(@admin_doc72)
Posts: 493
Member Admin
Topic starter
 

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.

 
Posted : 02/07/2018 6:19 pm
(@admin_doc72)
Posts: 493
Member Admin
Topic starter
 

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
 
Posted : 13/11/2018 3:34 pm
alec
 alec
(@alecarcinfo-com)
Posts: 1
Member Admin
 

Hello, The "hostname" command in DOS or Powershel gives you the requested informationl

 
Posted : 19/12/2018 2:53 pm