FelixdelasPozas / TrayWeather

Tray Weather is a simple application to retrieve and show weather information for a given geographic location in a small dialog and in the Windows OS system tray.
GNU General Public License v3.0
191 stars 22 forks source link

Every auto start TW cannot read settings #166

Closed henrypp closed 4 months ago

henrypp commented 4 months ago

sshot-001

required pressing Cancel and rerun app

it is QT cannot read settings or what?

FelixdelasPozas commented 4 months ago

Hi @henrypp .

I'll need more details. I suppose that you have enabled "Autostart on login" and when the program starts it cannot read the settings. Then you need to exit the app. When restarting it the app can read the settings without problems. Is it right?

Regards, Félix.

henrypp commented 4 months ago

ofc, portable, latest (1.29.1)

FelixdelasPozas commented 4 months ago

Looking the code I cannot locate any related issue. Since that version was released months ago and no one reported such an error I'm inclined to think the problem is with your machine.

Maybe you installed the portable version in a "protected" system directory? (like a "Program Files" child dir) Programs there must use the registry (or the user "appdata" dir) because it cannot write in that directory without admin permissions, so the configuration will never be written to the ini configuration file. If that is the case the problem will solve deleting the ini file in that directory, forcing the app to use the registry. Or moving the folder to a parent that is not protected by the OS.

I'll look into adding some code to warn the user if the ini file can't be updated. It looks like that is the problem. Please take a look. Edit: Or adding code to move/create the ini file to the user application data directory.

henrypp commented 4 months ago

program located even not in C: disk, but D: (whatever), so there is no reason to prevent read settings

FelixdelasPozas commented 4 months ago

program located even not in C: disk, but D: (whatever), so there is no reason to prevent read settings

I have a "Program Files" in D drive and is also read only (as shown if you click "Properties" in the context menu) so disk drive is no really relevant. Just look if the directory you've installed the app is "read only" according to OS.

You can test that for example moving the TW installation directory to "Downloads" dir of your user dir. And check if the dir is read-only there (i don't really remember, but it can be inherited from the old parent?). If the app starts without problem that's whats happening.

henrypp commented 4 months ago

@microsoft as always, implement "features" with no logic (like in 24h2 adds "Digital signatures" for ALL files even with no signature, and i check right now all folders (not files) in "Properies" have RO attribute, not idiotic?), i do not know when it started (only Signatures starts on 24h2 i know)

FelixdelasPozas commented 4 months ago

Well, that solves it. Make sure that in the portable version the directory is writable by the app. In the next version I'll add a check to make sure that the info is being written or a warning dialog will be shown to the user.

henrypp commented 4 months ago

it is NOTHING solves, i only described idiotic M$ decisions, TrayWeather.ini is NOT read-obly at all, anyway why is that read-only attribure prevents reads this file at startup? a?

FelixdelasPozas commented 4 months ago

it is NOTHING solves, i only described idiotic M$ decisions, TrayWeather.ini is NOT read-obly at all, anyway why is that read-only attribure prevents reads this file at startup? a?

The first time you started TW you entered the coordinates and other options, as normal. The info couldn't be written (but TW didn't warn you) so the file TrayWeather.ini remained with size 0. The next time the app starts it cannot read any info because there is nothing to read.

The problem of read-only is not reading, it's that you cannot modify/update the file. If the folder is read-only, any file inside cannot be modified, remove the read-only attribute in the folder.

henrypp commented 4 months ago

first time you see in picture of this topic what displayed/happened

henrypp commented 4 months ago

i checked what directory and trayweatyher.ini are writeable:

_Success_ (NT_SUCCESS (return))
NTSTATUS querytokeninformation (
    _In_ HANDLE token_handle,
    _In_ TOKEN_INFORMATION_CLASS token_class,
    _Out_ PVOID_PTR token_info
)
{
    PVOID buffer;
    ULONG buffer_length = 128;
    ULONG return_length;
    NTSTATUS status;

    buffer = HeapAlloc (GetProcessHeap (), HEAP_GENERATE_EXCEPTIONS | HEAP_ZERO_MEMORY, buffer_length);

    status = NtQueryInformationToken (token_handle, token_class, buffer, buffer_length, &return_length);

    if (status == STATUS_BUFFER_OVERFLOW || status == STATUS_BUFFER_TOO_SMALL)
    {
        buffer_length = return_length;
        buffer = HeapReAlloc (GetProcessHeap (), HEAP_GENERATE_EXCEPTIONS | HEAP_ZERO_MEMORY, buffer, buffer_length);

        status = NtQueryInformationToken (token_handle, token_class, buffer, buffer_length, &return_length);
    }

    if (NT_SUCCESS (status))
    {
        *token_info = buffer;
    }
    else
    {
        *token_info = NULL;

        HeapFree (GetProcessHeap (), 0, buffer);
    }

    return status;
}

