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

VERBOSE: Task Scheduler broken or removed from Windows. #561

Closed
5 of 6 tasks
Obegg opened this issue Mar 21, 2024 · 30 comments
Closed
5 of 6 tasks

VERBOSE: Task Scheduler broken or removed from Windows. #561

Obegg opened this issue Mar 21, 2024 · 30 comments

Comments

@Obegg
Copy link

Obegg commented Mar 21, 2024

Prerequisites

  • Verify that this is not a Windows issue;
  • Refer to the system requirements;
  • Refer to the How to use;
  • I do not use a homebrew Windows image;
  • I did not tweak Windows before that could cause system instability;
  • If your issue concerns the Wrapper, please mention @BenchTweakGaming in issue

Steps to reproduce

  1. Download Sophia Script:
iwr script.sophia.team -useb | iex
  1. Run Sophia Script.
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force
.\Sophia.ps1
  1. Result:

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     5.18.2     Sophia                              {ActiveHours, AdminApprovalMode, AdvertisingID, AeroShakin...

Edition : EnterpriseS

VERBOSE: GET https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/sophia_script_versions.json with
 0-byte payload
VERBOSE: received 374-byte response of content type text/plain; charset=utf-8
VERBOSE: GET https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/supported_windows_builds.json
with 0-byte payload
VERBOSE: received 115-byte response of content type text/plain; charset=utf-8

VERBOSE: Please wait...

VERBOSE: GET https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra.txt with 0-byte
payload
VERBOSE: received 15517-byte response of content type text/plain; charset=utf-8
VERBOSE: GET https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra_v6.txt with 0-byte
payload
VERBOSE: received 13522-byte response of content type text/plain; charset=utf-8
VERBOSE: GET https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt with 0-byte
payload
VERBOSE: received 12383-byte response of content type text/plain; charset=utf-8
VERBOSE: GET https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy_v6.txt with 0-byte
payload
VERBOSE: received 10653-byte response of content type text/plain; charset=utf-8
VERBOSE: GET https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update.txt with 0-byte
payload
VERBOSE: received 21459-byte response of content type text/plain; charset=utf-8
VERBOSE: GET https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update_v6.txt with 0-byte
payload
VERBOSE: received 18769-byte response of content type text/plain; charset=utf-8

VERBOSE: Please wait...

VERBOSE: Task Scheduler broken or removed from Windows.

This is a fresh install of Windows after installing all updates from windows updates.

Versions 5.18.1 and 5.18.2 are buggy.
I have tried overriding the Task Scheduler broken issue by using the following command:

(Get-Content Module\Sophia.psm1) -replace 'Register-ScheduledTask @Parameters -Force -ErrorAction Stop', '#'  | Set-Content Module\Sophia.psm1

And I couldn't renamed folders on my PC anymore.

Version 5.18.0 is working, but only if I override the version check by using the following command:

(Get-Content Module\Sophia.psm1) -replace 'https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/sophia_script_versions.json', '#' | Set-Content Module\Sophia.psm1

Which is another issue by itself - if the newer version is buggy, why can't I use older version?

Took my 2 days to diagnose this issue.

Windows Version

Windows 10 Iot Enterprise LTSC 2021

Sophia Script version

5.18.2

@farag2
Copy link
Owner

farag2 commented Mar 22, 2024

I have tried overriding the Task Scheduler broken issue by using the following command:

You mustn't change any code if you do not understand why you encounter with this error.

And I couldn't renamed folders on my PC anymore.

"Very" informative. No ((

Which is another issue by itself - if the newer version is buggy, why can't I use older version?

Because, firstly, the new version is not buggy, neither the old one does. Secondly, this is not a script issue, but a Windows one (really)!

Let's check

$Action     = New-ScheduledTaskAction -Execute powershell.exe
$Settings   = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable
$Principal  = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest
$Parameters = @{
	TaskName    = "SophiaTempScheduledTask"
	Principal   = $Principal
	Action      = $Action
	Settings    = $Settings
}
Register-ScheduledTask @Parameters -Force -ErrorAction Stop

Run this code as admin, and let's see whether a temp schedule task will be created. The problem is in Windows username I guess. I encounter 3 time with such issue. No workaround we have found. Just something goes wrong, and Windows is unable to create a simliest task. That's all we know. I mean, try to re-install or something else, but the script won't work for your, that's why I put an exception, and you tried to bypass it for the unknwon reason.

Took my 2 days to diagnose this issue.

Instead of just asking me by any way...

@farag2 farag2 closed this as completed Mar 22, 2024
@farag2
Copy link
Owner

farag2 commented Mar 22, 2024

# Register a temp schedule task to check whether there's a Windows bug presented

@Obegg
Copy link
Author

Obegg commented Mar 22, 2024

You mustn't change any code if you do not understand why you encounter with this error.

I did understand (after a while), that's why I changed it. It registers a temporary scheduled task just to check if there's any issues with it and if it detects it has issues then it will stop the entire script (which is not really a good solution because the task scheluder only being used with CleanupTask and SoftwareDistributionTask and TempTask, which probably won't work has is been a problem for a while or will be disabled by the user either way).

"Very" informative. No ((

What? I'm serious here, I have no more information other then before running the script I could rename folders on my PC and after running the script and restarting the PC I couldn't rename folders anymore, Windows would error saying "the path doesn't exist".
Why are you being dismissive here? I'm reporting an issue.
Even after overriding this first error - there's issue with the code, Windows will let me create folders but not rename them.
I now 100% certain the "Code refactoring" that was done in 5.18.1 led to this issue.
https://github.com/farag2/Sophia-Script-for-Windows/blob/master/CHANGELOG.md#5181--661--03032024

Run this code

Forget that code, something is wrong with this specific code and I don't want to debug it now after the long time I already tried to....
I have my own scripts for creating a task (not a temporary one) in task scheduler and it successfully adds them, the issue is with this specific code and I guess it's the Win8 bit.

Instead of just asking me by any way...

Well, it was a fresh install of Windows so.... I had no really way of communicating, so all I did was try a fresh install after a fresh install after a fresh install (hoping this would solve the issue because I really did start to believe my Windows install is broken - which is not).

@Obegg
Copy link
Author

Obegg commented Mar 22, 2024

Here, tested this bit:

$Action     = New-ScheduledTaskAction -Execute powershell.exe
$Settings   = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable
$Parameters = @{
	TaskName    = "SophiaTempScheduledTask"
	Action      = $Action
	Settings    = $Settings
}
Register-ScheduledTask @Parameters -Force -ErrorAction Stop

working fine without:

$Principal  = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest

and without:

Principal   = $Principal

@Obegg
Copy link
Author

Obegg commented Mar 22, 2024

Another thing to note, I have a script that will rename my PC to the username, exactly the variable you are using!
$env:USERNAME
guess what? there's no issue running:

Rename-Computer -NewName $env:username

The issue is with -UserId on $Principal, then just get rid of it.

@Obegg
Copy link
Author

Obegg commented Mar 22, 2024

So you might argue that you want the -RunLevel Highest to run as Admin, so here:
Instead of

$Principal  = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest

Use

$Principal  = New-ScheduledTaskPrincipal -GroupId BUILTIN\Administrators -RunLevel Highest

@Obegg
Copy link
Author

Obegg commented Mar 22, 2024

More information about the renaming folders issue:
Before running Sophia Script 5.18.2 = No Issues.
After running Sophia Script 5.18.2:
1
2

@farag2
Copy link
Owner

farag2 commented Mar 22, 2024

After running Sophia Script 5.18.2:

You didn't run it. The script was terminated. Also, there's no such code to break anything, This is not the script fault at all.

@Obegg
Copy link
Author

Obegg commented Mar 22, 2024

I'm testing it now, I will update you on any progress.

In the meantime I found a solution for the ScheduledTaskPrincipal issue:
Replace "Module\Sophia.psm1" all matching
From:
-UserId $env:USERNAME -RunLevel Highest
To:
-GroupId BUILTIN\Administrators -RunLevel Highest

This has fixed my issues with task scheduler.

@Obegg
Copy link
Author

Obegg commented Mar 22, 2024

Yes, so finally debugged the issues.
Here's an update.

  1. Task scheduler issue:
    VERBOSE: Task Scheduler broken or removed from Windows.
    Fixed by opening the file Module\Sophia.psm1 and changing every -UserId $env:USERNAME -RunLevel Highest to -GroupId BUILTIN\Administrators -RunLevel Highest.

  2. Renaming folders issue:
    This is caused by UserFolders function, you can easily reproduce this issue by using:

(Get-Content Sophia.ps1) -replace '# UserFolders -ThreeDObjects Hide -Desktop Hide -Documents Hide -Downloads Hide -Music Hide -Pictures Hide -Videos Hide', 'UserFolders -ThreeDObjects Hide -Desktop Hide -Documents Hide -Downloads Hide -Music Hide -Pictures Hide -Videos Hide' | Set-Content Sophia.ps1

(This basically just hides every user folder)
Furthermore, the Downloads folder still visible even after the function:
image

@farag2
Copy link
Owner

farag2 commented Mar 22, 2024

GroupId BUILTIN\Administrators -RunLevel Highest.

You mustn't use a built-in group, but $env:USERNAME only. so this is not a workaround unfortunately

Renaming folders issue:

Will check on Sunday.

@Obegg
Copy link
Author

Obegg commented Mar 22, 2024

You mustn't use a built-in group

Can you explain why?
I've tested it on built-in group and run the scheduled task and there were no issues with this approach.
I allowed Sophia Script to add the tasks as built-in group, when it finished I manually open task scheduler and changed the task to run 1 minute ahead of the system clock, it was running and cleaned my TEMP folder and showed me a notification, so regarding if it works or not - it works.

@Obegg
Copy link
Author

Obegg commented Mar 23, 2024

I have tested it a bit more now and I have some additional information to share with you.

Fresh Install of Windows (after Windows Updates).
Testing out task scheduler issue:
Before Setting Up Username
Works fine, no issues setting up a scheduled task.

All I did now is rename the PC:
Setting Up Username
And restarted the PC to changes to apply.

Now I tried the same scheduled task:
After Setting Up Username
Doesn't work anymore.

Conclusion: Rename the PC is causing the task scheduler issue.

@Obegg
Copy link
Author

Obegg commented Mar 23, 2024

I have tested it a bit more now and I have some additional information to share with you.

Fresh Install of Windows (after Windows Updates).
Testing out renaming folders issue:
https://github.com/farag2/Sophia-Script-for-Windows/blob/master/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1#L2840C6-L2867C5

if (-not (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{374DE290-123F-4565-9164-39C4925E467B}"))
					{
						New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{374DE290-123F-4565-9164-39C4925E467B}" -Force
					}
					if (-not (Test-Path -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{374DE290-123F-4565-9164-39C4925E467B}"))
					{
						New-Item -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{374DE290-123F-4565-9164-39C4925E467B}" -Force
					}
					if (-not (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{088e3905-0323-4b02-9826-5d99428e115f}"))
					{
						New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{088e3905-0323-4b02-9826-5d99428e115f}" -Force
					}
					if (-not (Test-Path -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{088e3905-0323-4b02-9826-5d99428e115f}"))
					{
						New-Item -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{088e3905-0323-4b02-9826-5d99428e115f}" -Force
					}

					if (-not (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{7d83ee9b-2244-4e70-b1f5-5404642af1e4}\PropertyBag"))
					{
						New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{7d83ee9b-2244-4e70-b1f5-5404642af1e4}\PropertyBag" -Force
					}
					if (-not (Test-Path -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{7d83ee9b-2244-4e70-b1f5-5404642af1e4}\PropertyBag"))
					{
						New-Item -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{7d83ee9b-2244-4e70-b1f5-5404642af1e4}\PropertyBag" -Force
					}
					New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{7d83ee9b-2244-4e70-b1f5-5404642af1e4}\PropertyBag" -Name ThisPCPolicy -PropertyType String -Value Hide -Force
					New-ItemProperty -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{7d83ee9b-2244-4e70-b1f5-5404642af1e4}\PropertyBag" -Name ThisPCPolicy -PropertyType String -Value Hide -Force
				

So first of all - just to show there is the downloads user folder visible:
1

Second - just to show I created a new folder and renamed it Test folder in desktop:
2

Third - Run powershell as admin and run only the selected lines:
3
Now I restart the PC.

Downloads folder still visible:
5

And can't rename the Test folder:
6
7

Conclusion: function UserFolders -Downloads hide is causing is renaming folder issue.

@farag2 farag2 reopened this Mar 23, 2024
@farag2
Copy link
Owner

farag2 commented Mar 24, 2024

🤔

@Obegg
Copy link
Author

Obegg commented Mar 24, 2024

What?

@farag2
Copy link
Owner

farag2 commented Mar 24, 2024

Thinking out how to fix)

@Obegg
Copy link
Author

Obegg commented Mar 24, 2024

Same, even though I hope there are other solutions.

  1. UserFolders -Downloads Issue: Simply revert back the changes from 3 weeks ago, luckily we have "blame",
    reverting the entire commit would be a bit an issue, so I would just suggest to remove what has been added in this specific lines.
  2. Task Scheduler Issue: Either use a group instead of a -userid or... give up entirely on this feature? or find some super rare issue on google on how to fix it? or make the script check if the PC has been renamed (how?) and it is then don't use the task schedule option, otherwise - continue normally?

@farag2
Copy link
Owner

farag2 commented Mar 24, 2024

  1. Yeah, something is wrong in the code.
  2. We need to use username only. I gave up isolating the Windows bug. Easier will be just to exit.

@Obegg
Copy link
Author

Obegg commented Mar 24, 2024

We need to use username only.

Why though?
What will happen if you use group?

Easier will be just to exit.

That's true, but also kind of... ignoring the issue?
Either way - can't argue with the fact that it's easier to exit instead of error out.

@Obegg
Copy link
Author

Obegg commented Mar 24, 2024

But hey... at least now you know why some users have issues with task scheduler and some users don't have issues :)

@farag2
Copy link
Owner

farag2 commented Mar 24, 2024

But hey... at least now you know why some users have issues with task scheduler and some users don't have issues :)

Once again how to repro the issue on a VM? My pal a year ago didn't rename his PC, as I understodd you correctly. :)

@Obegg
Copy link
Author

Obegg commented Mar 24, 2024

The command is in the screenshot in one of the reply above, rename-computer -newname

farag2 added a commit that referenced this issue Mar 26, 2024
@farag2
Copy link
Owner

farag2 commented Mar 26, 2024

Conclusion: Rename the PC is causing the task scheduler issue.

Confirm. WTF

@farag2
Copy link
Owner

farag2 commented Mar 26, 2024

@farag2
Copy link
Owner

farag2 commented Mar 26, 2024

or make the script check if the PC has been renamed (how?)

Due to many functions uses Register-ScheduledTask, I want to leave exit.

@Obegg
Copy link
Author

Obegg commented Mar 26, 2024

Confirm. WTF

HAHAHHAA LOL, indeed "WTF"

Regarding the issue opened - wow I did not know there was a github page for powershell, nice to know. don't know what's the ETA for a fix tho... also don't know about when Win10 will get the updated fix (before win11 or at the same time?), so we'll see..,

many functions

As far as I remember - only the first check (this reported issue) and the 4 scheduled tasks (clean up tasks) are using it.
Either way - a exit is a viable solution.

@Obegg
Copy link
Author

Obegg commented Mar 30, 2024

-UserId "$env:computername\$env:USERNAME"

Works fine.

@farag2
Copy link
Owner

farag2 commented Mar 30, 2024

I will test)

@farag2
Copy link
Owner

farag2 commented Mar 31, 2024

a18ab5c

@farag2 farag2 closed this as completed Mar 31, 2024
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