• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 658
  • Last Modified:

VBScript runtime error in ASP

hi

I put a VB script into asp to display an internal IP address and computer name in the browser:


<%@ LANGUAGE="VBSCRIPT" %>

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0">
<META HTTP-EQUIV="Content-Type" content="text/html;charset=iso-8859-1">
<TITLE>show IP address</TITLE>
</HEAD>
<BODY>

<%

arAddresses = GetIPAddresses()

Set WshNetwork = WScript.CreateObject("WScript.Network")

info = ""

for each ip in arAddresses
info = info & ip
next

WScript.echo "You IP address = " & info & " " & " " & "You Computer Name = " & WshNetwork.ComputerName


Function GetFQDN(ipaddress)
'====
' Returns Fully Qualified Domain Name
' from reverse DNS lookup via nslookup.exe
' only implemented for NT4, 2000
'====
set sh = createobject("wscript.shell")
set fso = createobject("scripting.filesystemobject")
Set Env = sh.Environment("PROCESS")

if Env("OS") = "Windows_NT" then
workfile = fso.gettempname
sh.run "%comspec% /c nslookup " & ipaddress & " > " & workfile,0,true
set sh = nothing
set ts = fso.opentextfile(workfile)
data = split(ts.readall,vbcr)
ts.close
set ts = nothing
fso.deletefile workfile
set fso = nothing
for n = 0 to ubound(data)
if instr(data(n),"Name") then
parts = split(data(n),":")
hostname= trim(cstr(parts(1)))
Exit For
end if
hostname = "could not resolve IP address"
next
GetFQDN = hostname
else
set sh = nothing
set fso = nothing
GetFQDN = ""
end if
End Function


Function GetIPAddresses()
'=====
' Returns array of IP Addresses as output
' by ipconfig or winipcfg...
'
' Win98/WinNT have ipconfig (Win95 doesn't)
' Win98/Win95 have winipcfg (WinNt doesn't)
'
' Note: The PPP Adapter (Dial Up Adapter) is
' excluded if not connected (IP address will be 0.0.0.0)
' and included if it is connected.
'=====
set sh = createobject("wscript.shell")
set fso = createobject("scripting.filesystemobject")

Set Env = sh.Environment("PROCESS")
if Env("OS") = "Windows_NT" then
workfile = fso.gettempname
sh.run "%comspec% /c ipconfig > " & workfile,0,true
else
'winipcfg in batch mode sends output to
'filename winipcfg.out
workfile = "winipcfg.out"
sh.run "winipcfg /batch" ,0,true
end if
set sh = nothing
set ts = fso.opentextfile(workfile)
data = split(ts.readall,vbcr)
ts.close
set ts = nothing
fso.deletefile workfile
set fso = nothing
arIPAddress = array()
index = -1
for n = 0 to ubound(data)
if instr(data(n),"IP Address") then
parts = split(data(n),":")
if trim(parts(1)) <> "0.0.0.0" then
index = index + 1
ReDim Preserve arIPAddress(index)
arIPAddress(index)= trim(cstr(parts(1)))
end if
end if
next
GetIPAddresses = arIPAddress


End Function

%>

</BODY>
</HTML>



and get this error message:

* Error Type:
Microsoft VBScript runtime (0x800A0035)
File not found
/mywebserver/performance/default.asp, line 89



this VB script without asp works well.

knows someone howto solve this problem ?
0
anoym
Asked:
anoym
  • 3
  • 2
1 Solution
 
RobSampsonCommented:
Hi, on line 89, I suspect that this line:
workfile = "winipcfg.out"

will not work in ASP, because it does not have a full path to find this file from the webserver.
I'm not that familiar with ASP (someone else may help here), but you should try:
workfile = Server.MapPath(./"winipcfg.out")

Regards,

Rob.
0
 
anoymAuthor Commented:
I tried to change from:

workfile = "winipcfg.out"

to:

workfile = Server.MapPath(./"winipcfg.out")

but still get an error:

