编写计划任务(ConsoleApp)来写入文本文件
我需要编写一个将文本写入文本文件的任务。我首先想到的是这不应该太复杂,但我很早就在某个地方犯了错误。该任务稍后应以没有本地 Windows 帐户的用户身份运行,也许这也可能是一个问题,但我更早地陷入了困境。我使用我(本地管理员,域用户)在Windows任务计划程序中实现和运行任务,操作是运行.exe,即使未登录,任务也应运行。exe
中的代码状态如下
StreamWriter sw = null; try { sw = File.CreateText(@"C:\temp\test.txt"); sw.WriteLine("something something"); } finally { sw.Dispose(); }
(temp -)整个域都可以访问该文件夹,包括我和稍后运行任务的用户。
任务以错误代码 0xc0000005 结束,并且未写入任何文本文件。我做错了什么?没有文本文件!
提前致谢!
PS:该任务背后的想法是让它以有权访问网络驱动器的用户身份运行,以便计算机上的人可以访问存储在网络驱动器中的数据,因为连接到网络驱动器很痛苦。
I need to write a task which writes Text into a Textfile. This shouldn´t be too complicated is what i first thought but i making a mistake somewhere pretty early. The Task should later run as a User which has no local Windows-Account, maybe that can be a problem, too, but im stuck even earlier. Im using me (local admin, domain user) to implement and run the task in windows task scheduler, the action is to run the .exe, task shall run even when not logged in.
The Code in the exe states as follws
StreamWriter sw = null; try { sw = File.CreateText(@"C:\temp\test.txt"); sw.WriteLine("something something"); } finally { sw.Dispose(); }
The (temp-)Folder is accessible to the whole domain, including me and the user to run the task later.
the task ends on errorcode 0xc0000005 and no textfile has been written. What am i doing wrong? There is no textfile!
Thanks in Advance!
PS: the idea behind the task is to let it be run as a user who has access to network drive, so that data stored in the network drive can be accessible to the person on the pc, as connecting to a network drive is a pain.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
错误代码 5 表示“访问被拒绝”。运行计划任务的用户是否有权写入 C:\TEMP?
An error code of 5 indicates "Access Denied". Does the user that your scheduled task run under have permission to write to C:\TEMP?
始终使用使用:
Always use using: