Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

W2K/IIS/ASP : Read / Write impossible with Scripting.FileSystemObject despite r/w rights setup

Posted on 2006-04-18
15
Medium Priority
?
395 Views
Last Modified: 2012-08-13
FileExists works correctly,
but read, write and create ops make the page hang, without error message.

have already checked the rights, following archived ExEx posts, but without effect.
Have checked with firewall / AV disabled, without effect.

The script works fine on my dev environment (XP Pro/IIS).
Problem is on target machine (W2K,IIS).

sample code :
<%
Dim FSO, fichier,ligne,strpath
strPath = Server.MapPath("testcmbp.txt")
Set FSO = server.CreateObject("Scripting.FileSystemObject")

Set fichier = FSO.Opentextfile(strpath,2,true)' 2:w  8:a
fichier.writeline now()
fichier.WriteLine "xavier"
fichier.writeline String(50,"-")
fichier.Close

set fichier=FSO.opentextfile(strpath,1,true)'1 : read
do until fichier.atendofstream
ligne=fichier.readline()
response.write(ligne&"<br>")
loop
fichier.close

Set fichier=nothing
set fso=nothing

%>      

Any help/suggestion welcome !            
0
Comment
Question by:tanuki66
  • 6
  • 4
  • 3
  • +2
15 Comments
 
LVL 33

Expert Comment

by:hongjun
ID: 16478747
It could also be due to your antivirus program.
Make sure you disable "Script Blocking".
0
 

Author Comment

by:tanuki66
ID: 16478914
thanks for your fast response, but "AV disabled" stood for "antivirus disabled".
sorry it was not clear !
0
 
LVL 12

Expert Comment

by:peterxlane
ID: 16480060
Create two subroutines with error trapping and see if you can get some sort of error description:

<%
Sub WriteMyFile
      On Error Resume Next
      Dim FSO, fichier,ligne,strpath
      strPath = Server.MapPath("testcmbp.txt")
      Set FSO = server.CreateObject("Scripting.FileSystemObject")

      Set fichier = FSO.Opentextfile(strpath,2,true)' 2:w  8:a
      fichier.writeline now()
      fichier.WriteLine "xavier"
      fichier.writeline String(50,"-")
      fichier.Close
      Set fichier=nothing
      set fso=nothing
            
      If Err.number <> 0 Then
            Response.Write "ERROR #: " & Err.number & "<br />"
            Response.Write "ERROR DESCRIPTION: " & Err.Description & "<br />"
      Else
            Response.Write "file created successfully<br />"
      End If      
End Sub       

Sub ReadMyFile
      On Error Resume Next
      Dim FSO, fichier,ligne,strpath
      strPath = Server.MapPath("testcmbp.txt")
      Set FSO = server.CreateObject("Scripting.FileSystemObject")
      set fichier=FSO.opentextfile(strpath,1,true)'1 : read
      something = 100 / 0
      do until fichier.atendofstream
      ligne=fichier.readline()
      response.write(ligne&"<br>")
      loop
      fichier.close
      Set fichier=nothing
      set fso=nothing

      If Err.number <> 0 Then
            Response.Write "ERROR #: " & Err.number & "<br />"
            Response.Write "ERROR DESCRIPTION: " & Err.Description & "<br />"
      Else
            Response.Write "file read successfully<br />"            
      End If      
End Sub       

Call WriteMyFile
Call ReadMyFile

%>  
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 7

Expert Comment

by:Cherukuri30
ID: 16481916
check the security options of the folder where you are trying to store the file. If this is the case give full permissions to the folder
0
 
LVL 7

Expert Comment

by:Cherukuri30
ID: 16481974
sorry that should not be a problem ingnore it
0
 

Author Comment

by:tanuki66
ID: 16482368
Thks peterxlane , but that script makes the page's service hang in the middle of nowhere.
0
 
LVL 7

Accepted Solution

by:
Cherukuri30 earned 2000 total points
ID: 16482399
Ok do the below steps

1) open c:\inetpub
2) right click on wwwroot folder and select sharing and security option
3) Once the www properties window is opened then click on security tab
4) Click on add button and then add the usernames wish are starting with IUSR_computer name and IWAM_computer name
5) for both these users assign full permissions and click ok button

Now execute your script
0
 
LVL 12

Expert Comment

by:peterxlane
ID: 16482426
I know everybody keeps saying it, but it has got to be a permissions issue if it is just hanging like that.  I think technically it is not an error, so my error trapping was not displaying an error.  Check and see if you have PermissionChecker installed on the server (I think it is actually part of IIS but most people have never used it).  Try running this code and I will bet that you don't have permission on the file..

