Currently, we deploy the applications by brute force - we generate an installer package through a Setup and Deployment project in Visual Studio, copy the packages to the target servers and run them manually there. Not an ideal situation, to put it mildly...

I see, so you have a known set of machines that you want to keep up-to-date with some winforms software.

The challenge with deploying to many machines like this will likely be the initial setup. That is, any registry settings, shortcuts or other functions the installer performs, would need to be included as part of your PowerShell script, to be used on first deploy.

Once the software is installed, it would work really nicely keeping these up-to-date from the Deployment Manager UI, without needing to manually install updates on each machine.

I hope this helps! Kindly let us know how you get on, or if you need further help with any powershell, etc.

This works really well when I run it directly on the target server, but unfortunately not when Deployment Manager attempts to execute it from my PreDeploy.ps1 file. In the latter case the process isn't stopped and CloseMainWindow() returns false.

The Deployment Manager Agent service which runs on your target machine runs is probably running on a different session ID to your WinForms application. If this is the case, the Agent service cannot see your WinForms application UI and hence can't close it.

You can view the session ID of different processes from Windows Task Manager in 'Processes' tab. Make sure the column for session ID is enabled from View -> Select Columns.

Because your Agent service starts up at boot time automatically, it runs under SYSTEM username and has session ID 0. Your WinForms application is running in a different session ID.

One fix to this problem would be to get the agent to run in same Session ID as your WinForms application. Please follow the steps below:
- Start Task Manager.
- Navigate to services tab.
- Right-click 'Red Gate Deployment Agent' and stop service.
- You can now start the Agent service in Interactive mode from the start menu option 'Deployment Agent (interactive mode). This should run in session ID 1 (unless you have multiple users logged in to your system, each of them have a different session ID allocated).

You can also configure the agent service to not start up automatically when you boot your server. If you go to start menu option 'Services' -> right click 'Red Gate Deployment Agent' -> Properties -> Change 'startup type' to manual.

One follow-up question: Our current setup with the WinForms application running on a server, is to 1) automatically log in a user when the computer boots up and 2) auto-start the WinForms application. I guess these steps are required for Deployment Agent as well when running it in interactive mode?

(I realize that running a WinForms application on a server like this really isn't ideal. We will certainly port this app to a Windows Service, but that's (still!) in the future... On that lucky day we can switch back to running Deployment Agent as a proper service.)

If you want to deploy to that target machine, then the Agent ought to be running either as a service or in the interactive mode.

The agent service starts up automatically in the background, when your server boots up (that is the default behaviour at least). You can get the agent in interactive mode to start up automatically when computer boots up by:
- Place a shortcut of 'Deployment Agent (interactive mode)' on desktop
- Cut the shortcut and paste it into Start Menu -> All Programs -> Startup