Get Windows Username

3 Posts
2 Users
0 Likes
27 Views
(@s-fauchillearcinfo-com)
Posts: 28
Eminent Member
Topic starter
 

Hello,

I need in SCADA to get the windows User Name.
Does someone knows how to do it

I tried this but it makes PcVue crash:
DECLARE FUNCTION GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As STR, nSize As Long) AS LONG; 'WindowsUser

Sub Main()
Dim strName As Str;

GetUserName(strName,255);
End Sub

 
Posted : 02/07/2020 5:10 pm
n.kunzer
(@n-kunzerarcinfo-com)
Posts: 1236
Member Moderator
 

You can use this in VBA
MsgBox VBA.Interaction.Environ$("UserName")

This one is basic and it doesn't send back the domain but only the username.

For more details, you can execute this code

Sub GetDetails()
Dim ObjWshNw As Object
Set ObjWshNw = CreateObject("WScript.Network")

MsgBox ObjWshNw.UserName
MsgBox ObjWshNw.ComputerName
MsgBox ObjWshNw.UserDomain

End Sub

Nico

 
Posted : 02/07/2020 6:18 pm
(@s-fauchillearcinfo-com)
Posts: 28
Eminent Member
Topic starter
 

Thank you Nico.
Finally I didi it in VBA.
But I would had prefered in SCADA

 
Posted : 02/07/2020 7:03 pm