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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read text from remote computer and display to ASP

Status
Not open for further replies.

acewilli

IS-IT--Management
Apr 11, 2003
98
US
Hello, can anyone help me with this? I've been turning my wheels and below is what I tried on my last attempt and it isn't working. If anyone knows how to do something like this I would much appreciate it.

I need to from a web page search for text in a text file on a remote computer and then display the results to the web page. If there is an easy way to do this please let me know. I am at a loss of what to do. Below is my last attempt.

search.asp that calls the 2nd asp called searchresult.asp
Code:
<%@ Language=VBScript %>
<% 
dim visitor
dim member
visitor=request.serverVariables("LOGON_USER")
member=right(visitor,len(visitor)-instr(1,visitor,"\"))
response.write "Greetings " & member & "!"
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<SCRIPT LANGUAGE=javascript>
<!--
	function Check()
	{
		if(document.form1.TextToSearch.value == 0)
		{
			alert("Please enter text to search !!")
			document.form1.TextToSearch.focus();
			return false;
		}
	}
//-->
</SCRIPT>
<BODY>
<P>&nbsp;</P>
<FORM METHOD=POST id=form1 action="searchresult.asp" name=form1 onsubmit="return Check();">
  Enter text to search for:
  <INPUT TYPE=TEXT NAME="TextToSearch">
  <P>
  Select BasePage Site:
  <select name="select">
    <option value="DTC0B00BD5A3B8B" selected>A</option>
    <option value="DTC0D0065A9FEE1" >B</option>
    <option value="DTC0D0065EFC8FE" >C</option>
    <option value="DTC0F00F1732570" >D</option>	
    <option value="DTC0600B57DABCA" >E</option>
    <option value="DTC0D0065B9FBF6" >F</option>
    <option value="DTCPCASOB30LY41" >G</option>
    <option value="DTC0D00651D79F3" >H</option>
    <option value="DTC0D00655D09F2" >I</option>
    <option value="DTCPTXWL9MTQY41" >J</option>					
  </select>
  <P>
  <INPUT TYPE=SUBMIT VALUE="Begin Search!" id=SUBMIT1 name=SUBMIT1>
</FORM>
</BODY>
</HTML>

searchresult.asp
Code:
<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<P><H3>Search Results</H3></P>
You have searched for: <B><%=Request("TextToSearch")%> on <%=Request("Select")%></B>
<hr>

<%
Dim strtextToSearch
Dim strselect
Dim strfile
Dim strcmd

strtextToSearch = Request("TextToSearch")
strselect = Request("Select")
'Now, we want to search all of the files
Dim fso

Const ForReading = 1
Set fso = Server.CreateObject("Scripting.FileSystemObject")

'Specify the folder path to search.
Dim FolderToSearch
If strselect = "DTC0B00BD5A3B8B" then
    FolderToSearch = "K:\BP2000.log"
    strcmd = "%comspec% /Q /C find /I " & Chr(34) & strTexttoSearch & Chr(34) & " " & FolderToSearch & " >K:\output.txt"    
    strfile = "K:\output.txt"
elseif strselect = "DTC0D0065A9FEE1" then
    FolderToSearch = "L:\BP2000.log"
    strcmd = "%comspec% /Q /C find /I " & Chr(34) & strTexttoSearch & Chr(34) & " " & FolderToSearch & " >L:\output.txt"    
    strfile = "L:\output.txt"
elseif strselect = "DTC0D0065EFC8FE" then
    FolderToSearch = "M:\BP2000.log"
    strcmd = "%comspec% /Q /C find /I " & Chr(34) & strTexttoSearch & Chr(34) & " " & FolderToSearch & " >M:\output.txt"    
    strfile = "M:\output.txt"
else
response.write "File does not exist!"
end if

    Dim oWSH
     Set oWSH= Server.CreateObject("WScript.Shell")
     oWSH.Run strcmd, 0, True
     set oWSH = nothing

Call getinfo(strfile)

Function getinfo(strfile)
IF fso.FileExists(strfile) THEN
       response.write "file exists" & "<br>"
    Set objTextStream = fso.OpenTextFile(strfile,ForReading)
        'Read the content
        strFileContents = objTextStream.ReadAll
           Response.Write "<B>" & strFileContents & "</B>"
        objTextStream.Close
Else
        response.write "Please wait on file to be created."
        WScript.sleep 20
        Call getinfo(strfile)
End If
End Function
    'Destroy the objects
    Set objTextStream = Nothing
'    Set objFolder = Nothing

Set fso = Nothing
%>
<center><a href="search.asp">Back</a></center>
</BODY>
</HTML>
 
Unless you changed the security settings on your IIS server, all of your ASP will run under the security profile of the local IUSR_<MachineName> account. This account, being local to your server, will not have any permissions to read files from drives mapped on other machines.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top