Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility for Windows 10/11 HOME editions #4

Open
brummbrum opened this issue Jun 18, 2022 · 7 comments
Open

Compatibility for Windows 10/11 HOME editions #4

brummbrum opened this issue Jun 18, 2022 · 7 comments

Comments

@brummbrum
Copy link

Thank you for sharing this tool! It looks perfect and works fine on Windows Pro/Enterprise Editions. For the latter I found one small issue in https://github.com/vasyaod/parental-control/blob/master/schedule-daemon/src/WindowsCommand.hs

The msg command requires '/TIME:10' rather than '/10'. At least on my test system the message would not be displayed otherwise.

A bigger problem would be Windows 10/11 HOME editions, which probably most children will run rather than a Pro or Enterprise Edition: The Windows commands 'query', 'msg' and 'logoff' do not exist in the HOME editions!

There may be ways to substitute them however. The substitutions should work with any edition of Windows, but are a little less powerful in that they only work with the current user (if multiple users are logged in the user with an active desktop is considered the current user):

Instead of 'query': Use 'wmic /node:localhost COMPUTERSYSTEM GET USERNAME'

Instead of 'logoff': Use 'shutdown /l'

Instead of 'msg': Use the vbs method shown here: https://superuser.com/questions/1278006/how-to-display-a-msgbox-directly-from-cmd. Message file can obviously be stored as part of the parental control as it is a static message

Any chance to make this work?

@vasyaod
Copy link
Owner

vasyaod commented Jun 19, 2022

I've created PR (#5) for that but I expect some issues for example

The program is being running as "system service/daemon" and shutdown /l can't kill needed user but exactly service... behavior of the command should be investigated.

The same situation with 'wmic COMPUTERSYSTEM GET USERNAME'.

Please, can you check correctness of windows-home version by link
https://github.com/vasyaod/parental-control/actions/runs/2522190413#artifacts
or
https://github.com/vasyaod/parental-control/suites/6992656757/artifacts/273905564

@brummbrum
Copy link
Author

brummbrum commented Jun 19, 2022

Yeah, I was already kind of worried about that. Home edition sucks - but it is what most children will be running. I have seen a bunch of posts where parents are looking for a solution like yours who do not want to use the built in Family functionality which requires MS accounts.

Maybe it requires to either
a) find a PowerShell command that list users similar to 'query' (a cursory search revealed this is possible but ridiculously complicated)
b) launch the program under the user account (at logon) rather than as system service?

Will test this tonight on a VM running Windows Home Edition and report back.

PS: I see you already found a much better solution for the message box than the vbs method. Nice.

@brummbrum
Copy link
Author

Here come the results of my testing.

The good news:
'wmic /node:localhost COMPUTERSYSTEM GET USERNAME' actually works nicely! Time recording works properly while a specific user is "active", i.e. running a desktop (I assume explorer.exe is the criteria behind the scenes). I.e. this may be even better than 'query' because "dormant" users are not getting punished with screen time counting.

The bad news:
'shutdown /l' does nothing when executed from system service. Probably because the system cannot log out - haha. I then tried to change the source code to execute 'shutdown /s /t 60" hoping this would work from a system level. Rebuilt the exe files with stack. I ran those directly (did not wrap them in a service) under a different admin account. This was useful to also watch the output (boolean flags per user) which confirms that wmic ... indeed works nicely. However, the system would not shutdown as expected even when all flags turned true. No idea why.

'PowerShell -Command "Add-Type -AssemblyName PresentationFramework;[System.Windows.MessageBox]::Show('User will be killed in a few minutes')"' as picked up from the config works - but it will only show the message on the desktop of the user who is running parental-control-exe. I saw this in the above situation running the exe directly from another admin account: The user which would exceed the allotted time did not receive the message box. Instead the message box pops up at the user who runs the parental-control-exe process. Another observation: Until the message is confirmed by clicking "OK" the flag for message sent will not change to true. Also, the time counting stops for that user.

@vasyaod
Copy link
Owner

vasyaod commented Jun 19, 2022

Yeah, i've checked shutdown /l too... and it doesn't work too
but there is a option like
runas /user:{someuser} shutdown /l

and I'm gona that

@vasyaod
Copy link
Owner

vasyaod commented Jun 19, 2022

'PowerShell -Command "Add-Type -AssemblyName PresentationFramework;[System.Windows.MessageBox]::Show('User will be killed in a few minutes')"' as picked up from the config works - but it will only show the message on the desktop of the user who is running parental-control-exe. I saw this in the above situation running the exe directly from another admin account: The user which would exceed the allotted time did not receive the message box. Instead the message box pops up at the user who runs the parental-control-exe process. Another observation: Until the message is confirmed by clicking "OK" the flag for message sent will not change to true. Also, the time counting stops for that user.

Good catch! Thanks

@brummbrum
Copy link
Author

Yeah, i've checked shutdown /l too... and it doesn't work too but there is a option like runas /user:{someuser} shutdown /l

and I'm gona that

Hmmm, this crossed my mind too but I'm skeptical it can work: How to deal with the user password? Impersonation seems to be possible from a system service but extremely complex in Windows (it is made almost impossible by design for security and audit reasons - even the admin cannot impersonate a normal user). This is why I tried to shutdown the machine via 'shutdown /s'. While it is brutal it would be acceptable from my perspective. I do not understand why it did not work in my first attempt. One would think that the local system has the privilege to shutdown the local machine.

However, there is another problem with running parental-control as a system service in Windows Home: Any interaction with the currently active user via UI like the message box will be impossible. Upon further reading I understood that system services run as session Id 0 in Windows, whereas all users run in sessions 1, 2, .. etc. It is impossible to interact from session 0 to any other session via UI - they are completely isolated. For that reason I added 'shutdown /s /t 60' as this creates a system wide pop up for any user announcing that the system will shut down in 60 seconds. One can even add a custom text by adding e.g. '/c "Time is Up!"'. But as stated above this did not yet work for some strange reason (maybe the service needs to be launched somehow differently to be allowed to do that).

The other strategy would be to not run parental control as a service under Windows Home. Rather launch it as the current user upon logon (aka startup items). Then both 'shutdown /l' as well as the message box should work.

@brummbrum
Copy link
Author

gave it another test running under user account. As expected, logoff via 'shutdowjn /l' and message box both work. Should be straight forward as a startup item. I also tested that it can be started hidden with a vbs script:

Set Shell = CreateObject("WScript.Shell")
Shell.Run """Path to command parental-control.exe""", 0, False

The only thing that is missing would be to have the message box sitting always on top (maybe something in the PowerShell command?) and the counting bug fixed, i.e. not waiting to confirm the message via ok button. From my point of view that would fit the bill for Windows Home. Obviously the system service is somewhat nicer and consistent with the Linux an Win Pro philosophy. But at least with my limited understanding I do not see a straight forward way under Home Edition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants