当设置为“启动时”时,控制台应用程序无法通过任务计划程序启动

当设置为“启动时”时,控制台应用程序无法通过任务计划程序启动

问题描述:





我在C#.Net中实现了一个简单的控制台应用程序,只要在C:\ MyFolder中写入文本文件它发射。我已在任务计划程序中配置了具有以下属性的应用程序。



常规选项卡 - >运行用户是否登录。

触发器 - >在系统启动时

操作 - >程序/脚本=我的exe的路径(E:\ MyProject \ Test.exe)

Start-in =带有exe名称的路径。 (E:\ MyProject)



一旦我启动机器,我希望文本文件存在。这是在登录桌面之前,因为我已将属性设置为At system start up而不是At log on。但是只有当我登录到机器时,我的exe开始运行并且文件被复制。是因为它是一个需要桌面/ UI启动的控制台应用程序。?



那么在我们没有的服务器机器中会出现怎样的情况?用户登录或默认登录。即使在登录之前/没有登录的情况下,如何使我的控制台应用程序能够在后台运行?





请澄清!!



谢谢



我尝试了什么:



我试过以下



a)更改属性运行任务时,使用以下用户帐户从我的默认登录到SYSTEM。

b)选中选项 - 以最高权限运行。

c)创建一个.bat文件,然后启动控制台应用程序。但是,这也不能通过任务调度程序启动我的控制台应用程序。

Hi,

I have implemented a simple console application in C#.Net that writes something to a text file in "C:\MyFolder" as soon as it launches. I have configured the application in task scheduler with the below properties.

General tab->Run whether user is logged on or not.
Triggers -> At system start up
Actions -> Program/Script = Path to my exe ( E:\MyProject\Test.exe)
Start-in = Path with exe name . (E:\MyProject)

I am expecting the text file to be present once I start my machine. That is before logging in to the desktop as I have set the property to "At system start up" rather than "At log on" . However only If I log in to the machine, my exe starts running and the file gets copied. Is it because it is a Console App which requires a Desktop/UI to launch.?

So how will be the case in server machines where we don't have a user login or it gets logged in by default.? How can I make my console application to lauch/ or work in background even before login/ where there is no login?


Please clarify!!

Thanks

What I have tried:

I have tried the below

a) changing the property "When running the task, use the following user account" from my default login to SYSTEM.
b) Checking the option - "Run with highest privileges".
c) Created a .bat file that would in turn launch console app. However this doesn't launch my console app through task scheduler also.

控制台应用程序不需要用户登录即可运行。



重写应用程序以捕获并将错误记录到C:\ Windows \ Logs中的文件中。此外,只需记录开始和其他diag消息到文件,而不仅仅是错误。



要检查的东西...



从任务计划程序运行的应用程序设置是什么帐户?应该是本地系统

或系统。



在尝试创建该文本文件之前,C:\ MyFolF路径是否存在?



E:是网络驱动器吗?如果是这样,那就行不通了。您必须使用UNC路径,因为驱动器映射将不存在。此外,系统帐户将没有共享文件夹的权限。
Console applications don't need a user to be logged in to run.

Rewrite the application to catch and log errors to a file in C:\Windows\Logs. Also, just log start and other diag messages to the file, not just errors.

Something things to check...

What account is the app setup to run from task scheduler? It should be Local System
or System.

Does the C:\MyFolder path exist before you try to create that text file?

Is E: is network drive? If so, that's not going to work. You have to use UNC paths as drive mappings won't exist. Also, the System account will not have permissions to the shared folder.


最好是使用服务而不是控制台应用程序。
May it would best for you to use a service instead instead of a console application.