Link to home
Start Free TrialLog in
Avatar of Dan_C
Dan_CFlag for United States of America

asked on

Client-Side CreateObject("Scripting.FileSystemObject") CreateTextFile Fails Window XP

I have a Web Page that I do client-side script using the CreateObject("Scripting.FileSystemObject")  to create some XML files on the client computer. The code works fine on Windows 2000 Professional Workstations but not on XP Pro, I get an unspecified error on the CreateTextFile method. I assume it is XP security, does anyone know of a workaround, I can't use cookies because of the size limitation.

My code is below.

<code>

Function TransferListToXML(objListsrc)

Dim file_being_created, fso, objLstBx, objToXML
      
              ' Name for the ouput document
              file_being_created= objListsrc & ".xml"

      ' create a file system object
      Set fso = CreateObject("Scripting.FileSystemObject")

      ' create the text file - true will overwrite any previous files
      ' Writes to a .xml file in the root directory
      Set objToXML = fso.CreateTextFile("c:\" & file_being_created, true)
      Set objLstBx = document.all(objListsrc)
            
      objToXML.WriteLine("<?xml version=""1.0"" encoding=""UTF-8""?>")
      objToXML.WriteLine("<" & objListsrc & ">")
            
            For i = 0 to objLstBx.length -1
                  objToXML.WriteLine("<RESID>" & objLstBx.item(i).value & "</RESID>" )
                  objToXML.WriteLine("<RESNAME>" & objLstBx.item(i).text & "</RESNAME>" )
            Next

      'All non repetitive xml on bottom goes here
      objToXML.WriteLine("</" & objListsrc & ">")

      ' close the object (xml)
      objToXML.close
      
      Set objToXML = Nothing
      Set fso = Nothing
      Set objLstBx = Nothing
                  
End Function

</Code>
SOLUTION
Avatar of kiddanger
kiddanger
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dan_C

ASKER

It is Intranet and I did add it as a trusted site. I also enabled all ActiveX settings in the Intranet zone and for the trusted site, still not working. The page is actually .net VB language but this is the only way I could that I know of to save a file other then a cookie on the client. I am not familiar with .hta could you elaborate?
Avatar of deighc
deighc

Why must you store a file on the client?
Avatar of Dan_C

ASKER

I was trying to avoid a post back and I didn't want to store the files on the server, that is all a thing of the past now. I have no choice but to
re-code it to save the prefs on the server, the hta will only work if the user has administration rights on the PC, so that option is of no help.

Really?  .hta requires admin privs?  Are you positive?  I would get a second opinion.  Where did you get this information?

This contradicts what you're telling me:

[quote]
As fully trusted applications, HTAs carry out actions that Internet Explorer would never permit in a Web page. The result is an application that runs seamlessly, without interruption.

In HTAs, the restrictions against allowing script to manipulate the client machine are lifted. For example, all command codes are supported without scripting limitations (see command id). And HTAs have read/write access to the files and system registry on the client machine.

The trusted status of HTAs also extends to all operations subject to security zone options. In short, zone security is off. Consequently, HTAs run embedded Microsoft ActiveX controls and Java applets irrespective of the zone security setting on the client machine. No warning displays before such objects are downloaded and run within an HTA
[/quote]

http://msdn.microsoft.com/workshop/author/hta/overview/htaoverview.asp
> the hta will only work if the user has administration rights on the PC

I've deployed HTA's to users who don't have admin rights - no problem.

You don't even need the HTA file to reside on each machine - users can simply open the file from a common shared location.
Avatar of Dan_C

ASKER

OK then, can you explain why would you receive an error message Access Denied when trying to write the file to the local drive?
Avatar of Dan_C

ASKER

As far as I am concerned it is not worth the effort to deal with XP and SP2 I can code it better and faster with Server-Side code.

Read the Object Caching and Access Denied error.

http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/overview/XpSp2Compat.asp
> OK then, can you explain why would you receive an error message Access Denied when trying to write the file to the local drive?

That's hard to say without knowing what local machine priviledges your users have. A user will ALWAYS be limited but the rights imposed upon them - doesn't matter if they're running Word or an intranet app thru an HTA.

Note that the article you linked to also says:

"HTML application (.hta) files are hosted in a different process and are not impacted by the Local Machine zone lockdown."

HTA's use the same basic rendering engine as IE (MSHTML) but run inside a different .exe (mshta.exe rather than iexplore.exe). So, often, security limitations that apply to IE aren't relevant to HTA's.

And as I explained, I've written intranet app's that access the local file system and work OK on XP SP2 in conjunction with an HTA. So it can be done.

> I can code it better and faster with Server-Side code.

Faster and better is good :-)
So maybe that's the best option for you.
Hey Dan...

You don't have to do it in an .hta.  That is just one alternative you have.  Admin rights are not required but a user would need access to the area being written to.

If it's easier for you to do it on the server-side, then do it that way.  If you need some help, we're here for you.
Avatar of Dan_C

ASKER

I have it coded to save the files on the server, I am now working on a way to schedule a 30-day purge job outside of the windows scheduler. I presently run jobs with WHS but want to get away from that and do more .NET. I would like to thank everyone for there comments/help, I just have to figure out who will get the points.

I think they should go to deighc because he originally suggested hta even though I didn't use it.
My feeling is that considering no one provided you with a solution that totally fit your requirements you should either split the points or ask for a refund.

Any thoughts kiddanger??
deighc...

Looks like I answered late.  However, I never have a problem with anything the OP wants to do.  On this site I've asked questions only and have been given points and I have had the only solution and been given nothing.  *throws hands in the air*  So, I just try to help where I can and hopefully the OP finds some or all of it useful.  I think if they don't get a solution they should be able to get their points back but I'm just a pawn on this chess board.
Thanks Dan.  Good luck with it.