CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2002
    Location
    Sweden
    Posts
    26

    Question Scripting.FileSystemObject returns Permission denied

    Hi!

    While the code below works perfect in VB, it returns "Permission denied" when I run it through my web-server (page.asp).
    Info:
    - Windows XP
    - Script enabled in the virtual folder
    - No NTFS
    - Even tried to put IUSR_..... in Administrators

    I'm probably missing something basic. Have anyone got any ideas?


    Regards.
    Erik


    Code:
    Dim fso
    Dim textstream
        
    Set fso = CreateObject("Scripting.FileSystemObject")    
    Set textstream = fso.OpenTextFile("C:\Temp\test.txt", 2)
    textstream.Write "hello"

  2. #2
    Cimperiali's Avatar
    Cimperiali is offline Old Uncle Moderator Power Poster Cimperiali is a name known to all (1000+) Cimperiali is a name known to all (1000+) Cimperiali is a name known to all (1000+) Cimperiali is a name known to all (1000+) Cimperiali is a name known to all (1000+) Cimperiali is a name known to all (1000+) Cimperiali is a name known to all (1000+) Cimperiali is a name known to all (1000+) Cimperiali is a name known to all (1000+)
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,722

    Asp and filesystem...

    An Asp page is running in IIS as some user (usually Anonimous or Guest or User).
    You have two choices:
    The dangerous one is: run your asp as user with permission to write on server (really not encouraged!)
    The safer one is: build a Com+ component, which may run even as Administrator, if you want, that has a method with those instructions. Via Asp page, you use createObject to instantiate that component, and use the method (yes, you can pass parameters, and even get a value back or change byref parameters) to read - write files....
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Mar 2002
    Location
    Sweden
    Posts
    26

    The strange thing....

    Thanx for your reply Cimperiali!

    I've already tried the first alternative, and it didn't help.

    The strange thing is that I get the exact same code to work (via IIS) on a Windows 2000 Server. But not on my or my friends machine that both are running Windows XP.

    Do you know if there any changes in file access from 2000 to XP?
    Reading the file works fine. But not opening it for writing.


    Regards.
    Erik

  4. #4
    Cimperiali's Avatar
    Cimperiali is offline Old Uncle Moderator Power Poster Cimperiali is a name known to all (1000+) Cimperiali is a name known to all (1000+) Cimperiali is a name known to all (1000+) Cimperiali is a name known to all (1000+) Cimperiali is a name known to all (1000+) Cimperiali is a name known to all (1000+) Cimperiali is a name known to all (1000+) Cimperiali is a name known to all (1000+) Cimperiali is a name known to all (1000+)
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,722

    Do not know Xp...

    Sorry, I do not work with Xp...
    You sure interactive user has permission to write? You sure the virtual dir has been set with permission to write (IIS settings)?
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  5. #5
    Join Date
    Mar 2002
    Location
    Sweden
    Posts
    26
    Yep, checked...

    Ok... Thanks anyway...


    Regards.
    Erik

  6. #6
    Join Date
    Apr 2002
    Location
    Melbourne, Victoria, Australia
    Posts
    1,792
    The folder C:\Temp must be visible from the Virtual directory - if you are trying to write somewhere other than the virtual directory or one of the sub-folders, you are always going to get into trouble....


    XP has a lot of protection switched ON by default (the opposite to what we're all used to).

    Change the file that you're writing to, to something that can be seen by the virtual directory....see if that works. (I'll assume that you've already tried that, and it works.)

    I don't think that IIS can write to anywhere other than a virtual directory. I have had to reverse map drives on a protected FTP server to get things writeable.

    Good luck....and if you're not bald already, you will be by the time you figure IIS out
    Be nice to Harley riders...

  7. #7
    Join Date
    Mar 2002
    Location
    Sweden
    Posts
    26

    IIS is a nut shell...

    Thanx Twodogs!

    That's what I kind of thought, but I couldn't put my finger on it.
    I'll try some different things on tuesday when I get back to work again.

    How would you write the following line?
    (If your virtual directory is named "/vd".)
    fso.OpenTextFile("C:\Temp\test.txt", 2)

    Like this?
    fso.OpenTextFile("/vd/test.txt", 2)


    Regards.
    Erik

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts



HTML5 Development Center

Click Here to Expand Forum to Full Width