question

MarcHankinMarcAMsAcct-1398 avatar image
0 Votes"
MarcHankinMarcAMsAcct-1398 asked LimitlessTechnology-2700 answered

Powershell commands to show the desktop don't work in my bootup .cmd script.

I have found 2 ways to use Powershell and .cmd files to minimize all windows, and show the desktop.
Each of the 2 methods work when I run either of them in a command prompt window in my Win 10 pro 64 bit pcs:

 :: # https://devblogs.microsoft.com/scripting/powertip-use-powershell-to-display-the-desktop/
 Rem  Method #1
 set _ShowDesktopPs1="C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "(New-Object -ComObject shell.application).toggleDesktop()"
 START "Show Desktop" /Min %_ShowDesktopPs1%
    
 Rem  Method #2
 "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "(New-Object -ComObject shell.application).toggleDesktop()"

But neither Method #1 nor Method #2 work (i.e., by minimizing all windows and showing the desktop), when I run them as two of last three lines of my boot-up script:

"C:\Documents and Settings\Marc\Start Menu\Programs\Startup\Desktop_startup_aaa.cmd - Shortcut.lnk"

The last line of my bootup script, Desktop_startup_aaa.cmd, is: "@ECHO Batch file execution completed."

I would appreciate any suggestions where I could find something that would help me understand why neither Method #1 nor Method #2 work (i.e., by minimizing all windows and showing the desktop), when I run them as two of last three lines of my boot-up script.

Alternatively, it'd be great if someone could tell me how to alter them so that they would minimize all windows and show the desktop.

Lastly, if I used the wrong tags for this question, please tell me what the right ones are; and if I posted this in the wrong forum, please tell me what the right one is, if you know.

Thank you for your help.

                     Marc




windows-10-generalwindows-server-powershell
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Maybe this operation is performed too yearly, when the windows were not displayed yet. It is probably difficult to determine if it is the time to minimise the windows. If the windows are created by this command file, maybe you can use the “START /MIN …” command to launch the programs in minimised state.


0 Votes 0 ·
AndreasBaumgarten avatar image
0 Votes"
AndreasBaumgarten answered

Hi @MarcHankinMarcAMsAcct-1398 ,

I am assuming the script will be executed while the computers are booting? Or is the script triggered during a user's login phase?

My guess (just a guess!): At the time the script is executed, there is still no "desktop environment" that can be controlled by the script.


(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

Regards
Andreas Baumgarten

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered

Hello,

Thank you for your question.

Additionally, I would suggest to put pause of 30 to 60 seconds at the starting the actual command of minimizing the windows.

Alternatively ,
I would like to suggest you to check record PowerShell scripts logs using below example , to see where it stuck or it actually runs or not.



Start-Transcript -path "C:\Temp\PSLog.txt"

<Your Power shell command and Code>

Stop-Transcript



If the reply was helpful, please don’t forget to upvote or accept as answer.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.