?
Solved

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

Posted on 2005-04-19
16
Medium Priority
?
701 Views
Last Modified: 2008-02-01
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>
0
Comment
Question by:Dan_C
  • 6
  • 5
  • 5
16 Comments
 
LVL 14

Assisted Solution

by:kiddanger
kiddanger earned 186 total points
ID: 13821864
Is this on an Intranet?  What zone is the page running in?
0
 
LVL 15

Accepted Solution

by:
deighc earned 189 total points
ID: 13822483
This will most certainly be a security issue.

You could try adding the site to the 'Trusted sites' or 'Local intranet' zone (as kiddanger has already alluded to) but you may find that the only way to get this to work is to run your site inside and .hta file.
0
 

Author Comment

by:Dan_C
ID: 13823122
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?
0
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!

 
LVL 15

Expert Comment

by:deighc
ID: 13823161
0
 
LVL 14

Expert Comment

by:kiddanger
ID: 13826445
Why must you store a file on the client?
0
 

Author Comment

by:Dan_C
ID: 13826606
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.

0
 
LVL 14

Expert Comment

by:kiddanger
ID: 13831252
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
0
 
LVL 15

Expert Comment

by:deighc
ID: 13831887
> 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.
0
 

Author Comment

by:Dan_C
ID: 13833796
OK then, can you explain why would you receive an error message Access Denied when trying to write the file to the local drive?
0
 

Author Comment

by:Dan_C
ID: 13833887
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
0
 
LVL 15

Expert Comment

by:deighc
ID: 13834111
> 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.
0
 
LVL 14

Expert Comment

by:kiddanger
ID: 13844292
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.
0
 

Author Comment

by:Dan_C
ID: 13844353
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.
0
 
LVL 15

Expert Comment

by:deighc
ID: 13844383
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??
0
 
LVL 14

Expert Comment

by:kiddanger
ID: 13845531
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.
0
 
LVL 14

Expert Comment

by:kiddanger
ID: 13845536
Thanks Dan.  Good luck with it.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
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 video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

807 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