Error Type:
Microsoft VBScript compilation (0x800A03F2)
Expected identifier
/SSRIntranet/performance/Default.asp, line 85, column 27
0
 
RobSampsonCommented:
Ooops, sorry, try
workfile = Server.MapPath("./winipcfg.out")

I put the quote in the wrong spot...

Regards,

Rob.
0
 
anoymAuthor Commented:
I tried:

<%@ LANGUAGE="VBSCRIPT" %>

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0">
<META HTTP-EQUIV="Content-Type" content="text/html;charset=iso-8859-1">
<TITLE>show IP address</TITLE>
</HEAD>
<BODY>

<%

arAddresses = GetIPAddresses()

Set WshNetwork = WScript.CreateObject("WScript.Network")

info = ""

for each ip in arAddresses
info = info & ip
next

WScript.echo "You IP address = " & info & " " & " " & "You Computer Name = " & WshNetwork.ComputerName


Function GetFQDN(ipaddress)
'====
' Returns Fully Qualified Domain Name
' from reverse DNS lookup via nslookup.exe
' only implemented for NT4, 2000
'====
set sh = createobject("wscript.shell")
set fso = createobject("scripting.filesystemobject")
Set Env = sh.Environment("PROCESS")

if Env("OS") = "Windows_NT" then
workfile = fso.gettempname
sh.run "%comspec% /c nslookup " & ipaddress & " > " & workfile,0,true
set sh = nothing
set ts = fso.opentextfile(workfile)
data = split(ts.readall,vbcr)
ts.close
set ts = nothing
fso.deletefile workfile
set fso = nothing
for n = 0 to ubound(data)
if instr(data(n),"Name") then
parts = split(data(n),":")
hostname= trim(cstr(parts(1)))
Exit For
end if
hostname = "could not resolve IP address"
next
GetFQDN = hostname
else
set sh = nothing
set fso = nothing
GetFQDN = ""
end if
End Function


Function GetIPAddresses()
'=====
' Returns array of IP Addresses as output
' by ipconfig or winipcfg...
'
' Win98/WinNT have ipconfig (Win95 doesn't)
' Win98/Win95 have winipcfg (WinNt doesn't)
'
' Note: The PPP Adapter (Dial Up Adapter) is
' excluded if not connected (IP address will be 0.0.0.0)
' and included if it is connected.
'=====
set sh = createobject("wscript.shell")
set fso = createobject("scripting.filesystemobject")

Set Env = sh.Environment("PROCESS")
if Env("OS") = "Windows_NT" then
workfile = fso.gettempname
sh.run "%comspec% /c ipconfig > " & workfile,0,true
else
'winipcfg in batch mode sends output to
'filename winipcfg.out
workfile = Server.MapPath("./winipcfg.out")
sh.run "winipcfg /batch" ,0,true
end if
set sh = nothing
set ts = fso.opentextfile(workfile)
data = split(ts.readall,vbcr)
ts.close
set ts = nothing
fso.deletefile workfile
set fso = nothing
arIPAddress = array()
index = -1
for n = 0 to ubound(data)
if instr(data(n),"IP Address") then
parts = split(data(n),":")
if trim(parts(1)) <> "0.0.0.0" then
index = index + 1
ReDim Preserve arIPAddress(index)
arIPAddress(index)= trim(cstr(parts(1)))
end if
end if
next
GetIPAddresses = arIPAddress


End Function

%>

</BODY>
</HTML>

but still doesn't work and I get this error:

Error Type:
Microsoft VBScript runtime (0x800A0035)
File not found
/SSRIntranet/performance/dd.asp, line 89
 
0
 
RobSampsonCommented:
Hi, this depends on where the winipcfg.out file actually resides.
With Server.MapPath, if Path doesn't start with a slash, the MapPath method returns a path relative to the directory of the .asp file being processed.

So, in this case, you'll need winipcfg.out in the same folder on the webserver as the asp file with this code in it.  See here for more info:
http://msdn2.microsoft.com/en-us/library/ms524632.aspx

Hope that helps,

Rob.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now