Read/Write App Files Under Limited User Account
Hi All,
My desktop app is intended for Windows only. I'm writing files to the hard disk to store app specific configuration.
The applications main data source is a ZIp file that consists several XML files. The user can store this ZIP anywehre they like and the application will extract the necessary files to a temp dir so that it can read in data.
When logged into a PC as either an Administrator or Power User, I am able to read write my config files and extract XML files from the ZIP with no problem.
When logged in as a user with "limited" access, I can only read and write the config files. But when I go to extract any XML files from the ZIP, it seem to get denied due to insufficient permissions.
The working directory for storeing all these files is: C:\Documents and Settings\<USER NAME>\Application Data\<MY APP>\
Don't users with limited access have full read/write permissions to their own home directory?
If not, what can be done to give them full read write access? Is there perhaps some other location I should be using?
Also, would code signing from some place like Verisign do any good?
I'm targeting Windows 2000/XP.
Thanks in advance.
Regards,
Jim
[1261 byte] By [
JimDVa] at [2007-11-27 9:12:08]

# 1
This seems to be the same issue I am having. Looking for help with it,
as well.
> The working directory for storing all these files
> is: C:\Documents and Settings\<USER NAME>\Application
> Data\<MY APP>\
>
> Don't users with limited access have full read/write
> permissions to their own home directory?
>
> If not, what can be done to give them full read write
> access? Is there perhaps some other location I should
> be using?
Additionally, I have found instances where the Application Data directory
did not exist. Isn't this folder supposed to be present in all the <Users>
directories?
Can I ask how you are determining where the directory is, and if it is writable?
When check file.canWrite() is called on the <User>/Application Data directory,
the return value is false, however my test file was written successfully to
the Application Data directory.
Looking for the best place to write Application Data that can be read/written
without fail.
Help ....
-Deba at 2007-7-12 21:58:20 >

# 2
Hi Deb,
I wasn't checking the 'canWrite()', but I will since you mentioned it.
I got the user directory by calling System.getProperty("user.home");
This should return something like: "C:\Documents and Settings\<USER NAME>"
I then append the "Application Data" paths.
I just tried removing the "Application Data" path from the working directory and I am now able to fully read and write files when logged in as a user with limited access.
i.e: my app working directory is : "C:\Documents and Settings\<USER NAME>\<MY APP>\"
I tested this in both Win XP and 2000.
Even though you could sucessfully write a file to that location it may still be restricted like the 'canWrite()' call suggests. I was able to create temp files in that folder as a limited user, but I oculd not copy or extract files into it.
Can anyone shed some light on this?
Jim
JimDVa at 2007-7-12 21:58:20 >

# 3
You can also access the user folder through the registry:
public static final String APP_DATA_FOLDER_CMD = REG_QUERY_UTIL
+ "\"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\"
+ "Explorer\\Shell Folders\" /v AppData";
/**
* Gets the current user Application Data folder path defined in the
* registry.
*
* @return The current user Application Data folder path.
*
*/
public static String getCurrentUserAppDataFolderPath()
{
return queryREG_SZ(APP_DATA_FOLDER_CMD);
}
/**
* Performs the query in the registry for the specified value type.
*
* @param queryString The query to be performed.
* @param valueType The value type.
*
* @return The value data for the specified value name in the registry.
*
*/
public static String queryREG_SZ(String queryString, String valueType)
{
try
{
Process process = Runtime.getRuntime().exec(queryString);
StreamReader reader = new StreamReader(process.getInputStream());
reader.start();
process.waitFor();
reader.join();
String result = reader.getResult();
int p = result.indexOf("REG_SZ");
if (p == -1)
{
return null;
}
return result.substring(p + valueType.length()).trim();
}
catch (Exception e)
{
return null;
}
}
This will get you the user directory from the registry. However, my issue is
that the value returned was:
C:\Documents and Settings\<USER NAME>\Application Data
Which is great, but that folder didn't exists on my computer. I cannot find
any documentation to say why it would be there. Except I had no Application
Data folders under any user. I have XP.
So when running the program on one computer, I had no valid folder to write
to and it wouldn't let me create it. Said the <USER NAME> folder could not
be written to. canWrite() returned false and the directory could not be
created.
On another computer, I had the Application Data folder, the canWrite()
returned false, yet I was able to create a folder and file inside.
I checked the default <ALL USERS> directory and the Application Data folder
did not exist there.
I don't understand how I am supposed to work around it...
If the folder doesn't exist, I need to be able to create it, whether it's in the
<ALL USER> or <USER NAME> folder.
I guess I am counting on the canWrite() to be accurate. Yet it appears that
I cannot rely on the canWrite() since a false was returned. I wrote!!
So confused ... need to be able to write to this folder on any computer...
Help!!
-Deba at 2007-7-12 21:58:20 >

# 4
Well, I've ducked the issue somewhat by simply not messing with the "Application Data" folder at all. Instead I simply go one level up and create a folder for my app. I can then check the canWrite() function and it always comes back as true.
This should probably work for you as well...
Jim
JimDVa at 2007-7-12 21:58:20 >

# 5
Thanks. I'll give it a try. But I'm not sure that will work on Vista.
I think you have to create an <Program Name> folder in the <Application Data>
folder on Vista to be able to write.
I am trying to make in Windows compatible for XP and Vista. It works already
on XP, and only on Vista when you install and run in XP Mode.
I think there needs to be a lot more advice in this forum for working with Java
16 and Vista.
I'll let you know how it goes. Thanks for the help.
-Deb
-Deba at 2007-7-12 21:58:20 >
