Solved

Get Computer Name

Posted on 2001-06-04
14
240 Views
Last Modified: 2010-05-18
I want to get the computer name of the client machine and post it to the page as a form value. I would like to do this either automatically when the page loads or after a button or link is clicked.

This is on an intranet, and won't be used on the internet at any point.

I thought that:
%=Request.Cookies("Preferences")("Computer_Name")%
or
%=Request.ServerVariables("REMOTE_HOST")%

would do it but they are not it...


I did a search but the search just sat there several times so I guess I will just ask.

All machines are running IE 4.x or IE 5.x and WinNT.

Thanks In Advance for any help.

(This does not necessarily have to be ASP depending on what other solutions entail.)
0
Comment
Question by:Entropy
  • 5
  • 3
  • 2
  • +3
14 Comments
 
LVL 15

Expert Comment

by:robbert
ID: 6153191
The only ways are a) asking the user (and saving that to a cookie) or b) writing a client-side ActiveX control (requires custom IE security settings).
0
 
LVL 3

Expert Comment

by:Maxim10553
ID: 6153918
couldnt you grab the IP of the computer with Request.ServerVariables("REMOTE_HOST"), store the IP to a variable and pass it to dll acting as a wrapper that takes an IP as its sole parameter and, using the Win API grabs the computer name from the IP(im sure there is a windows function that does this), and send it back to the calling ASP?
0
 
LVL 2

Expert Comment

by:cybermoonlight
ID: 6154294
I seriously doubt that this is possible..you cannot get the computer name from an IP..you can perhaps resolve a netbios add. i'm not sure..but no way can u get com name from ip
0
 
LVL 2

Expert Comment

by:cybermoonlight
ID: 6154303
oops..i may have been a bit hasty..didn't see this was on an intranet..
Also maxim..your comment is exactly what robbert means..isn't it?
on't know how big your intanet is but perhaps you could have static IPs such as .1 for mach1 .2 for mach2, etc..
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 300 total points
ID: 6154482
>>writing a client-side ActiveX control

you can use WSH client-side...its an activeX solution, but you are spared the task of writing your own control:


<html>
<script language="VBScript">
Sub GetCompName()
     Dim wshObj
     Set wshObj = CreateObject("WScript.Network")
     MsgBox wshObj.ComputerName
End Sub
</script>
<body onload="GetCompName()"
</body>
</html>
0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 6154511
The rules are often different on an intranet.  Pick an IP of a machine on your intranet and try the following from the commandline of your webserver:

  nbtstat -A <IP address>

Odds are good that you'll get the remote machine's name table.  If you do, then it's a simple matter to use AspEXEC (http://www.serverobjects.com/products.htm#free) to do something like:

<%
Set myExecutable = Server.CreateObject("ASPExec.Execute")
 myExecutable.Application = "nbtstat -A " & request.servervariables("REMOTE_ADDR")
 myExecutable.ShowWindow = False
 Response.Write "Executing " & myExecutable.Application & "<br>"
 strResult = myExecutable.ExecuteDosApp
 lines = split(strResult, chr(13))
 for i = lbound(lines) to ubound(lines)
   if lines(i) <> "" then response.write lines(i) & "<BR>"
   locmatch = instr(1, lines(i), "<20>")
   if locmatch > 1 then machinename = trim(left(lines(i), locmatch - 1))
 next
%>
<hr>Machine Name: <%=machinename%>
0
 
LVL 3

Expert Comment

by:Maxim10553
ID: 6156175
Also maxim..your comment is exactly what robbert means..isn't it?-> no, my idea does not involve any client-side ActiveX controls, the code and dll are both executed server-side, i think you could do it this way
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 2

Expert Comment

by:cybermoonlight
ID: 6156186
yeah..okay i see what you mean..but i doubt it's possible. Client side activex..will work..but server side..no way
correct me if i'm wrong
0
 

Author Comment

by:Entropy
ID: 6157693
Azrasound

That worked on my machine but will require some editing of the ActiveX permissions possibly.  We are talking a whole department here too so that could mean hundreds.  Still viable... I may be able to get around it, it does prompt so... I will play with it and let you know.

Someone asked how big the network was for static addresses... we have about 60K Employees so that would not be feasible.  I should have mentioned the scope so that machine level changes could be put into perspective sorry about that.

Clockwatcher... I couldn't get your script to work... which could be operator malfunction but I do know the nbtstat command will work... but it gives 6 registered responses, which I think could effect the outcome.

Thanks all... so far. :)
0
 

Author Comment

by:Entropy
ID: 6157706
Also, Azrasound...

 How could I post that out to a value in the page.  I need it to appear in a form and then obviously be passed on. Worst comes to worse they can type it from the box... but that leaves room for user error.
0
 

Author Comment

by:Entropy
ID: 6157990
OK I figured out how to get it into the field...  this might just work.
0
 

Author Comment

by:Entropy
ID: 6158001
<SCRIPT Language="VBScript">
Function GetCompName()
    Dim GetComp
    Set GetComp = CreateObject("WScript.Network")
    document.RequestForm.ComputerName.value = GetComp.ComputerName
End Function
</SCRIPT>


Is what I am using now... I have to do some testing but I think this is the simplest and best way.  If all goes well I think you got it Azrasound thanks.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6158126
just keep us informed...sorry i didnt respond earlier, i was in an all day meeting
0
 

Author Comment

by:Entropy
ID: 6159879
Well, it works, I just have to add a line in there that says "Click Yes on the Security Box" at least until the next image comes out and I can have the security settings changed to enable instead of prompt.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now