2

I cannot implement it as a windows service because my process has to interact with desktop and it's prohibited in Windows 7.

What is the simplest way to accomplish this? Starting under another (privileged) user? How to do this?

My users are not hackers, just an operators, so some "dumb" methods like hiding from task manager would help too.

EDIT: some clarification according to provided answers

my process doesn't have any GUI, so I'm trying to avoid killing the process from task manager

my process is a client of a supervising system that has to monitor user's desktop, so it has to interact with desktop

EDIT 2:

can I use a windows service that will start separate process in user session under system account (since my service is running under system account)? can user kill this child process?

Andriy Tylychko
  • 15,967
  • 6
  • 64
  • 112
  • Possible duplicate of [Prevent user process from being killed with "End Process" from Process Explorer](http://stackoverflow.com/questions/6185975/prevent-user-process-from-being-killed-with-end-process-from-process-explorer) – EMBarbosa Jan 19 '17 at 18:12

4 Answers4

2

You could disable the task manager using a Group Policy and hide the close button from you application's window and the reaction on [Alt+F4].

marc
  • 6,103
  • 1
  • 28
  • 33
  • 2
    Is the fix worse than the problem? Task Manager is a key diagnostic tool. And of course not the only way of listing/manipulating processes built into Windows (eg. `Stop-Process` in PSH). – Richard Jul 26 '11 at 08:33
  • @Richard: my users don't need to diagnose the system, they have technical persons for this. Probably it's an acceptable "dumb" method that I asked for, still waiting for other suggestions... – Andriy Tylychko Jul 26 '11 at 08:37
  • @AndyT: I was avoiding making assumptions about what you mean by "operators" (eg. help desk operators). – Richard Jul 26 '11 at 08:41
  • [Don't use global state to manage a local problem](http://blogs.msdn.com/b/oldnewthing/archive/2008/12/11/9193695.aspx). – user Dec 19 '12 at 12:36
2

after long digging I found acceptable answer here: Prevent user process from being killed with "End Process" from Process Explorer

works fine if you're logged in as a regular user, you cannot kill the process from Process Explorer. Admin still can kill it because has sufficient privileges. it's exactly what I needed

Community
  • 1
  • 1
Andriy Tylychko
  • 15,967
  • 6
  • 64
  • 112
1

Closing the (root) window doesn't mean stopping the process – when the message pump loop exists you could just re-start it with a new window (clearly if you are using a framework there is probably a wrapper around this).

But if a user owns a windows object (like a process) they can always delete (terminate) it. But running as a different user that user's credentials will need to be stored in a way that's accessible to the launcher running as the current user.

To help more specifically I think we need to understand why:

because my process has to interact with desktop

is a requirement.

Richard
  • 106,783
  • 21
  • 203
  • 265
  • The first option (effectively ignoring `WM_CLOSE`) is sufficient for the stated goal. Surviving `TerminateProcess()` is probably overkill given the context. – MSalters Jul 26 '11 at 08:31
1

From this MSDN blog:


This is how you do it:

Get the user token by calling

WTSQueryUserToken (WTSGetActiveConsoleSessionId (), &hToken) ;     

Use this token in CreateProcessAsUser.


You just need to call WTSQueryUserToken from your service, and launch the process - it works on Windows 7 too!

Ajay
  • 18,086
  • 12
  • 59
  • 105
  • +1 for very interesting link. but that's not a complete story! following your advice I'll create interactive process under logged-in user, so it can be terminated by this logged-in user. and I try to avoid this. how to run this service under system account? `1.B` case in that blog post sounds similar. So I could create temp process under logged-in account (as you described) and from there CreateProcessAsUser with system account token. But how can I pass system account token from my service to that temp process? – Andriy Tylychko Jul 26 '11 at 15:00
  • 1
    I understood your problem. Don't know "how" to achieve this, but this is possible - NAV's process 'ccSvcHst.exe' cannot be terminated by me despite it running under my user account. It probably uses `SetKernelObjectSecurity` to delete all ACL for account (or sets them to "deny"). – Ajay Jul 26 '11 at 15:07