views:

502

answers:

4

I have a windows forms application on a client machine. I am trying to log in via telnet, shut it down, update some files, and restart it.

Using cmd on the client machine and typing in MyApp.exe works great to start it. But if I do this in the telnet window something odd happens: The application starts in as far as it is now in the process list but none of its forms ever open nor any log4net logging is done.

What's going on and how do I fix this?

Edit: This seems to be the case with all form-based windows apps. Try it out yourself: telnet localhost => notepad. It pops up int he user interface but not the ui!

Also, I have RAdmin installed on all these machines? From what I've seen its got non-existent automation facilities but maybe there's something about it that can help me out?

+1  A: 

Edit: In my original answer, I misunderstood your question, I thought you said you restarted the machine.

With that said, I'd still probably try to take a different approach. Can you set some type of auto update service into MyApp.exe. An easy way would be to set up a webservice which MyApp.exe can poll to see when new versions are available. Then you'll need to lauch an updater application to do the updating work.

Bob
why no user context? I log into telnet as the user. I do not want to restart the machine, just update the system files such as the program's dll.
George Mauer
Ok, we're getting into some pretty complicated architecture austronaut territory just to solve a problem with an application starting in the wrong mode. If worst comes to worst I can do a 2 line bootstrapping app that uses Process.Start or something but that's just another moving part, there has to be something simpler?
George Mauer
+1  A: 

I think what's going on is that your app is starting up on a private desktop, and then quiting as soon as you close your telnet session. I don't know how to make it start up on the "current/active" desktop window, but to keep it running after you log out of telnet try running with the "start" command.

Joel Coehoorn
Ah, thanks joel, an interesting clue.
George Mauer
Actually I just thought of this, if it was simply starting on a private desktop then why isn't log4net logging anything?
George Mauer
If you log out right away, it could be it quits before it has time to do anything. But I suspect it's more likely a permissions issue.
Joel Coehoorn
+1  A: 

Instead of using telnet, you could try using VNCRobot. I believe VNCRobot runs as the user and should share the same desktop.

Disclaimer: I've never used VNCRobot, I just thought it would be worth mentioning.

dss539
Thanks, that sounds interesting but I can't justify installing more third party VNC software on these machines when we already have remote administrator running on there - even if it's automation is sh*t.
George Mauer
So you have http://www.radmin.com/products/radmin/ installed? I didn't notice that in the question. You might want to edit that into your question because there may be something special about telnetting via that tool that causes this problem. Or maybe not... but it's worth mentioning just in case.
dss539
Well I'm not telneting in via that tool, I'm doing this via a ruby script actually. Or cmd, or powershell - don't particularly care which one. I did edit this fact in however. Maybe it has some sort of utility or extension that I could use.
George Mauer
A: 

If you can run PowerShell on these machines you could use it to find the running process and kill it. the..

Get-Process

..Cmdlet will show you the running processes, you can write the logic to foreach through this list and match your application with regex directly in powershell, I don't know Ruby but theoretically you could use it to do the same invoking the powershell commands with:

powershell.exe -command Get-Process

To kill a process its:

Stop-Process <processId>
Stop-Process -processname <processName>

Not quite sure how to start the GUI process through telnet, I don't have telnet setup on my equipment.

perhaps you can do something similar to this: http://www.peterprovost.org/blog/post/Powershell-Sudo-(sort-of)-for-Vista-UAC.aspx

Setting the verb to "runas" like in the example at that address will invoke UAC, doing this I was unable to kill the new process, however I am to kill it if I set:

$psi.Verb = "open"

Additionally you can set these attributes as well:

Verb                    : open
Arguments               :
CreateNoWindow          : False
EnvironmentVariables    : {processor_revision, processor_level, logonserver, systemroot...}
RedirectStandardInput   : False
RedirectStandardOutput  : False
RedirectStandardError   : False
StandardErrorEncoding   :
StandardOutputEncoding  :
UseShellExecute         : True
Verbs                   : {open, runas, runasuser}
UserName                :
Password                :
Domain                  :
LoadUserProfile         : False
FileName                : notepad.exe
WorkingDirectory        :
ErrorDialog             : False
ErrorDialogParentHandle : 0
WindowStyle             : Normal
thinkhard
The only problem that I'm having is with starting the process. Stopping it is easy - taskkill. Also no powershell, they're touchscreen dumb-terminals so its unlikely to be approved too.
George Mauer