GetProcessesByName() and Windows Server 2003 scheduled task
Asked Answered
A

4

1

Does anybody know what user privileges are needed for the following code needs to successfully execute as a scheduled task on 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.

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?

Avera answered 30/9, 2008 at 9:15 Comment(1)
Can u re-read my follow up, was a bit big for the comment box.Illconditioned
A
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.

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

Avera answered 1/10, 2008 at 8:26 Comment(0)
I
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'.

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

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?

Cheers
Kev

Illconditioned answered 30/9, 2008 at 10:49 Comment(1)
This is already done automatically: In Windows 2000 Server, Windows 2000 Professional, Windows XP Professional and the Windows Server 2003 family, the Task Scheduler automatically grants this right as necessary.Avera
H
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

You can either set it to zero or deleted it.

Hellen answered 30/9, 2008 at 10:4 Comment(0)
B
-1

Taken from MSDN:

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

Bunche answered 30/9, 2008 at 9:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.