BOOLEAN issecurelocation (
    _In_ LPCWSTR file_path
)
{
    PSECURITY_DESCRIPTOR security_descriptor;
    PACCESS_ALLOWED_ACE ace = {0};
    PTOKEN_USER token_user = NULL;
    PSID current_user_sid;
    PACL dacl = NULL;
    BOOLEAN is_writeable = FALSE;
    NTSTATUS status;

    status = GetNamedSecurityInfoW (file_path, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, NULL, NULL, &dacl, NULL, &security_descriptor);

    if (status != ERROR_SUCCESS)
        return FALSE;

    if (!dacl)
    {
        is_writeable = TRUE;
    }
    else
    {
        querytokeninformation (NtCurrentProcessToken (), TokenUser, &token_user); // win8.1+

        current_user_sid = token_user->User.Sid;

        for (WORD ace_index = 0; ace_index < dacl->AceCount; ace_index++)
        {
            status = RtlGetAce (dacl, ace_index, &ace);

            if (!NT_SUCCESS (status))
                continue;

            if (ace->Header.AceType != ACCESS_ALLOWED_ACE_TYPE)
                continue;

            if (RtlEqualSid (&ace->SidStart, &SeAuthenticatedUserSid) || RtlEqualSid (&ace->SidStart, current_user_sid))
            {
                if (ace->Mask & (DELETE | ACTRL_FILE_WRITE_ATTRIB | SYNCHRONIZE | READ_CONTROL))
                {
                    is_writeable = TRUE;

                    break;
                }
            }
        }
    }

    LocalFree (security_descriptor);

    return !is_writeable;
}
henrypp commented 4 months ago

hmmm, like i say, another idiotic M$ decision with complete no logic:

sshot-001

FelixdelasPozas commented 4 months ago

Well, in your last picture you can see "Read-only (Only applies to files in folder)" in the folder containing the application. So that's definitely the problem. I suppose you can uncheck that checkbox and the app will work as intended. I'll close the issue for the moment.

In the next release I'll add a check to see if the file "TrayWeather.ini" can be written and warn the user.

Regards, Félix.

henrypp commented 4 months ago

it is not a SOLUTION at all, because it is read only on ALL directories on win11 24h2 (do not know why, but it is), but ini file is writeable, where is the problem?

henrypp commented 4 months ago

and when i uncheck RO and apply , directory is still RO

FelixdelasPozas commented 4 months ago

That's an OS problem with Win 11 24H2. In my version...

Edición Windows 11 Pro
Versión 23H2
Instalado el    ‎05/‎05/‎2023
Versión del sistema operativo   22631.3810
Experiencia Windows Feature Experience Pack 1000.22700.1020.0

I have not such problem.

In your case I would try:

You're probably having this kind of problem with any other "portable" application in your system. Portable applications need to save the information in it's own folder.

If the problem persists I would check for viruses/malware/rootkits. It's not normal that the user in Windows (that can access admin privileges very easily) cannot change the permissions in folder he/she has created and is the owner.

Edit: Apparently Win11 24H2 is still in "insider" channel as a preview version. Can have bugs...

henrypp commented 4 months ago

no viruses/rootkits or whatever, not any file in folder does have RO attribute, but folder is still display as RO, i checked it by enumerate and ini file does not have RO

FelixdelasPozas commented 4 months ago

no viruses/rootkits or whatever, not any file in folder does have RO attribute, but folder is still display as RO, i checked it by enumerate and ini file does not have RO

If the folder has RO doesn't matter if the file attributes has it. Cannot be written.

Edit: It can be if the application modifying it has admin privileges, to be more precise.

henrypp commented 4 months ago

easier complete rewrite this tool in C without any QT which is does not needed, it easier

FelixdelasPozas commented 4 months ago

easier complete rewrite this tool in C without any QT which is does not needed, it easier

It's open source for a reason. Be my guest 😀