GetProcessesByName()和Windows Server 2003计划任务

时间:2022-03-19 02:30:30

Does anybody know what user privileges are needed for the following code needs to successfully execute as a scheduled task on Windows Server 2003:

是否有人知道以下代码需要哪些用户权限才能在Windows Server 2003上成功执行作为计划任务:

System.Diagnostics.Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName)

When NOT running as scheduled task i.e. under a logged in user, as long as the user is a member of "Performance Monitor Users", this code will not throw an exception.

当NOT未按预定任务运行时,即在登录用户下运行时,只要用户是“性能监视器用户”的成员,此代码就不会引发异常。

When running as a scheduled task under the same user account, it fails.

在同一用户帐户下作为计划任务运行时,它会失败。

The only way I can get it to work is to run it as a member of the Local Administrator group.

我可以让它工作的唯一方法是将其作为本地管理员组的成员运行。

Any ideas?

4 个解决方案

#1


2  

My humblest apologies. The user I was using was NOT a member of "Performance Monitor Users" group.

我最卑鄙的道歉。我使用的用户不是“性能监视器用户”组的成员。

This is necessary for .NET Framework 1.1 implementation of System.Diagnostics.

这对于System.Diagnostics的.NET Framework 1.1实现是必需的。

I have added the user to this group, and all is well.

我已将用户添加到此组,一切都很顺利。

#2


1  

What user rights assignments have you given the account that is running as a scheduled task? You'll need to give the account in question 'Log on as a batch job' in your local security settings.

您将哪些用户权限分配给作为计划任务运行的帐户?您需要在本地安全设置中提供有问题的帐户“以批处理作业登录”。

Update: Does your app write to any files and if so does the scheduled task user have enough rights?

更新:您的应用是否写入任何文件,如果是这样,计划任务用户是否有足够的权限?

I just knocked up a test app that writes the process names from the Process[] array returned by Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName) to a file and it works just fine as a scheduled task...even running under the identity of a user that is only a member of the Users group (not even a member of 'Performance Monitor Users'.

我刚刚敲了一个测试应用程序,它将Process.GetProcessesByName(Process.GetCurrentProcess()。ProcessName)返回的Process []数组中的进程名称写入文件,它可以正常工作...即使在仅作为Users组成员的用户的身份(甚至不是'Performance Monitor Users'的成员。

The folder it writes to is assigned modify rights to SYSTEM, Administrators and the scheduled task user.

它写入的文件夹被分配了对SYSTEM,Administrators和计划任务用户的修改权限。

Any chance of pasting your code or at least a small enough snippet that demonstrates the exe failing as a scheduled task so we can help diagnose the problem?

是否有机会粘贴您的代码或至少足够小的片段,证明exe作为计划任务失败,以便我们可以帮助诊断问题?

Cheers
Kev

#3


0  

One issue that I have seen with reading the process name is that access to the performance counters can get disabled.

我在阅读进程名称时遇到的一个问题是,可以禁用对性能计数器的访问。

Crack open your registry and see if this key is there: [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\PerfProc\Performance] "Disable Performance Counters"=dword:00000001

破解你的注册表,看看是否有这个键:[HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ PerfProc \ Performance]“禁用性能计数器”= dword:00000001

You can either set it to zero or deleted it.

您可以将其设置为零或删除它。

#4


-1  

Taken from MSDN:

摘自MSDN:

Permissions LinkDemand - for full trust for the immediate caller. This member cannot be used by partially trusted code.

权限LinkDemand - 完全信任直接调用者。该成员不能由部分信任的代码使用。

#1


2  

My humblest apologies. The user I was using was NOT a member of "Performance Monitor Users" group.

我最卑鄙的道歉。我使用的用户不是“性能监视器用户”组的成员。

This is necessary for .NET Framework 1.1 implementation of System.Diagnostics.

这对于System.Diagnostics的.NET Framework 1.1实现是必需的。

I have added the user to this group, and all is well.

我已将用户添加到此组,一切都很顺利。

#2


1  

What user rights assignments have you given the account that is running as a scheduled task? You'll need to give the account in question 'Log on as a batch job' in your local security settings.

您将哪些用户权限分配给作为计划任务运行的帐户?您需要在本地安全设置中提供有问题的帐户“以批处理作业登录”。

Update: Does your app write to any files and if so does the scheduled task user have enough rights?

更新:您的应用是否写入任何文件,如果是这样,计划任务用户是否有足够的权限?

I just knocked up a test app that writes the process names from the Process[] array returned by Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName) to a file and it works just fine as a scheduled task...even running under the identity of a user that is only a member of the Users group (not even a member of 'Performance Monitor Users'.

我刚刚敲了一个测试应用程序,它将Process.GetProcessesByName(Process.GetCurrentProcess()。ProcessName)返回的Process []数组中的进程名称写入文件,它可以正常工作...即使在仅作为Users组成员的用户的身份(甚至不是'Performance Monitor Users'的成员。

The folder it writes to is assigned modify rights to SYSTEM, Administrators and the scheduled task user.

它写入的文件夹被分配了对SYSTEM,Administrators和计划任务用户的修改权限。

Any chance of pasting your code or at least a small enough snippet that demonstrates the exe failing as a scheduled task so we can help diagnose the problem?

是否有机会粘贴您的代码或至少足够小的片段,证明exe作为计划任务失败,以便我们可以帮助诊断问题?

Cheers
Kev

#3


0  

One issue that I have seen with reading the process name is that access to the performance counters can get disabled.

我在阅读进程名称时遇到的一个问题是,可以禁用对性能计数器的访问。

Crack open your registry and see if this key is there: [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\PerfProc\Performance] "Disable Performance Counters"=dword:00000001

破解你的注册表,看看是否有这个键:[HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ PerfProc \ Performance]“禁用性能计数器”= dword:00000001

You can either set it to zero or deleted it.

您可以将其设置为零或删除它。

#4


-1  

Taken from MSDN:

摘自MSDN:

Permissions LinkDemand - for full trust for the immediate caller. This member cannot be used by partially trusted code.

权限LinkDemand - 完全信任直接调用者。该成员不能由部分信任的代码使用。