Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Get Client Computer name with either Classic ASP or Client Side VBScriHelpful Member!(2) 

ironhide1975 (Programmer)
1 Jul 05 11:32
Is there any easy way to grab a computer name with ASP Classic or Client Side VBScript?

Any help is appreciated.

Helpful Member!(2)  tsuji (TechnicalUser)
1 Jul 05 11:54
Client-side.

set wshnetwork=createobject("wscript.network")
scomputername=wshnetwork.computername
set wshnetwork=nothing

ironhide1975 (Programmer)
1 Jul 05 11:56
like this?

CODE

<script language="vbscript">
set wshnetwork=createobject("wscript.network")
scomputername=wshnetwork.computername
set wshnetwork=nothing
</script>

tsuji (TechnicalUser)
1 Jul 05 11:59
That's what I meant. Security zone setting should be low enough at most prompting the user for consent to let it execute.
ironhide1975 (Programmer)
1 Jul 05 14:32
A co-worker also gave me this, but both scripts do not seem to give me the Computer name. Any ideas?

CODE

<%
                    Dim sIP
                    Dim oShell, oExec, sCommand, sOutput
                    sIP = Request.ServerVariables("REMOTE_ADDR")
                    ''watch for line wrap - begin
                    sCommand = "%comspec% /c [at] echo off & for /f ""tokens=2"" %q in ('ping -n1 -a " & sIP & "^|find /i ""pinging""') do echo %q"
                    ''watch for line wrap - end
                    Set oShell = CreateObject("WScript.Shell")
                    Set oExec = oShell.Exec(sCommand)
                    sOutput = oExec.StdOut.ReadAll
                    Set oExec = Nothing
                    Set oShell = Nothing
                    scomputername = sOutput
                    %>

longhair (MIS)
1 Jul 05 16:16
ironhide1975,
ping -a 0.0.0.0 will return machine name.  what you have is close... the following should help - untested togeather (though i have used all of the code in seperate batch jobs):

test.bat

CODE

REM script to return all ip's used in a subnet
REM Just change the base IP address after from 255.255.255.%2 to whatever range you want (keep the %2 though).

@echo off

if %1!==! goto start
if %1==h goto hundreds
if %1==t goto tens
if %1==u goto units
:start
echo Starting ping
echo Starting ping > pinglist.txt
for %%h in (0,1,2) do call %0 h %2%%h
goto end
:hundreds
for %%t in (0,1,2,3,4,5) do call %0 t %2%%t
goto end
:tens
for %%u in (0,1,2,3,4,5,6,7,8,9) do call %0 u %2%%u
goto end
:units
ping -a -n 1 192.168.5.%2|find "Pinging" >> pinglist.txt
IF %2!==259! goto repeat
:end

:: gets only 2nd element of pinglist
:repeat
for /f "eol=; tokens=2 delims= " %%i in (pinglist.txt) do @echo %%i>>list.txt
if "%i%"=="" goto repeat1
goto repeat
:ender

:: strips everything after 1st instance of '.' or ' '
:repeat1
for /f "eol=; tokens=1 delims=. " %%i in (list.txt) do @echo %%i>>lista.txt
if "%i%"=="" goto repeat2
goto repeat1
:ender1

:: gets rid of 192 and ping
:repeat2
awk "{if($1!=192) print $1}" lista.txt >>listb.txt

this will take awhile to run.  you may want to break it out in sections.  you will also need awk, but yuo can google for it - free.
regards,
longhair
longhair (MIS)
1 Jul 05 16:18
yes - i know this is the vbscript forum, but seeing how it works in dos might inspire some ideas and i believe you can call a bat job with vbscript.  correct?
regards,
longhair
tsuji (TechnicalUser)
4 Jul 05 8:40
ironhide, you said:
>A co-worker also gave me this, but both scripts do not seem to give me the Computer name
which I suppose including the lines I posted?

Here are my comments:

[1] For my suggestion, in case you did not capture the main idea of it, is that work on a client machine via a html script. It can be run soon after the page is loaded via a onload handler. The scomputername is a variable and you must store it in a form, maybe hidden field, which will return to the server in the next round trip after "submitting". If you have no idea what I am talking about, ask you co-worker first or post back.

[2] For you second script, I doubt it _very_ much that it will work.

[2.1] sCommand
    >sCommand = "%comspec% /c [at] echo off & for /f ""tokens=2"" %q in ('ping -n1 -a " & sIP & "^|find /i ""pinging""') do echo %q"

What is the [at]? Maybe the forum trnasformed it from "@"? Even that, when you ping a site with its ip address, the echo will not contain the machine name (even within the domain). It is not the case if you ping the machine name, then ip address may be revealed in the echo back.

[2.2] Besides the syntax will not suite the wshshell.exec method and will hang the server. You _must_ take out the %comspec% /c part.

[2.3] An alternative is to capture the stdout.readall into a string variable, and device a regexp of pattern "Pinging machinename [ipaddress]" (figurative only). _But_, since you ping the ipaddress, the resulting pattern will only be "Ping ipaddress" in the stdout. That's what I mean in [2.1].

If you know the ipaddress through the server variable as you've shown, then you can use a little free asp component doing a reverse lookup of your domain. You can refer to a previous thread I'd posted:
    http://tek-tips.com/viewthread.cfm?qid=891609&amp;page=1
Check it out.

- tsuji
tsuji (TechnicalUser)
4 Jul 05 8:53
Further note:

An immediate note to further a point I'd overlooked: it is that you use -a switch. It does take away the inconvenience I mentioned in [2.1]/[2.3]. The result may be not completely reliable, but it is viable.

In that case, the procedure is this.
[1] Take away the %comspec% /c in the scommand.
[2] Use simply this scommand:
    scommand="ping -n1 -a " & sIP
[3] Capture stdout.readall to a string variable, sout, say.
[4] Device the regexp

set regex=new regexp
with regex
    .ignorecase=true
    .global=false
    .pattern="Pinging.*?\[" & sIP & "\]"
end with
set matches=regex.execute(sout)
scomputername=matches.item(0)
scomputername=replace(replace(scomputername,"Pinging ","")," [" & sIP & "]",""))

Then you might get a sensible scomputername. You might try it first. Detail might need some fine tuning. (The regexp pattern I just write off hand. It might need some refinement. But, I think it is about that.)

- tsuji
longhair (MIS)
5 Jul 05 7:41
tsuji,
nice detailed explanations.  a star for you.
regards,
longhair
UnderTheRadar (IS/IT--Management)
11 Jul 05 17:13
I don't do a lot of web development, so I'm not sure if any of these methods will work for you but it looks like they may be a little easier if they do.

Using Local System Environment Variables:

CODE

set shell = WScript.CreateObject( "WScript.Shell" )
computername = shell.ExpandEnvironmentStrings("%COMPUTERNAME%")
wscript.echo computername

Using Hostname

CODE

SET objShell=CreateObject("Wscript.Shell")
DIM objExec, strResult
SET objExec = objShell.Exec("hostname")
strResult = objExec.StdOut.ReadAll
WScript.Echo strResult

Using WMI

CODE

Set wmiColl = GetObject("WinMgmts:root/cimv2")_
  .ExecQuery("Select * FROM Win32_ComputerSystem")
For Each wmiObj in wmiColl
  WScript.Echo wmiObj.Name
Next

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close