Modify file permissions in a windows environment

Hi everyone,
I'm currently looking for a way to define a file as readable and writable under a Windows environment.
I saw 3 relevant methods in the java.io.File class, which are:
setReadable
setWritable
setExecutable
There are 2 versions of those methods, among which you have one that allow you t set readable and writable flags for "everyone" (meaning any user?).
I am currently develloping an application where files must be shared (readable and writable) between many users (from a Windows user point of view).
Reading the files causes no issue. However, a "FileNotFoundException (access denied)" is raised anytime I try to overwrite a file created by some other windows user.
Apparently, those setWritable, setReadable methods do not work ... or I am messing up somewhere?
The solution I'm looking for has to be Java native, since this application has to remain portable to any other platform (no Runtime.exec call with DOS commands).
Here's a dummy application I made which can help you reproduce my problem:
package local.test;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class Test {
     public static void main(String[] args) throws IOException{
          File file = new File("C:/test.txt");
          file.createNewFile();     
          System.out.println("R - " + file.setReadable(true));
          System.out.println("W - " + file.setWritable(true));
          System.out.println("X - " + file.setExecutable(true));
          System.out.println("R everyone - " + file.setReadable(true, false));
          System.out.println("W everyone - " + file.setWritable(true, false));
          System.out.println("X everyone - " + file.setExecutable(true, false));
          FileWriter writer = new FileWriter(file);
          writer.write(System.getProperty("user.name"));
          writer.close();
          System.out.println("R - " + file.setReadable(true));
          System.out.println("W - " + file.setWritable(true));
          System.out.println("X - " + file.setExecutable(true));
          System.out.println("R everyone - " + file.setReadable(true, false));
          System.out.println("W everyone - " + file.setWritable(true, false));
          System.out.println("X everyone - " + file.setExecutable(true, false));
}All functions return true with the first user. When executing with some other user, setWritable always return false.
The call to writer.write(System.getProperty("user.name")); raises an exception when trying to open the FileOutputStream.
Just for the memo, the files I want to create will be under the "Documents and Settings\All Users\Application Data" folder.
Thanks in advance for your help,
Eric

Alan,
Many thanks for your reply, it really helps knowing that I shouldn't look any further yet.
I believe it may be useful to add this note to the javadoc, because it currently mentions that the call to this method will set it as readable/writable/executable for "everyone", with no more information, which is why I was a bit lost.
Anyway, I'm looking forward to the JDK7 ;) Keep up the good work!

Similar Messages

  • Compressed dump file while export on Windows!

    Hi All
    Could someone suggest how do we take and compressed dump file while exporting on Windows environment with oracle 9.2.0.6.Please specify the exact syntax how to proceed on this.
    Thanks
    Bala.

    I don't think that exp tool can compress the export file it is creating (the compress parameter has nothing to do with the export file but with the way the database objects are going to be created in the target database).
    If you run export under Unix, there is a possibility to use Unix pipes to compress the export file during the export using Unix commands (compress or gzip for example). I don't know how to do something similar under Windows I have some doubts about this possibility.

  • Windows file permissions problems

    We have an Xserve G5 that was running Server 10.3. I upgraded it directly to Server 10.5. Since then, I am having problems with some of our Windows users.
    When they create a new folder, it puts them as the owner, but gives them NO rights. I am using ACLs to give full rights to the group that needs access, and also setting the POSIX group rights to read/write. So once they leave that folder, they can no longer get back in. I have SMB set to inherit rights from the parent, and the ACL is set to inherit as well. Other people in the group can access the folder, just not the owner! I change the owner permissions and all is well (for that folder at least). How do I need to set SMB so it follows the inheritance I set?
    Once I have the folder set correctly, any new files created there have the POSIX group set to read only. The ACL inherits properly and still has full control. The owner is set correctly, usually. It is not consistent.
    Once someone creates a file in any folder, if a Windows user modifies a file someone else created, it changes the owner name and gives them no rights. It also creates a new ACL record. If the original owner was a Mac user, it creates a new explicit ACL with all rights except execute and delete. If the file has ACL records already, it duplicates them and gives whatever rights it feels like (it seems). One new record may say Allow Delete only, and the next one say Allow Read except for execute. The only thing for certain is it will never match the original ACL. It always adds the new ACLs at the top of the list, and the duplicates are grayed out as if they were actually inherited that way. The most 'popular' file I've found so far had 128 "inherited" ACL records!
    It is also denying access to some folders that the user has the correct permissions for. For instance, I can create/modify/delete files logged in on the Mac side, but when I log in on Windows, I have problems accessing files/folders. It shows everything as read only. Even if I change the properties in Windows, it will revert back to read-only when I apply the change.
    We have a new Xserve that we will be moving the file services to. At that time, all the Windows users will be moved completely to the Mac side - currently the Windows users are accessing the Xserve and a Novell server.
    Thanks in advance for any help.

    Hi Thy,
    Based on my research, the Trusted Installer is a service, for those resources which only allow Trusted Installer to modify, neither Administrator nor System can modify them.
    I am wondering that how secure the network and physical environment is that you need to create a GPO to prevent users making permissions changes on system files. These system files normally only can be modified by Administrators,
    System or Trusted Installer, which is secure enough when we don’t add users we don’t trust enough to Administrators group.
    >What is the best way to undo this while leaving the audit failures turned on and still retaining the correct permissions on all the files?
    As long as administrators on these machines are qualified, you can remove the Group Policy. If not, please don’t make any user you don’t trust as Administrator.
    >What happens to the files that aren't owned trustedinstalled than now have the trustedinstaller default permissions under system32 and syswow64 if I were to remove the gpo?  What file  permissions would be retained?
    We should keep the default permissions, if those files weren’t owned by Trusted Installer before, we should change the original owner back, vice versa.
    Here are some related articles below I suggest you refer to:
    New ACLs Improve Security in Windows Vista
    http://technet.microsoft.com/en-us/magazine/2007.06.acl.aspx
    SYSK 277: How-To Bring Back the TrustedInstaller
     http://blogs.msdn.com/b/irenak/archive/2007/01/30/sysk-277-how-to-bring-back-the-trustedinstaller.aspx
    Best Regards,
    Amy

  • Problem with file permissions in Windows shares

    Due to a company merger we are now supporting a group of Macs in our PC environment. These Macs connect to our Windows shares. This generally works well, however we have discovered a problem. It’s to do with the way our Macs interact with our Windows shares. When they copy a file to a windows share they take the permissions for the file they copy from the route of the share rather than from the subfolder the files are copied to and write the file permissions accordingly.
    This only affects admin users who use Macs with the ability to change file permissions. Everyone else inherits the permissions from the subfolder as they should because their account can’t change the permissions. If the route and subfolder permissions are the same then there is no change. If they are different, the Mac will use the share route permissions as preference.
    We have shares where users don’t have access to the route folder but do have access to other folders. This is so that they can’t change the top level folder structure. However they are able to create folders and files under the top level folders. If an administrator uses a Mac, no one has access to any files or folders they create because users don’t have access to the route folder and this is copied to the files and folders they create. This doesn’t affect our PC’s only the Macs.
    We are using the latest Mac OS fully updated and Windows 2008 server. Is this a normal Mac ‘Feature’? Is there a work around?

    I’m a bit disappointed by the lack of response to my problem. As Windows is the predominant file server in business, this problem must have occurred before.
    Are Mac people really saying that Macs are not designed to connect to networks? At the moment our Macs are unusable apart from a few isolated tasks. Basically they are used by a few designers who work in isolation. If PC’s had this problem no one would buy them.

  • Bursting control file for Printer not working in WINDOWS ENVIRONMENT

    Hi,
    We are trying to print xml publisher report output (PDF) using bursting control file. Is not wokring.
    We are using ebs (R12.1.1) on Windows environment.
    Any pre-requisite setup (ie. cups config) should be done before printing using control file. Please guide me i am not having knowledge in printer setup and printer part..
    Thanks in advance
    --Ben                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Hi Hussein,
    Yes, I am able to print seed concurrent report (o/p -text) to that printer (method:- giving the printer name and copies by clicking " Option " in SRS window.. )
    When i do the same for xml publisher publisher report to the same printer , its not working using bursting control file.
    I too made the test in xml publisher report without bursting control file , there i faced another new issue. Let me explain
    1. We are using RDF as data source . here o/p :-" XML "
    2. We are using RTF as layout. In template definition, i chose the default o/p type as :- "HTML"
    3. When i submit the request, i choose the printer which is working fine for printing seeded report. (method:- giving the printer name and copies by clicking " Option " in SRS window.. )
    4. My printer getting prints HTML tag, instead of desired o/p. I wondered after seeing the printout.
    5. I cross checked by clicking view output, its showing me the exact html output as per RTF layout.
    Dont know wat happening ??? Help me out.
    i did the same for changing default output type in template definition to RTF,PDF.. its printing source code of the output type instead of printing output.
    Thanks & Regards,
    --Ben                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • FTP Receiver File adapter  -- CRLF In output File in Windows environment.

    Hi All,
    Idoc to File : Receiver File adapter.
    I use the endseparator 'nl' and the output file is coming correctly with NFS and It is not working when we are doing with with FTP.
    Tested with NFS (Unix environment)
    I used the endseparator 'nl' and the output file is coming with CRLF.
    Tested with FTP (Windows environment)
    When I tested the same the output file is coming with LF.
    I tried by using the module "SAP XI Sample/ConvertCRLFfromToLF" which will convert from LFToCRLF.But it is serving my purpose.
    Can anyone please suggest how I can get the CRLF in the file while putting in the output directory which is in windows environment.
    Thanks
    Seema

    Do not mention endSeparator in content conversion parameters...by default XI puts newline as endSeparator
    It should work for NFS and FTP on Windows

  • Installed Photoshop cc 2014 asks for serial # - corrupted Windows file permissions

    More of a warning / heads up to all than a question - installing Photoshop cc 2014 [via the CC manager app] caused some Windows file (security) permissions to become corrupt corrupt on my system. Symptoms include cc2014 asking for serial number validation on startup (when, as a cloud version, it should not do so), then being unable to connect to the internet when you press the 'validate serial' button so getting that window into infinite loops, and - a real pain in the *** when trying to fix the above - causing abends of some windows shell functions that in turn cause windows explorer to crash and restart.
    Anyhow, digging into this (fortunately, I am a long time Windows SysProg) I discovered that for reasons unknown, either the CC master app or the actual Photoshop cc2014 installer (or both) are changing file access control permissions on a number of files, mostly DLL's. Most of the files affected are in the (normally hidden) Program Data directory on the windows root disk, Some of them are in the Adobe subdirectory - so fair enough if they want to fool around with their own program - but others being changed are in the Common Files and Microsoft subdirectories. I cannot for the life of me figure out why this is necessary nor why Adobe feel the need to touch files that 'do not belong' to them - something dangerous in the extreme as an external app such as Windows Update might replace or 'repair' the files so touched, and if Adobe / CC are relying on file permissions on non-Adobe files, such changes could result in all manner of random and spurious problems / error messages occurring.
    Anyhow, if, fellow Photoshop cc 2014 user, you get this happen to you then you can fix the file permissions by opening a console window [also called a "DOS box", or "command prompt" depending on your age and knowledge... 8-) ] and run the windows file checker with the command
    "sfc /scannow". Make sure that you use 'run as administrator' to open the console window, or you'll get an error about sfc only being available to administrators. Also a very (very) sensible idea to close all non-essential running applications first to prevent any possibility of weird interactions happening.
    Finally, check that the 'hosts' file in [root drive]:/Windows/System32/drivers/etc is valid - for some reason, it looks like the install tried to check or update this file (again, I have no idea why) but the result was a corrupted hosts file, which I assume is the root cause of the 'unable to connect to host' type internet error messages. Copy the file, rename it as 'hosts.txt' and edit it with notepad or wordpad. Look for lines containing garbage strings at the bottom of the file  (any line that starts with a # ignore, it is a comment, and any line that has IP addresses or host names should be ignored - though if they reference a site such as "someserver.adobe.com" you might want to treat them with suspicion if you continue to get internet 'cant connect to site' type errors.
    Anyhow, when I fixed these two sets of problems, Photoshop cc 2014 started 'right first time' without all the BS messages about serial numbers etc.
    Hope this helps somebody out there in AdobeLand......
    Rick

    Update: I tried several times to reproduce the error, actually it dosen't occur. I changed nothing on my system, without reboot it twice. This is what I said in my beginning times: it occurs sometimes but often. I will keep you up to date.

  • Windows 7 ignores file permissions for shared 10.5.8 folder

    I set up a shared folder on my Mac using SMB. I also set up an account with limited privileges (read only) for accessing it. The problem is that, while the Windows 7 computer needs the account password to access the folder, once it's accessed the file permissions are completely ignored, permitting to user to change and delete files at will.
    Any ideas on how to keep the folder Read-Only?

    When you enter the account's password, you are logging in to the Mac as that user, which is why everything is coming up as read + write.
    This article indicates that you have to provide the account name and password for SMB sharing:
    http://docs.info.apple.com/article.html?path=Mac/10.5/en/8201.html
    There's a special forum for Windows compatibility; you might want to search and/or post in there:
    http://discussions.apple.com/forum.jspa?forumID=687

  • Problem Assigning file permissions on windows client

    I have created some Users and Groups in the OD. I have several Windows PC's including Server 2003 installations. SMB is running and configured as "primary domain controller".
    When I browse the OD from the Windows client to assign file permissions I ONLY see the USERS, not the Groups. I have Groups and Users checked in the "Locations" sub dialog.
    ie. Right Click on folder to share, choose Sharing and Security, choose Permissions, choose Add, choose Advanced, choose Find. Same thing in the Security Tab. Same thing in the User manager.
    This also affects the logons. I don't want to have to add each user every time I want to share or give logon permissions on the Windows client. Adding a Group is much easier.
    Any suggestions?

    N'<national symbols>', being part of an SQL statement, will be converted to the database character set (WE8ISO8859P1) before being parsed. Only if the client and the database are both 10.2 or higher, the client can encode the literal appropriately so that it survives this conversion.
    In earlier versions, you can do the encoding yourself. Instead of the N'<national symbols>' literal use the UNISTR function: UNISTR('\xxxx\yyyy\zzzz'), where U+xxxx, U+yyyy, U+zzzz are Unicode code points of your national characters.
    -- Sergiusz

  • How to edit NTFS file permissions in Windows PE 3.0

    Does anyone know how to edit NTFS file permissions from Windows PE 3.0?

    Hello,
    The Windows Desktop Perfmon and Diagnostic tools forum is to discuss performance monitor (perfmon), resource monitor (resmon), and task manager, focusing on HOW-TO, Errors/Problems, and usage scenarios.
    Since your post is off-topic, I am moving it to the
    off topic forum.
    Karl
    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer.
    My Blog: Unlock PowerShell
    My Book:
    Windows PowerShell 2.0 Bible
    My E-mail: -join ('6F6C646B61726C406F75746C6F6F6B2E636F6D'-split'(?<=\G.{2})'|%{if($_){[char][int]"0x$_"}})

  • Why is it impossible to save a modified file since my computer is on Windows 8.1? What can I do?

    Why is it impossible to save a modified file since my computer is on Windows 8.1? What can I do?Photoshop Elements FAQ List

    It shows up as Drive :E.  I was able to copy my entire collection earlier on F drive.  But it would not copy just the pics I had selected.  I'll probably get it worked out before the next mililenium.  Thanks.  I'll keep on working on it. I'll yell again if I have a major operator error situation.  I really do want to be able to copy only selected photos though.  All I could find in the Editor tab was to Backup.  I really don't want to always copy my entire backup files.

  • File Permissions in windows XP

    ok im alittle stumped on this
    i need to give my application read\write access to %USERPROFILE%\\savedir
    now if i put it fully qualified
    i.e.
    permission java.io.FilePermission "C:\\Documents andSettings\\zaelld\\.saveDir", "read, write";
    it works fine
    by
    permission java.io.FilePermission "%USERPROFILE%\\.saveDir", "read, write";
    that should work as ide assume $HOME/.saveDir in linux would work fine(i havent tested that yet)
    and i ONLY want the program to have access to .saveDir
    any ideas? or have a missed something obvious:?

    well then i should have read the file permissions tutorial more carefully
    permission java.io.FilePermission "${user.home}\\.saveDir", "read, write";
    fixed

  • Fix downloaded files permissions on Windows 7

    Almost every time I download a file from various sources, Firefox adds a padlock to the downloaded file icon. This means that the file can only be accessed by the current user unless I change back the file permissions manually.
    Is there any way of stop the downloads from changing their file permissions? I've only noticed this happening for a week or so, currently I'm on Firefox beta 26.0

    You can try to set the browser.download.manager.scanWhenDone pref to false on the <b>about:config</b> page to prevent Firefox from adding zone identifier data to the downloaded files.
    See:
    *http://kb.mozillazine.org/Unable_to_save_or_download_files

  • Error/warning message "you don't have permission to modify files in this network location"

    Hi,
    We have a windows server 2008 running, and we access it via remote desktop. And there's this certain folder that all users access, and where we save important files. So, since this is where important files are stored, we wanted to disable deletion (and if
    possible moving) of the folder and everything under it. However, it's harder than i thought. Right now, we have the permissions "Delete" and "Delete files and subfolders" disabled already, BUT when we try to save a file to this folder,
    we got this warning/error message:
    "You don't have permission to modify files in this network location"
    The file is saved however, but there's no content. But when we try to cut/copy an existing file to this folder, it works.
    Does anyone know how a workaround on this issue. I've already spent days configuring the settings, and when one works, another issue comes up. This is really frustrating.
    Thank you.

    Hi,
    What are NTFS Permissions and Share Permissions of the shared folder? If you remove delete permissions, when someone tried to create a new folder, they couldn't rename it. Without Delete permission, we can open, modify a file and save with the same file name
    but cannot create a new file with a new name.
    For more detailed information, please refer to the thread below:
    NTFS Permissions Question - Allow creation but not deletion
    https://social.technet.microsoft.com/Forums/windowsserver/en-US/3335a9b3-d49a-42f0-970a-3fe44b551274/ntfs-permissions-question-allow-creation-but-not-deletion
    Best Regards,
    Mandy 
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Time Capsule file permissions

    Whenever I copy a file to the time capsule (either via finder by moving it there, or via terminal with cp) the file permissions of the file end up with -rwxrwxrwx, independently whether the file was an executable, or whether it only had reading permissions for all or group. Running chmod on the Time Capsule files has no effect.
    This is really silly and makes the Airport Disk sharing useless. This way I will never share files with my friends over the Airport disk because the files loose their property and all files are executables at the end.
    Is there a way to mount or configure the Time Capsule so that it conserves the file permissions?
    I am aware that time capsule cannot handle different users, but at least it should conserve the file permissions. I imagine it could be like a scp or ftp of files to another server. My files on the other server will not have my user name, but at least they conserve the file permissions. A -rw-r-r- file will still be a -rw-r-r- file even if I copy it 10 times from one server to another.
    I would lik to encourage Apple to take this problem seriously and provide an update for this issue. So many other Apple products are just so well integrated in a networking environment, even if it is a heterogeneous one, but not Time Capsule with this flaw.
    Best wishes,
    Reto

    Agree, this is a serious flaw, that makes the device very dangerous to use as a central server for shared files, for example, the family's photograph collection. Since there appears to be no way to write protect anything, how can I ensure the files don't get modified or deleted?
    Here's a nasty case I am seeing:
    We unload a digital camera onto the TC's disk, then someone goes to their iPhoto app, and adds these files to their iPhoto library. Then they do something simple, like rotate the photos, and voila! The master file on the TC has now been modified! Horrible.

Maybe you are looking for

  • Suppress dialog

    what is suppress dialog?

  • Oracle 8i: Problem with connectong trough firewall/connection manager

    Hello. i've been trying to make this work for I think 2 weeks now. with no luck. if I go around the firewall/connection manager. everything works fine. it runs on win xp. port 1521 and port 1630 has been forwarded. conn manager log: (TIMESTAMP=22-JUN

  • Dbms_xmlsave for update

    Hi, I'm using dbms_xmlsave for updating columns in a table with data in an XML file. This works only when the tags in XML file exact match the columnnames in the table. How can i do the same when the tagnames differ from the columnnames? Regards, Jos

  • Lightroom 5.5 identification of Sony A7 FE 28-70 mm lens with JPG

    Learning my new A7 camera with the FE 28-70 mm lens . Shot a number of pictures with Quality = Fine (Jpg). When imported into LR 5.5, in the Develop Module, and I select Enable Profile Correction and select Sony, the only option I am given for the ca

  • Locked out of pre purchased downloads

    No where in the agreement does it state that I have to have money in my account in order to recieve pre-purchase books and tv programs from iTunes. I paid for books via Audible.com but when I went to download them Itunes stated there was a problem wi