Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Tue Nov 12, 2019 8:55 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Problem creating a file in W vista e seven
PostPosted: Thu Jun 10, 2010 5:28 am 
Offline

Joined: Sun Jan 17, 2010 4:06 pm
Posts: 21
Location: Italy
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem creating a file in W vista e seven
PostPosted: Thu Jun 10, 2010 6:45 am 
Offline

Joined: Wed Aug 05, 2009 6:32 am
Posts: 174
Location: Arkansas - USA
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")

_________________
Windows 7 (RB Pro 2012R2.1) / Ubuntu 12.10 (RB Pro 2012R2)


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem creating a file in W vista e seven
PostPosted: Thu Jun 10, 2010 10:22 am 
Offline

Joined: Sun Jan 17, 2010 4:06 pm
Posts: 21
Location: Italy
Now I try and let you know, thanks for the kindness.


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem creating a file in W vista e seven
PostPosted: Thu Jun 10, 2010 10:51 am 
Offline

Joined: Sun Jan 17, 2010 4:06 pm
Posts: 21
Location: Italy
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!!!


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem creating a file in W vista e seven
PostPosted: Thu Jun 10, 2010 11:48 am 
Offline
Real Software Engineer

Joined: Sat Dec 24, 2005 8:18 pm
Posts: 7858
Location: Canada, Alberta, Near Red Deer
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

_________________
Norman Palardy (Real Software)


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem creating a file in W vista e seven
PostPosted: Thu Jun 10, 2010 12:44 pm 
Offline

Joined: Wed Sep 17, 2008 2:45 pm
Posts: 220
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

_________________
My native language is not English.


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem creating a file in W vista e seven
PostPosted: Thu Jun 10, 2010 1:17 pm 
Offline

Joined: Sun Jan 17, 2010 4:06 pm
Posts: 21
Location: Italy
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!


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem creating a file in W vista e seven
PostPosted: Mon Dec 12, 2011 12:59 pm 
Offline

Joined: Wed Jun 09, 2010 10:17 am
Posts: 6
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)


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem creating a file in W vista e seven
PostPosted: Mon Dec 12, 2011 1:03 pm 
Offline

Joined: Wed Jun 09, 2010 10:17 am
Posts: 6
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem creating a file in W vista e seven
PostPosted: Mon Jan 30, 2012 7:05 pm 
Offline

Joined: Mon Oct 03, 2005 4:30 pm
Posts: 54
Location: Auckland NZ
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group