Welcome aboard! We are happy you are here and wish you good net-raft!
// you need to use javascript framework Node.js
// check out the code below
// try this ... this works
// at first you install "npm install --save path"
//put this code into app.js
var path = require('path');
var userName = process.env['USERPROFILE'].split(path.sep)[2];
var loginId = path.join("domainName",userName);
console.log(loginId);
// type "node app.js" in command prompt
// this is the complete code for javascript framework Node.js
// you can get domainName and computerName
// at first you install "npm install --save path"
//put this code into app.js
var path = require('path');
var userName = process.env['USERPROFILE'].split(path.sep)[2];
var computerName = process.env['COMPUTERNAME'];
var loginId1 = path.join("domainName",userName);
var loginId2 = path.join("computerName",computerName);
console.log(loginId1);
console.log(loginId2);
// type "node app.js" in command prompt
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function () {
try
{
var ax = new ActiveXObject("WScript.Network");
alert('User: ' + ax.UserName );
alert('Computer: ' + ax.ComputerName);
}
catch (e)
{
alert('Permission to access computer name is denied');
}
});
</script>
</body>
</html>
// this is the only solution, works only for IE in intranet or local machine, there is a security reason
// You get username or computer name via VBA or VB.NET (Environ$("username"),Environ$("computername")), but javascript, jquery ... all of client side is security reason
try
{
var ax = new ActiveXObject("WScript.Network");
alert('User: ' + ax.UserName );
alert('Computer: ' + ax.ComputerName);
}
catch (e)
{
alert('Permission to access computer name is denied');
}
});
// important : ActiveXObject works only for IE (new ActiveXObject("ADODB.Connection"))
The most helpful JQUERY solutions