boruchsiper
boruchsiper

Reputation: 2028

Can't debug Windows Service -"attach to process"

Microsoft instructions state the following

In Visual Studio, choose Attach to Process from the Debug menu.

The Processes dialog box appears.

Click Show system processes.

In the Available Processes section, click the process for your service, and then click Attach.

However, I don't see the "Show system processes." option. I've tried checking off the other options but my service doesn't show up in the list.

enter image description here

Yes, I've installed and started the services and can see it in the in service manager.

I'm also aware that It's not possible to debug onstart. However, I have a continuous loop running.

Upvotes: 11

Views: 26489

Answers (6)

Alexander Higgins
Alexander Higgins

Reputation: 6923

By default processes not running under your account will be hidden, which is how services run by default unless you set them to run using a custom user.

Make sure show processes from all users is checked: enter image description here

Upvotes: 0

Steve Homayooni
Steve Homayooni

Reputation: 135

The name of the service might be different with the name of the process. The name of the process is probably the name of the service exe file. you can check this in task manager or in your windows service vs project. (the name that appears in the Attach Process window is the name of the process not the name of the service)

Upvotes: 0

Mike de Klerk
Mike de Klerk

Reputation: 12328

Make sure selected code type settings are correct. You manage them by clicking the [Select...] button next to "Attach to:". In the image you attached, you have set it to "Automatic: Native code". Try some other settings. Note: Press [Refresh] button after you have changed the setting to update the list of processes shown.

Upvotes: 0

IUnknown
IUnknown

Reputation: 22458

You may add somewhere in service, for example in OnStart method this code:

#if DEBUG
    System.Diagnostics.Debugger.Launch();
#endif

On service start, you will get a prompt dialog to debug process. Don't forget to build in Debug mode and switch to Release in production

Upvotes: 12

theMayer
theMayer

Reputation: 16167

You must do the following:

  1. Open your solution in Visual Studio Administrator mode.
  2. Make sure your service is running.
  3. Open the "Attach to process window"
  4. Make sure both checkboxes are checked (all users, all sessions).
  5. Find the name of your executable in the list.

If the above doesn't work, you will need to provide some additional details about your setup. :-)

Upvotes: 17

AgentFire
AgentFire

Reputation: 9780

Actually to allow the program to get the list of the processes of every user on the machine, that program must have administrative rights. Ensure you start visual studio with the corresponding account.

Upvotes: 0

Related Questions