MSI executing VB.net application, current user is returning the system user and not the logged on user

穿精又带淫゛_ 提交于 2019-12-02 03:56:20

You could potentially try using WMI:

Dim username, objItem
Dim objWMIService  : Set objWMIService = GetObject( "winmgmts:\\.\root\cimv2" )
Dim colItems  : Set colItems = objWMIService.ExecQuery( "Select * from Win32_ComputerSystem" )

For Each objItem in colItems
    username = objItem.UserName
    if (instr(username ,"\") > 0) Then
        username = Split(username, "\")(1)
    end if   
Next
msgbox username

Or Quser:

Dim strCmd : strCmd = "cmd /q /c for /f ""skip=1 tokens=1"" %a in ('quser console') do @echo %a"
username = CreateObject("WScript.Shell").Exec(strCmd).StdOut.ReadAll()
username = Right(username,Len(username)-1)
msgbox username
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!