Installing a WinForm application with Deployment Manager

Automated deployment for web applications and databases

Moderators: Mike Upton, justin.caldicott, Sean.newham, csmith, chirayu, DavidSimner, david.conlin

Installing a WinForm application with Deployment Manager

Postby swinghouse » Tue Oct 30, 2012 10:56 am

Thanks for the help in setting up Windows Services with Deployment Manager: http://www.red-gate.com/messageboard/vi ... 8646#58646

There's another type of .NET application that I'd like to manage through Deployment Manager, namely WinForms applications.

I suspect I should write a PowerShell script for this as well? Could you point me in the right direction as to which command(s) I should use?

(You'd be correct in identifying me as a PowerShell n00b!)

Please let me know if you think I should direct these PowerShell specific questions to other forums.

/Mattias
swinghouse
 
Posts: 99
Joined: Mon Sep 12, 2011 10:51 am

Postby justin.caldicott » Thu Nov 01, 2012 5:01 pm

Hi Mattias,

I'm glad we helped you get your Windows Services setup.

Yes, you could write a powershell script to deploy your WinForms apps, but there are a few possible approaches. How do you currently deploy them?

Thanks,

Justin
justin.caldicott
 
Posts: 55
Joined: Wed Apr 20, 2011 5:42 pm

Postby swinghouse » Tue Nov 06, 2012 3:41 pm

Hi Justin,

Thanks for the reply!

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... :roll:

/Mattias
swinghouse
 
Posts: 99
Joined: Mon Sep 12, 2011 10:51 am

Postby justin.caldicott » Tue Nov 06, 2012 6:02 pm

Hi Mattias,

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.
Justin Caldicott
Product Manager - Deployment Manager
Red Gate
justin.caldicott
 
Posts: 55
Joined: Wed Apr 20, 2011 5:42 pm

Postby swinghouse » Mon Dec 03, 2012 10:21 am

Hi,

Many thanks for your help and sorry for the belated reply.

The scenario you describe sounds very reasonable.

Please forgive my ignorance, but currently I'm stuck on a PowerShell detail. I tried to issue the following command through a PreDeploy.ps1 script:

Code: Select all
$processName = "MyProcess"
Get-Process $processName | % { $_.CloseMainWindow() }


What I want to accomplish is shutting down the "MyProcess" process before deployment starts.

Alas, the script doesn't manage to shut down the process (and returns false) when it is run by Deployment Manager. In contrast, running it locally on the target server, the script succeeds.

I suspect this is a security restriction in Windows? Are there any alternative commands I could use, or could I "elevate" the script?

Any help would be most appreciated!

/Mattias

PS. We really should convert this WinForms application to a Windows Service, but for now we have to cope with it. :-( DS.
swinghouse
 
Posts: 99
Joined: Mon Sep 12, 2011 10:51 am

Postby Mike Upton » Tue Dec 04, 2012 5:51 pm

Hi Mattias,

Have you tried using the PowerShell 'Stop-Process' cmdlet (MSDN)?

Code: Select all
Stop-Process -processname MyProcess

or using the 'kill' alias for Stop-Process...
Code: Select all
kill -processname MyProcess

(by the way, the processname parameter accepts wildcards as well. I decided to try
Code: Select all
kill -processname *
which you'll be glad to know results in an almost immediate BSOD :twisted:)

The PowerShell runner should have the appropriate permissions, because it runs in process with its host, the Red Gate Deployment Agent service, which normally runs as Local System.
Mike Upton

Software Engineer
Red Gate Software Ltd.
Mike Upton
 
Posts: 157
Joined: Wed May 11, 2011 8:04 am
Location: Red Gate

Postby swinghouse » Thu Dec 06, 2012 11:35 am

Hi Mike,

Thank you so much, Stop-Process worked beautifully!

Kudos as well for the final code sample in your post... :lol:

(And I really do need to get up to speed with PowerShell - a perfect task for the upcoming holidays when I come to think of it.)

/Mattias
swinghouse
 
Posts: 99
Joined: Mon Sep 12, 2011 10:51 am

Postby justin.caldicott » Fri Dec 14, 2012 7:06 pm

Hi Mattias,

If you get a chance, it would be great to share your script for deploying Win Forms apps in our new PowerShell forum!

http://www.red-gate.com/messageboard/vi ... .php?f=166
Justin Caldicott
Product Manager - Deployment Manager
Red Gate
justin.caldicott
 
Posts: 55
Joined: Wed Apr 20, 2011 5:42 pm

Postby swinghouse » Thu Jan 03, 2013 10:59 am

Hi Justin,

I'd love to contribute with something profound, but my current PowerShell script is very humble indeed!

All I do is check if my Win Forms app is running and, if that is the case, I shut it down, like so:

Code: Select all
$fullProcessName = $processName + '.exe'
if ((Get-WmiObject win32_process -Filter "name = '$fullProcessName'") -ne $null) {Stop-Process -processname $processName}


This is in the PreDeploy.ps1 script. The binaries are deployed through the magic of Deployment Manager and NuGet.

I'll revisit the PowerShell forum if and when I have some "juicier" scripts to share.

Update

I went ahead and linked to this discussion at http://www.red-gate.com/messageboard/vi ... 9594#59594
swinghouse
 
Posts: 99
Joined: Mon Sep 12, 2011 10:51 am

Postby swinghouse » Tue Jan 08, 2013 12:02 pm

One drawback to Stop-Process command that I have come to realize is that it terminates the process abruptly, without letting the process perform its usual shutdown activities.

Therefore I tested this command:

Code: Select all
(Get-Process 'processName').CloseMainWindow()


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.

Is it impossible to run CloseMainWindow() from Deployment Manager?

(This is related to my question at http://www.red-gate.com/messageboard/viewtopic.php?t=16312)
swinghouse
 
Posts: 99
Joined: Mon Sep 12, 2011 10:51 am

Postby chirayu » Tue Jan 08, 2013 4:07 pm

Hi Mattias,

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.

Let us know if it works out!

Thanks!
Chirayu Shishodiya
Software Engineer - Deployment Manager
Red Gate
chirayu
 
Posts: 68
Joined: Mon Sep 17, 2012 5:48 pm

Postby swinghouse » Tue Jan 08, 2013 6:47 pm

Hi Chirayu,

That worked superbly! Thank you!

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.)

/Mattias
swinghouse
 
Posts: 99
Joined: Mon Sep 12, 2011 10:51 am

Postby chirayu » Wed Jan 09, 2013 11:45 am

Glad it works, Mattias!

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

Thanks!
Chirayu Shishodiya
Software Engineer - Deployment Manager
Red Gate
chirayu
 
Posts: 68
Joined: Mon Sep 17, 2012 5:48 pm

Postby swinghouse » Thu Jan 10, 2013 6:09 pm

Thanks Chirayu,

And by automatically logging in the user in question when the system boots up, Deployment Agent (in interactive mode) is automatically available again.

I'm happy with this setup for now. Like I wrote earlier, when we get rid of the WinForms application, we'll certainly switch back to running Deployment Agent as a service.

/Mattias
swinghouse
 
Posts: 99
Joined: Mon Sep 12, 2011 10:51 am

Postby chirayu » Thu Jan 10, 2013 6:14 pm

Thats great!
Chirayu Shishodiya
Software Engineer - Deployment Manager
Red Gate
chirayu
 
Posts: 68
Joined: Mon Sep 17, 2012 5:48 pm


Return to Deployment Manager

Who is online

Users browsing this forum: No registered users and 0 guests