Node.Js - Get windows username

后端 未结 6 1562
臣服心动
臣服心动 2021-02-05 09:50

I am trying to get the windows username of the machine that is running my node.jS app (the app is always running on a Windows machine).

How can I get the current windows

6条回答
  •  庸人自扰
    2021-02-05 10:11

    I understand that this will not give the client user of a web app as OP asked, but this question is very high in the search results for trying to get the logged in user when running a Node application locally.

    You can reproduce the \ output of whoamI and WindowsIdentity.GetCurrent() with environment variables in Windows.

    process.env.USERDOMAIN + '\\' + process.env.USERNAME

    If you'd rather use USERPROFILE:

    process.env.USERDOMAIN + '\\' + process.env.USERPROFILE.split('\\').pop()

提交回复
热议问题