Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: a stranger behavior on Vista/Windows 2008  (Read 3119 times)

0 Members and 1 Guest are viewing this topic.

qliao

    Topic Starter


    Greenhorn

    a stranger behavior on Vista/Windows 2008
    « on: April 23, 2008, 04:21:54 PM »
    Hello,

    I am encountering a strange behavior with prgram files folder on Vista/Windows 2008 when running as non-admin. My code is to check if a folder/path exists. Here is what it is:
    try {
        File f1 = new File("C:\abc"); 
        if (!f1.exists()) { return -1;}
        if (!f.canWrite()) { return -1;}

        File f2 = new File("C:\Program Files\Data"); // this folder doesn't exist
        if (!f1.exists()) { return -2;}
        if (!f.canWrite()) { return -2;}
        return 0;
    }catch(Exception e) {e.printstacktrace();}

    Logged in non-admin account, the first block of code for f1 behaves well, if that folder doesn't exist, it'll return -1. However if f1 exists but f2 doesn't exist, the condition checking for f2 got passed and returns 0!!

    Running as admin, it works normal.  Has anyone seen this before and how to solve the problem?

    Thank you very much in advance.

    Regards,
    Jan

    qliao

      Topic Starter


      Greenhorn

      Re: a stranger behavior on Vista/Windows 2008
      « Reply #1 on: April 23, 2008, 05:33:02 PM »
      Forgot to mention: Data folder under Program Files was created before, then renamed to abcData, running as admin account would return non-exist for "Data" folder, but non-admin would return exist!

      patio

      • Moderator


      • Genius
      • Maud' Dib
      • Thanked: 1769
        • Yes
      • Experience: Beginner
      • OS: Windows 7
      Re: a stranger behavior on Vista/Windows 2008
      « Reply #2 on: April 23, 2008, 06:49:47 PM »
      If any file/folder has changes to it made in the Admin account unless you allow that file permissions for all or other accounts it is as if that file no longer exists in any user account...

      What is it you are trying to do ? ?
      " Anyone who goes to a psychiatrist should have his head examined. "

      qliao

        Topic Starter


        Greenhorn

        Re: a stranger behavior on Vista/Windows 2008
        « Reply #3 on: April 24, 2008, 07:31:53 AM »
        Hi, thank you very much for the attention and reply.

        What I'm trying to do here is to test if C:\Program Files\Data folder exists, if yes, then do something; otherwise just exit.. This way it'll avoid a crash if that folder doesn't exist.

        Our installer is suppsed to install Data folder there, so normally the folder should be there. However it happens if someone renames it or delete it, we need to test the existency of the Data folder...

        Now if I renamed Data folder to abcData or Data_ (its name still contains "Data") running as admin would tell us Data folder doesn't exist, which is correct; however running as non-admin would tell us Data folder exists! which is wrong, and there is no exception thrown.   But if renamed Data folder to something like "sdflsd", and both non-admin & admin would tell us Data folder doesn't exist - correct..

        Wondering if there is a software bug...

        patio

        • Moderator


        • Genius
        • Maud' Dib
        • Thanked: 1769
          • Yes
        • Experience: Beginner
        • OS: Windows 7
        Re: a stranger behavior on Vista/Windows 2008
        « Reply #4 on: April 24, 2008, 03:47:34 PM »
        Can you change the path of the Data folder in the program...in other words have it write the data to C:\Data folder ? ?
        " Anyone who goes to a psychiatrist should have his head examined. "