LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Windows Vista, files and directories in program folder

Hello,

as formerly mentioned in the thread "vista hard coded files/folders
(05-09-2007) a standard program folder in c:\programs has limited access.
Therefore, if you try to create a directory or write to a file, the
directories and files are not really written in the program folder than into
a "virtual store".
In my program i create a folder and then create a file and write it into the
folder. So far it works. But when i try to look for the file with the
FileSelectPopup, no file seems to be in the folder. Trying to save the same
file again, causes a "file already exists" error. So it doesn't work right
but i'm not sure whether the problem is the virtual store (it seems to
create the directory and the file and hold it) or CVI, because it can't see
the file with the file select poup, even if it's there in the virtual store.
To get the program to work i changed the programm folder properties for the
user to full access. Then i created the directory manually within the
program folder, because the programm still can't create the directory hard
coded in the programm folder. I think, that's because the directory is still
in the virtual store and so windows tells the program that the directory
already exists.
But with the manually created directory and the full-access privilege
everything works fine now.
So i understand that programs that want to write into its program folder
need full-access privilege befor its started for the first time.

With Windows XP i can handle a setup-cd to our customer, he calls the setup
and the program installs itself and can be started right away. So, i do not
want the customers to run setup and then manually change the access
properties of the program folder (i suspect that some customers are
overstrained....)
So here are my questions:

1. Can i change the user access rights (to full-access) of a program folder
programmatically ? (I dont't think so, because of vista safety standard)
2. What is a good way to write a programm for vista that uses ini-files
(read/write), creates files at run-time or directories, to get it work with
standar user rights of the programm folder?

Thanks for any help

Norbert Rieper


0 Kudos
Message 1 of 6
(5,761 Views)
Hello Norbert,

as you already wrote, it is not possible to change the read/write permissions of protected directories with user rights.
You can, however, use new built-in UAC mechanisms to temporarily assume administrator privileges to make the necessary changes.
The mechanism is described in a Microsoft TechNet article.

The user has to enter his password for this and needs to have the rights to get administrator privileges. If you only want to write this file once, I guess this this is acceptable.

As for your second questions - there really is no "good way" to write to protected folders in Vista.
The Vista security model has been changed to be closer to that of most other operating systems, which means that there are some directories which applications simply are not supposed to write to. Of course, this does not make things easier if you want to write a program that runs in Vista and previous versions of Windows. I suppose a good place to write your ini files to is the <UserProfile>\AppData\YourApp directory, which should always be readable and writeable by the user in Windows Vista, and is also available in XP and 2000.

Here are two more links about UAC:
http://zone.ni.com/devzone/cda/tut/p/id/5538
http://www.regdeveloper.co.uk/2006/09/22/vista_for_developers/

Regards,
Johannes

National Instruments Germany
0 Kudos
Message 2 of 6
(5,737 Views)
Hello Johannes,

thanks for your detailled explanation. So I think i will write my datafiles
created at runtime to the recommended folder UserProfile\AppData\...
Is there an easy way to find out the path of this folder pragrammaticely,
may be reading the registry?

Greetings from Bremerhaven, Germany

Norbert



"JoBa" <x@no.email> schrieb im Newsbeitrag
news:1197627010730-626796@exchange.ni.com...
> Hello Norbert,as you already wrote, it is not possible to change the
> read/write permissions of protected directories with user rights.You can,
> however, use new built-in UAC mechanisms to temporarily assume
> administrator privileges to make the necessary changes.The mechanism is
> described in a <a
> href="http://www.microsoft.com/technet/technetmag/issues/2007/06/UAC/default.aspx?loc=de"
> target="_blank">Microsoft TechNet article</a>. The user has to enter his
> password for this and needs to have the rights to get administrator
> privileges. If you only want to write this file once, I guess this this is
> acceptable.As for your second questions - there really is no "good way" to
> write to protected folders in Vista.The Vista security model has been
> changed to be closer to that of most other operating systems, which means
> that there are some directories which applications simply are not supposed
> to write to. Of course, this does not make things easier if you want to
> write a program that runs in Vista and previous versions of Windows. I
> suppose a good place to write your ini files to is the
> &lt;UserProfile&gt;\AppData\YourApp directory, which should always be
> readable and writeable by the user in Windows Vista, and is also available
> in XP and 2000.Here are two more links about UAC:<a
> href="http://zone.ni.com/devzone/cda/tut/p/id/5538"
> target="_blank">http://zone.ni.com/devzone/cda/tut/p/id/5538</a> <a
> href="http://www.regdeveloper.co.uk/2006/09/22/vista_for_developers/"
> target="_blank">http://www.regdeveloper.co.uk/2006/09/22/vista_for_developers/</a>
> Regards,JohannesNational Instruments Germany


0 Kudos
Message 3 of 6
(5,726 Views)

Norbert,

This function call (include toolbox.h) will do it:

 err = RegReadString (REGKEY_HKCU, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "AppData",
         appdatapath, PATHLEN, &keysize);

By the way I was interested to see that NI now puts the CVI examples in the Public Folder, presumably to avoid per user copies, and to allow write access for compilation and tinkering.

--Ian

 

0 Kudos
Message 4 of 6
(5,704 Views)
Thank you Ian,

your function works fine.
For future projects i guess i will use this AppData directory for hard coded
files and directorys rather than the program directory.

Thank you all for helping.

Norbert Rieper


"Ian W" <x@no.email> schrieb im Newsbeitrag
news:1197663010340-627126@exchange.ni.com...
> Norbert,
> This function call (include toolbox.h) will do it:
> &nbsp;err = RegReadString (REGKEY_HKCU,
> "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
> "AppData",
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;appdatapath,
> PATHLEN, &amp;keysize);
> By the way I was interested to see that NI now puts the CVI examples in
> the Public Folder, presumably to avoid per user copies, and to allow write
> access for compilation and tinkering.
> --Ian
> &nbsp;


0 Kudos
Message 5 of 6
(5,657 Views)
To close the loop here, reading from the registry does not always work. Better to use an SDK call per this thread.
0 Kudos
Message 6 of 6
(4,472 Views)