Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User's computer name and info

Status
Not open for further replies.

BuzzerTom

Technical User
Aug 20, 2003
35
0
0
BE
Hi all,

I have the following script:

<HTML>
<HEAD> <TITLE>Getting User Information. </TITLE>
<Script Language="VBScript">

Dim objNet
On Error Resume Next

Set objNet = CreateObject("WScript.NetWork")
If Err.Number <> 0 Then
MsgBox "Don't be Shy." & vbCRLF & "Do not press ""No"" If your browser warns you."
Document.Location = "UserInfo.html"
End if

Dim strInfo
strInfo = "User Name is " & objNet.UserName & vbCRLF & _
"Computer Name is " & objNet.ComputerName & vbCRLF & _
"Domain Name is " & objNet.UserDomain

MsgBox strInfo

Set objNet = Nothing
</Script>
</HEAD>
<BODY>
</Body>
</HTML>

The script works fine when you double click the UserInfo.html. But when I upload it to my server or when i try to run it on my IIS, it gives an empty alert box. Can anyone help me ?

Thanx
Buzzer
 
take off on error resume next and you might see what is going wrong.
if the message box is being displayed but it is empty then it is something wrong with the

Dim strInfo
strInfo = "User Name is " & objNet.UserName & vbCRLF & _
"Computer Name is " & objNet.ComputerName & vbCRLF & _
"Domain Name is " & objNet.UserDomain

if it errors during this line then strInfo we indeed be empty
 
I removed the on error resume next part and the result is the same. I don't get an error, I just get an empty message box.

When I double click the UserInfo.html it opens in IE and I get a warning message from IE that an ActiveX component is trying to interact with this page. Do you wish to allow that ? When I choose yes, I get the alert box with the details in it.

But when I open the UserInfo.html on the server or on my local IIS, I don't get the ActiveX warning and the message box is empty.

Any solutions why I get two different results ?
Thanx,
Buzzer
 
If in asp, try this:
Set objNet = Server.CreateObject("WScript.NetWork")

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
I tried it with server.createobject, but that doesn't work. If I make it completely in asp, then I get the pc information of my hosting server and not from the visitor.

I tested it on several computers and I came to a strange conclusion. the script above seems to work in windows xp home (tested it on 2 computers with windows xp home), but is doesn't work on windows xp professional (tested on 2 computers with professional). That's quit strange isn't it ?

Can someone help me with an answer for this ? Or does anyone else knows another way to get the pc name (or something unique) of a users computer?

Thanx
Buzzer
 
You need to have to make the following changes in IE.
you need to add the web site as a trusted site and also you need to enable the option that says "Intialize and script Acitve X Controls not marked as safe."
once you do this it works fine.
 
Thanks,

that works wonderfull. The user will have to do that then. Unless someone knows a way to work around that ?!

One last problem concerning this, it doesn't work in netscape. I searched for something like trusted sites in IE, but I don't find it in Netscape. Does someone know how I can make it work in netscape too ?

Thanx,
Buzzer
 
I already searched the net for a long time, but I don't find a javascript that works in IE and in netscape to do the trick.
 
Hello BuzzerTom,

The facets of the problem are these.
[1] The script tag itself can have a jscript version. It will run in IE-n up.
Code:
<HTML>
<HEAD> <TITLE>Getting User Information. </TITLE>
<Script Language="Jscript">
try{
	var objNet = new ActiveXObject("WScript.Network");
} catch(e) {
	alert("Don't be Shy." + "\n" + "Do not press \"No\" If your browser warns you.");
	alert(e);
	document.location = "UserInfo.html";
}
var strInfo = "User Name is " + objNet.UserName + "\n" +
	"Computer Name is " + objNet.ComputerName + "\n" +
	"Domain Name is " + objNet.UserDomain;
alert(strInfo);
var objNet = null; 
</Script>
</HEAD>
<BODY>
</BODY>
</HTML>
[2] The new ActiveXObject() is jscript specific. Netscape/javascript does _not_ support this construction. Hence, the script won't work in NS.

regards - tsuji
 
ok, so if I understand it correctly I have to test what kind of browser the user is using. If it's IE I can use the script above. And if it's Netscape... what can I do then ? Is there another java function to do it ? Or is there another language that could do the trick for netscape ?

Thanx
Buzzer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top