-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
Issues running SetResolution.exe as a scheduled task. #11
Comments
Nabu, I'm successfully using this as a scheduled task for a project. What is your task's trigger? If it is upon user login, you will want to add a sleep/delay for a couple of seconds -- the task tries to run instantly before the GUI is fully rendered, and thus fails. I'm hoping to suggest a fix to handle this scenario more gracefully, but that is a functional workaround. |
Thanks for getting back to me!
I've tried a couple different methods, primarily with the executable you've released. (I'd tried using the .Net tool as well - but the tool didn't seem to stay loaded. Likely more due to a quirk that occurs with using the system account.) With the executable, I'd tried both using the system account as well as a locally created account (set up as an administrator). And, I confess, I can't claim to be a programmer myself, just some scripting - typically using powershell. I was actually attempting to set the resolution at both startup and after login. In both cases, I am setting a delay, though I used a random timer of up to 30 seconds. (Originally, I was planning on doing so only at startup and when that wasn't working well for me, I also added logon to cover my bases.)
In our case, we're trying to automatically set the refresh rate on several computers that we have. (I'm part of the technology group at Duval County Public Schools, in Jacksonville FL. We have several, 'Interactive Monitors' for classrooms. Basically it's a small form factor Lenovo computer strapped to the back of a TV. Occasionally, the display is having trouble syncing with the actual computer. In playing around with things, it seems that they get along much better so long as the refresh rate is set to 29 Hz, but the computers like to negotiate automatically to 30 Hz. Typically we're setting the display to use 4K resolution, but in testing, I was actually setting a lower resolution (so I could test on other devices in the meantime).
This is the scheduled task portion of the script - in this case I'm using the user account that I'd created. (As time went on, I tried to 'simply' things - so I stopped using the system account and also stopped using environmental variables like %ProgramFiles% in case that was causing part of my trouble).
#Generate Scheduled Task
#Call the setresolution dotnet tool and provide the resolution and refresh rate needed
#$Action = New-ScheduledTaskAction -Execute '"C:\Program Files\SetResolution\SetREsolution.exe"' -WorkingDirectory "C:\Program Files\SetResolution" -Argument "SET -w 3840 -h 2160 -f 29 -noprompt"
#$Action = New-ScheduledTaskAction -Execute CMD.EXE -Argument '/C "C:\Program Files\SetResolution\SetREsolution.exe" SET -w 3840 -h 2160 -f 29 -noprompt > C:\TechDiv\Logs\SetResolution.log 2>&1'
$Action = New-ScheduledTaskAction -Execute CMD.EXE -Argument '/C "C:\Program Files\SetResolution\SetREsolution.exe" SET -w 1920 -h 1200 -f 59 -noprompt > C:\TechDiv\Logs\SetResolution.log 2>&1'
#Trigger the scheduled task upon system startup and a user logging on.
$Trigger = @($(New-ScheduledTaskTrigger -AtStartup -RandomDelay (New-TimeSpan -Seconds 30)),$(New-ScheduledTaskTrigger -AtLogOn -RandomDelay (New-TimeSpan -Seconds 30)))
#Set the details of running the task itself, primarily automatically canceling the application if it takes more than a minute to run.
$Settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -DontStopOnIdleEnd -Priority 0 -StartWhenAvailable:$true -WakeToRun -ExecutionTimeLimit 00:05:00 -MultipleInstances IgnoreNew
#Create the actual scheduled task
Register-ScheduledTask -User $UserName -Password $Password -TaskName "SetResolution" -Action $Action -Description "For INM computers. Sets the screen resolution to 4K with a 29Hz refresh rate" -Settings $Settings -Trigger $Trigger -RunLevel Highest -Force -Verbose
Thanks again!
…-Bill
From: Tim ***@***.***>
Sent: Thursday, December 19, 2024 9:45 PM
To: RickStrahl/SetResolution ***@***.***>
Cc: Vollers, William L. ***@***.***>; Author ***@***.***>
Subject: [External Email] Re: [RickStrahl/SetResolution] Issues running SetResolution.exe as a scheduled task. (Issue #11)
This message was sent from outside the district. Please do not click links or open attachments unless you recognize the source of this email and know the content is safe.
________________________________
Nabu,
I'm successfully using this as a scheduled task for a project. How is your task scheduled? If it is upon user login, you will want to add a sleep/delay for a couple of seconds -- the task tries to run instantly before the GUI is fully rendered, and thus fails. This appears to be a Windows issue rather than something easily solved within this tool.
-
Reply to this email directly, view it on GitHub<#11 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/BNMVQYB46Z5AQZXDT72JCY32GOABVAVCNFSM6AAAAABS3767MWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNJWGE2TIMZRGY>.
You are receiving this because you authored the thread.Message ID: ***@***.******@***.***>>
________________________________
This communication may contain privileged and confidential information intended only for the addressee(s) named above. If you are not the intended recipient, you are hereby notified that any review, dissemination, distribution or duplication of this communication is strictly prohibited. If you are not the intended recipient, please notify the sender by reply email and destroy all copies of the original message. Under Florida law, e-mail addresses are public records. If you do not want your e-mail address released in response to a public records request, do not send electronic mail to this entity. Instead, contact this office by phone or in writing. Florida has broad public records laws and virtually all written communications are public records unless specifically deemed confidential pursuant to state or federal law.
#Clean up any previous versions of Set Resolution
#Find and remove local Resolution user, if exists. Checking for local account only
$OldAccounts = Get-WmiObject -Namespace root\cimv2 -Class Win32_UserAccount -Filter "LocalAccount = True AND Caption Like '$Env:COMPUTERNAME\\SetResolution%'"
#If local user was discovered, remove user using Net User command
foreach ($OldAccount in $OldAccounts)
{
if ($OldAccount.Name)
{
Write-Host "Removing account $($OldAccount.Name)"
CMD.EXE /C net user $OldAccount.Name /Delete
}
}
#Create a List of valid characters usable for usernames
$ValidChars = [char[]]([char]'A'..[char]'Z')
$ValidChars += [char[]]([char]'a'..[char]'z')
$ValidChars += [char[]]([char]'0'..[char]'9')
#Write-Host $ValidChars
#The Compass user account will start with SetResolution and then have 7 random characters following, for a total of 20 characters - the maximum net user accepts.
$UserName = 'SetResolution'
for ($i=1; $i -le 7; $i++)
{
#Write-Host $i
$UserName += Get-Random -InputObject $ValidChars
}
#Write-Host $UserName
#Add characters usable for passwords.
$ValidChars += ('!','#','$',',','~','-', '.','_')
#Write-Host $ValidChars
#Since password creation is completely random, it's possible, though unlikely, that a username would be created without letters, numbers or special characters. So, each password starts with $R1 to make sure that at least one of each type of character is included.
#Technically, this means the password is less random and only has 61 random characters rather than 64.
$Password = '$R1'
for ($i=1; $i -le 61; $i++)
{
#Write-Host $i
$Password += Get-Random -InputObject $ValidChars
}
#Write-Host $Password
#Create SetResolution User
#Write-Host "CMD.EXE /C net user $UserName $Password /ADD /PASSWORDCHG:NO /Y"
CMD.EXE /C net user $UserName $Password /ADD /PASSWORDCHG:NO /Y
#Get User Account
$User = Get-WmiObject -Namespace root\cimv2 -Class Win32_UserAccount -Filter "LocalAccount = True AND Caption Like '$Env:COMPUTERNAME\\$UserName'"
#Set Users password to never expire
$User.PasswordExpires = $False
#Save password never expires
$User.Put()
#Flag local user so that they don't show up as an available user on the desktop. Not needed in most instances, but special kiosks may make this necessary
if (!(Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts"))
{
New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts" -Force
}
if (!(Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList"))
{
New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList" -Force
}
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList" -Name $UserName -PropertyType DWORD -Value "0" -Force
#Add user to local administrators group
#Write-Host "CMD.EXE /C net localgroup Administrators $UserName /ADD"
CMD.EXE /C net localgroup Administrators $UserName /ADD
#Generate Scheduled Task
#Call the setresolution dotnet tool and provide the resolution and refresh rate needed
#$Action = New-ScheduledTaskAction -Execute '"C:\Program Files\SetResolution\SetREsolution.exe"' -WorkingDirectory "C:\Program Files\SetResolution" -Argument "SET -w 3840 -h 2160 -f 29 -noprompt"
#$Action = New-ScheduledTaskAction -Execute CMD.EXE -Argument '/C "C:\Program Files\SetResolution\SetREsolution.exe" SET -w 3840 -h 2160 -f 29 -noprompt > C:\TechDiv\Logs\SetResolution.log 2>&1'
$Action = New-ScheduledTaskAction -Execute CMD.EXE -Argument '/C "C:\Program Files\SetResolution\SetREsolution.exe" SET -w 1920 -h 1200 -f 59 -noprompt > C:\TechDiv\Logs\SetResolution.log 2>&1'
#Trigger the scheduled task upon system startup and a user logging on.
$Trigger = @($(New-ScheduledTaskTrigger -AtStartup -RandomDelay (New-TimeSpan -Seconds 30)),$(New-ScheduledTaskTrigger -AtLogOn -RandomDelay (New-TimeSpan -Seconds 30)))
#Set the details of running the task itself, primarily automatically canceling the application if it takes more than a minute to run.
$Settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -DontStopOnIdleEnd -Priority 0 -StartWhenAvailable:$true -WakeToRun -ExecutionTimeLimit 00:05:00 -MultipleInstances IgnoreNew
#Create the actual scheduled task
Register-ScheduledTask -User $UserName -Password $Password -TaskName "SetResolution" -Action $Action -Description "For INM computers. Sets the screen resolution to 4K with a 29Hz refresh rate" -Settings $Settings -Trigger $Trigger -RunLevel Highest -Force -Verbose
|
The display settings are user specific so if you running a scheduled task under an admin account, then that's not affecting the specific user's display settings. |
That makes sense.
With that in mind, would setting values for the system account affect the login screen then? The biggest issue that our teachers have actually been having is problems with the TV syncing with the desktop attached to it. So, it doesn't show the login screen, but instead just a black screen. (Technically, it's a black screen with a spinning progress circle. The circle is generated by the TV.)
The issue itself is relatively easy to fix, simply disconnect the hdmi cable and plug it back in after ten seconds or so and they're able to sync themselves again. But the issue there is two fold. Many teachers are technology adverse (after all, working with kids is often the opposite of that - and part of why they got into teaching in the first place). Even worse, some aren't scared of technology and will take the opportunity to improve things. (Which may or may not be an improvement - but it now means that no one else has instructions for the new configuration.)
Thanks!
…-Bill
From: Rick Strahl ***@***.***>
Sent: Sunday, January 5, 2025 3:32 AM
To: RickStrahl/SetResolution ***@***.***>
Cc: Vollers, William L. ***@***.***>; Author ***@***.***>
Subject: [External Email] Re: [RickStrahl/SetResolution] Issues running SetResolution.exe as a scheduled task. (Issue #11)
This message was sent from outside the district. Please do not click links or open attachments unless you recognize the source of this email and know the content is safe.
________________________________
The display settings are user specific so if you running a scheduled task under an admin account, then that's not affecting the specific user's display settings.
-
Reply to this email directly, view it on GitHub<#11 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/BNMVQYCHUCLGZLLVLAKMC6D2JDUZLAVCNFSM6AAAAABS3767MWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNZRGU2DMMRRG4>.
You are receiving this because you authored the thread.Message ID: ***@***.******@***.***>>
________________________________
This communication may contain privileged and confidential information intended only for the addressee(s) named above. If you are not the intended recipient, you are hereby notified that any review, dissemination, distribution or duplication of this communication is strictly prohibited. If you are not the intended recipient, please notify the sender by reply email and destroy all copies of the original message. Under Florida law, e-mail addresses are public records. If you do not want your e-mail address released in response to a public records request, do not send electronic mail to this entity. Instead, contact this office by phone or in writing. Florida has broad public records laws and virtually all written communications are public records unless specifically deemed confidential pursuant to state or federal law.
|
I'm with a school system that's trying to use your application as a scheduled task (we're trying to compensate for an issue between some classroom computers and the TV they're plugged into).
I've come across a problem running the application as a scheduled task. Originally, I thought it was an issue with running under the system account but in playing with things further, by using a local administrative account, it seems that the issue is more insidious.
For troubleshooting, I'm running a scheduled task with the following properties:
Program: CMD.EXE
Arguments: /C "C:\Program Files\SetResolution\SetREsolution.exe" SET -w 3840 -h 2160 -f 29 -noprompt > C:\TechDiv\Logs\SetResolution.log 2>&1
And that gives me the output to the log file of:
Set Resolution v0.2.1
(c) West Wind Technologies, 2022-2024
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at Westwind.SetResolution.SetResolutionProcessor.SetResolution()
at Westwind.SetResolution.SetResolutionProcessor.Process()
at Westwind.SetResolution.Program.Main(String[] args)
If I instead run the following from an administrative command prompt:
"C:\Program Files\SetResolution\SetREsolution.exe" SET -w 3840 -h 2160 -f 29 -noprompt > C:\TechDiv\Logs\SetResolution.log 2>&1
I get this output:
Set Resolution v0.2.1
(c) West Wind Technologies, 2022-2024
Couldn't find a matching Display Mode.
Available Monitors
1 Generic PnP Monitor
2 Generic PnP Monitor * (Main)
3 Generic PnP Monitor
Available Display Modes (8)
1920 x 1200 *
1920 x 1080
1680 x 1050
1600 x 900
1600 x 1024
1440 x 1080
1280 x 720
1176 x 664
(And yes, I realize that this isn't a great test on my computer - I don't have the available resolutions, but it's also been failing to run on the type of stations that we ultimately want it running from.)
I'd also attempted running this as the .Net tool but the system account seemed to have trouble keeping it loaded. (I hadn't really gotten far into testing it as the tool since I'd noticed that it wasn't staying available.)
Thanks!
Nabu
The text was updated successfully, but these errors were encountered: