Closed Obegg closed 8 months ago
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...
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).
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
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.
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
More information about the renaming folders issue: Before running Sophia Script 5.18.2 = No Issues. After running Sophia Script 5.18.2:
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.
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.
Yes, so finally debugged the issues. Here's an update.
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
.
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:
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.
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.
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: Works fine, no issues setting up a scheduled task.
All I did now is rename the PC: And restarted the PC to changes to apply.
Now I tried the same scheduled task: Doesn't work anymore.
Conclusion: Rename the PC is causing the task scheduler issue.
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:
Second - just to show I created a new folder and renamed it Test folder in desktop:
Third - Run powershell as admin and run only the selected lines: Now I restart the PC.
Downloads folder still visible:
And can't rename the Test folder:
Conclusion: function UserFolders -Downloads hide
is causing is renaming folder issue.
🤔
What?
Thinking out how to fix)
Same, even though I hope there are other solutions.
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.-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?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.
But hey... at least now you know why some users have issues with task scheduler and some users don't have issues :)
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. :)
The command is in the screenshot in one of the reply above, rename-computer -newname
Conclusion: Rename the PC is causing the task scheduler issue.
Confirm. WTF
or make the script check if the PC has been renamed (how?)
Due to many functions uses Register-ScheduledTask
, I want to leave exit
.
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.
-UserId "$env:computername\$env:USERNAME"
Works fine.
I will test)
Prerequisites
Steps to reproduce
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.
(Get-Content Module\Sophia.psm1) -replace 'Register-ScheduledTask @Parameters -Force -ErrorAction Stop', '#' | Set-Content Module\Sophia.psm1
(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