Real Software Forums
http://forums.realsoftware.com/

Problem creating a file in W vista e seven
http://forums.realsoftware.com/viewtopic.php?f=6&t=34211
Page 1 of 1

Author:  janluk [ Thu Jun 10, 2010 5:28 am ]
Post subject:  Problem creating a file in W vista e seven

Hi All,

have a problem.
I wrote this code to create a file in a directory of my choice.
Works well on xp but will not work on Windows Vista (32bit) and Windows 7 (32bit). Shows the error message:

An exception of IOException was not handled. The application must shut down.
Exception Error Number: 5
:evil:

Dim f As FolderItem = SpecialFolder.windows.Child ("SmpS.txt")
Dim t As TextOutputStream

f= SpecialFolder.windows.Child ("SmpS.txt")

t=TextOutputStream.Create(f)

t.WriteLine Str(app.LongVersion)
t.WriteLine "try1"
t.WriteLine "Try2"

t.Close

How can I fix this, where am I wrong?
Thanks for the reply.

Author:  jharris [ Thu Jun 10, 2010 6:45 am ]
Post subject:  Re: Problem creating a file in W vista e seven

I don't think Vista or Windows 7 will let you create or modify files in the system folders. You will be better off to
create a folder in the users AppData folder and use it to store the files for your application.

f = SpecialFolder.Preferences.Child("FolderName").Child("SmpS.txt")

or

f = SpecialFolder.ApplicationData.Child("FolderName").Child("SmpS.txt")

Author:  janluk [ Thu Jun 10, 2010 10:22 am ]
Post subject:  Re: Problem creating a file in W vista e seven

Now I try and let you know, thanks for the kindness.

Author:  janluk [ Thu Jun 10, 2010 10:51 am ]
Post subject:  Re: Problem creating a file in W vista e seven

Nothing to do, will not work.
The one that works is;

f = GetFolderItem ("SmpS.txt")

I can not believe that is the only this directory where you can create a file on Vista or W7!!!
Help me!!!

Author:  npalardy [ Thu Jun 10, 2010 11:48 am ]
Post subject:  Re: Problem creating a file in W vista e seven

There ARE protected locations on Windows Vista and 7 that the OS will stop you from modifying.
XP was less strict than Vista and Windows 7 and would let you create files almost anywhere - even if it was potentially unsafe to do so.

In order to create a file in ANY directory you may need to authenticate before trying to create the file.
That might involve declares into OS system calls to validate user id/passwords.

WHAT is it you're trying to save ?
If it's preferences or application specific data there are good places for that.
See SpecialFolder.ApplicationData and / or SpecialFolder.Preferences

Author:  Carharttguy [ Thu Jun 10, 2010 12:44 pm ]
Post subject:  Re: Problem creating a file in W vista e seven

I think your code's working.
But try to launch your app in adminmode.

Right click on your app -> run as admin

Didn't try it with RB yet, but got tha problem many times when I coded in VB6

Cheers

Author:  janluk [ Thu Jun 10, 2010 1:17 pm ]
Post subject:  Re: Problem creating a file in W vista e seven

I want to create a simple text file to store some string in a directory other than the possible application directory so that the operator put us to the nose.
Example control the amount of openings in the demo program or similar.

P.S.You're right Carharttguy.
How it works very well admin and create files in any directory.
Do you have any advice for me view your experience?
Thanks to all!

Author:  kyja72 [ Mon Dec 12, 2011 12:59 pm ]
Post subject:  Re: Problem creating a file in W vista e seven

Windows Vista 64 here with Real Studio 2011r4 Pro
I am having similar trouble.
See bellow in the snip-it the line I commented the trouble I am having.
I have tried nesting this is try catch as well. the ide stops on that line.

Dim s As binarystream, f As FolderItem
f = vol.Root.Child(str(key))
if f<>nil then
s = BinaryStream.Create(f,true) //<-- the ide haults here with ioexception. it does create the virtualvolume on desktop but refuses to create a textfile in it. Probably unless I use a dialog box then it would work.
if s<>nil then
s.Write Data
s.Close
end
end
Exception err as IOException
MsgBox "IOerror - "+str(TextOutputStream(f).LastErrorCode)

Author:  kyja72 [ Mon Dec 12, 2011 1:03 pm ]
Post subject:  Re: Problem creating a file in W vista e seven

Ps

I don't believe it has anything to do with OS file access permissions. Real Studio is running in my account and the desktop where it created the virtual volume and is SUPPOSE to be able to read and write in that virtual volume.

Author:  Wayneg@axisdirect.co.nz [ Mon Jan 30, 2012 7:05 pm ]
Post subject:  Re: Problem creating a file in W vista e seven

This will be a problem with permissions. For example

f = specialfolder.sharedapplicationdata.child("myFile") will work but unless running as administrator will be read only.
f = specialfolder.applicationdata.child("myFile") will work with read/write permissions.

RS has no way of knowing about or requesting elevated privileges for the operation.

The same issue occurs in the registry where HK_LM is read-only to users and read/write to administrators, HK_CU is always read/write. The IDE actually bumps into this problem when Associating file types where it just won't work unless the IDE is launched with elevated privileges.

HTH

Wayne

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/