<%
Set PermissionChecker = Server.CreateObject("MSWC.PermissionChecker")
strPathToCheck = Server.MapPath("testcmbp.txt")
If PermissionChecker.HasAccess(strPathToCheck) Then
      Response.Write "You have permission to view:" & strPathToCheck
Else
      Response.Write "You do not have permission to view: " & strPathToCheck
End If
Set PermissionChecker = Nothing
%>
0
 
LVL 7

Expert Comment

by:Cherukuri30
ID: 16482483
peterxlane you mean to say the steps which gave are not the right way to sort this problem out? If so which is the best way to solve i am intrested to learn new concepts

thanks
0
 
LVL 12

Expert Comment

by:peterxlane
ID: 16482569
@Cherukuri30 - I think that the five steps you outlined above are most likely what would resolve the problem; however one of the first things that tanuki66 stated was that they had checked the file permissions, so I was going on the assumption that they had already done those five steps.  My first solution posted was an attempt to trap any errors that might have been occurring, but apparently not having access to a file is not an error.  My second solution should show definitively whether or not IUSER_<computername> has permission to access the file.  If it does in fact show that it does have the correct permissions, then we could focus our efforts elsewhere.  I actually learned about the PermissionChecker here at EE, so I figured I would pass it along.  Here is some more information about it:

http://www.microsoft.com/windows2000/en/server/IIs/default.asp?url=/windows2000/en/server/IIs/htm/asp/comp3hf8.htm



0
 
LVL 7

Expert Comment

by:Cherukuri30
ID: 16482588
Thanks peterxlane i do agree with you, The best method is to trap the error and then solve it instead of doing it in traditional way.
0
 
LVL 25

Expert Comment

by:kevp75
ID: 16482684
actually Cherukuri30, I've found that folder (NTFS) permissions do matter, in fact they override IIS security settings

best bet is to try out peters subs to trap the error
0
 
LVL 7

Expert Comment

by:Cherukuri30
ID: 16482703
Thats right i am working out with peter's script for myself to learn more about it
0
 
LVL 12

Expert Comment

by:peterxlane
ID: 16482786
@all - what I discovered by running my own code is that if you don't have permission to access the file, then it will cause it to just hang.  I tested it by running this:

<%
Sub ReadMyFile
     On Error Resume Next
     Dim FSO, fichier,ligne,strpath
     strPath = "C:\boot.ini"
     Set FSO = server.CreateObject("Scripting.FileSystemObject")
     set fichier=FSO.opentextfile(strpath,1,true)'1 : read
     do until fichier.atendofstream
     ligne=fichier.readline()
     response.write(ligne&"<br>")
     loop
     fichier.close
     Set fichier=nothing
     set fso=nothing

     If Err.number <> 0 Then
          Response.Write "ERROR #: " & Err.number & "<br />"
          Response.Write "ERROR DESCRIPTION: " & Err.Description & "<br />"
     Else
          Response.Write "file read successfully<br />"          
     End If    
End Sub
%>

And since it didn't have permission to access that file, it just hung... Maybe the two could be combined together, something like this:

<%
Sub ReadMyFile
      On Error Resume Next
      Set PermissionChecker = Server.CreateObject("MSWC.PermissionChecker")
      Dim oFSO, oFile, strPath
      strPath = "C:\boot.ini"      
      If PermissionChecker.HasAccess(strPath) Then
            Response.Write "You have permission to view:" & strPath & "<br />"
            Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
            Set oFile = oFSO.opentextfile(strPath,1,true)
            Do Until oFile.atenDofstream
                  Response.Write oFile.ReadLine & "<br />"
            Loop
            oFile.Close
            Set oFile = Nothing
            Set oFSO = Nothing            
      Else
            Response.Write "You do not have permission to view: " & strPath & "<br />"
      End If
      If Err.Number <> 0 Then
            Response.Write "ERROR #: " & Err.Number & "<br />"
            Response.Write "ERROR DESCRIPTION: " & Err.Description & "<br />"
      End If      
End Sub       

Call ReadMyFile
%>


0
 

Author Comment

by:tanuki66
ID: 16485271
Thanks for so many suggestions, and keep cool, it's only about computers !
Well, first thing i tried was  peterxlane suggestion (script for file perms).
It works fine and confirms i do have the access right.

Then i followed Cherukuri30's suggestion and...yes the IWAM was missing.(had Admin and IUSR only).

Thanks a lot to all, you gave me a lot of pertinent informations.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

569 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