ActiveX controls only work in Internet Explorer. If you happen to be using this for an office intranet, you can count on some kinda-internet-savvy employee using Firefox and not having your application function properly.
You should always, always make sure that your application will work for 100% of your users before you even start adding features like automatically finding usernames (which requires as much time and effort as having them just TYPE their usernames!)
You appear to be using JavaScript or JScript (you should also always specify your script language in your HTML).
If that's the case, you can just set the cookie from the scripting language. No need to mix languages when it's unnecessary.
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
// Function above is from http://quirksmode.org/js/cookies.html
var networkVars = new ActiveXObject("WScript.Network");
createCookie('username', environmentVars.UserName, 1);
After the user visits this page and everything goes as planned, they will have a cookie that you can access in PHP for their username. Remember, they have to visit the page with the script and THEN visit a new page for this to work in PHP!
<?php
echo "Your username is";
echo $_COOKIE['username'];
?>
Just make SURE this cookie does not overwrite any other cookies named "username" that your intranet might be using!