How to get current logged in user (Windows) from Nodejs app

1.1k Views Asked by At

I'm writing a Nodejs application running in client machine (Windows 10), it uses the current logged in user to authenticate on the server.

The problem is, if I run this application under the SYSTEM account then I couldn't get the current logged in user to authenticate.

How can I solve this problem?

1

There are 1 best solutions below

0
Phuc On

I've resolved it by using:

 exec('for /f "tokens=2" %u in ('query session ^| findstr /R "^>"') do @echo %u',
 function (error, stdout, stderr) {
     username = stdout.trim()
 });