The Windows Form app does not become active when the Task Scheduler is started.

Asked 2 years ago, Updated 2 years ago, 44 views

Developed with C#.

I am creating a Windows Form application with administrator privileges and
You have registered with the Task Scheduler to launch this form application at PC startup.
(Because I found that Windows 10 cannot launch applications that require administrator privileges from startup)

Here's the point.
I'd like to put the application in the active state when I start the Task Scheduler.
This.Activate();
or
This.TopMost=true;
The ActForm.ActiveForm 」 does not appear to be true.

Manual double-click boot will bring you to the active state.

Is there any way?

c#

2022-09-30 19:16

2 Answers

The situation may be similar to the one shown on the page below.

Several conditions were required for one process to foreground another's window.If the conditions are not met, the taskbar icon flashes instead of foregrounding the window.
Activate a window for an external application - DOBON.NET

(Note) The above conditions are explained on the following page.
SetForegroundWindow-MSDN

If you are okay with using the Win32 API, why don't you use AllowSetForegroundWindow-MSDN or BringWindowToTop-MSDN?
In addition, The above page contains instructions and precautions, so please read them carefully beforehand.

Note:
In the pattern I experienced, I didn't want to use Win32 API, so I was satisfied with the Taskbar icon flashing.(Main Process → When moving to a subprocess, we waited until the subprocess's form handle was obtained before hiding the form displayed in the main process, but we compromised because we encountered a phenomenon in which the subprocess → main process did not become active.)


2022-09-30 19:16

"If you search ""Windows task scheduler administrator privileges"", this would be good."

Windows 10 - Automatically launch apps that require administrative privileges (startup)
https://pc-karuma.net/windows-10-task-schedule-without-uac-prompt/

Additional
Under Security Options on the General tab in Task Properties,
It appears that Run only when the user is logged on is selected.

Below is an example of how Windows 7 has registered to run a batch file.
The screen does not display the batch files that Windows 7 runs from the Task Scheduler.
https://answers.microsoft.com/ja-jp/windows/forum/windows_7-winapps/windows7%E3%81%A7%E3%82%BF%E3%82%B9%E3%82%AF/ccff2c2f-5a0e-4f3d-ae81-9dff3e36fc3c?auth=1


About setting the user account and author to use when performing tasks
in similar Q&A I'm referring to something, but I think it's okay.
UI Does Not Appear When Booting to Windows 7 Task Scheduler
https://okwave.jp/qa/q5910555.html

Windows 7/8.x/10 Task Scheduler General Description is available below.
Basic Task Scheduler Usage (Windows 7/8.x/10)
http://www.atmarkit.co.jp/ait/articles/1305/31/news049.html


2022-09-30 19:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.