| Author |
Message |
swinghouse
Joined: 12 Sep 2011 Posts: 80
|
Posted: Tue Oct 30, 2012 10:56 am Post subject: Installing a WinForm application with Deployment Manager |
|
|
Thanks for the help in setting up Windows Services with Deployment Manager: http://www.red-gate.com/messageboard/viewtopic.php?p=58646#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 |
|
| Back to top |
|
 |
justin.caldicott
Joined: 20 Apr 2011 Posts: 18
|
Posted: Thu Nov 01, 2012 5:01 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
swinghouse
Joined: 12 Sep 2011 Posts: 80
|
Posted: Tue Nov 06, 2012 3:41 pm Post subject: |
|
|
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...
/Mattias |
|
| Back to top |
|
 |
justin.caldicott
Joined: 20 Apr 2011 Posts: 18
|
Posted: Tue Nov 06, 2012 6:02 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
swinghouse
Joined: 12 Sep 2011 Posts: 80
|
Posted: Mon Dec 03, 2012 10:21 am Post subject: |
|
|
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: |
$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. |
|
| Back to top |
|
 |
Mike Upton
Joined: 11 May 2011 Posts: 50 Location: Red Gate
|
Posted: Tue Dec 04, 2012 5:51 pm Post subject: |
|
|
Hi Mattias,
Have you tried using the PowerShell 'Stop-Process' cmdlet (MSDN)?
| Code: |
| Stop-Process -processname MyProcess |
or using the 'kill' alias for Stop-Process...
| Code: |
| kill -processname MyProcess |
(by the way, the processname parameter accepts wildcards as well. I decided to try
| Code: |
| kill -processname * |
which you'll be glad to know results in an almost immediate BSOD )
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.
|
|
| Back to top |
|
 |
swinghouse
Joined: 12 Sep 2011 Posts: 80
|
Posted: Thu Dec 06, 2012 11:35 am Post subject: |
|
|
Hi Mike,
Thank you so much, Stop-Process worked beautifully!
Kudos as well for the final code sample in your post...
(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 |
|
| Back to top |
|
 |
justin.caldicott
Joined: 20 Apr 2011 Posts: 18
|
|
| Back to top |
|
 |
swinghouse
Joined: 12 Sep 2011 Posts: 80
|
Posted: Thu Jan 03, 2013 10:59 am Post subject: |
|
|
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: |
$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/viewtopic.php?p=59594#59594 |
|
| Back to top |
|
 |
swinghouse
Joined: 12 Sep 2011 Posts: 80
|
Posted: Tue Jan 08, 2013 12:02 pm Post subject: |
|
|
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: |
| (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) |
|
| Back to top |
|
 |
chirayu
Joined: 17 Sep 2012 Posts: 22
|
Posted: Tue Jan 08, 2013 4:07 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
swinghouse
Joined: 12 Sep 2011 Posts: 80
|
Posted: Tue Jan 08, 2013 6:47 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
chirayu
Joined: 17 Sep 2012 Posts: 22
|
Posted: Wed Jan 09, 2013 11:45 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
swinghouse
Joined: 12 Sep 2011 Posts: 80
|
Posted: Thu Jan 10, 2013 6:09 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
chirayu
Joined: 17 Sep 2012 Posts: 22
|
Posted: Thu Jan 10, 2013 6:14 pm Post subject: |
|
|
Thats great! _________________ Chirayu Shishodiya
Software Engineer - Deployment Manager
Red Gate |
|
| Back to top |
|
 |
|