Tutorial :How I start my winforms app via telnet?



Question:

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?


Solution:1

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.


Solution:2

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.


Solution:3

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.


Solution:4

On Windows XP, I found a way around this limitation by using Windows task scheduler. For Windows 7, telnet is not installed by default.

I first had to change the Network Access: Sharing and security model for local accounts to "Classic â€" local users authenticate as themselves" by merging the following registry settings:

Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa] "forceguest"=dword:00000000

I placed it in a file on a remote FTP server and used the FTP command to get it.

Merge it with regedit /s file.reg

Then I created a task that ran once: SchTasks /Create /SC ONCE /RU "user" /RP pass /TN "StartApp" /TR "\"C:\Windows\NotePad.exe\"" /ST 00:00:00

Manually started the schedule: Schtasks /run /tn "StartApp"

Deleted the schedule: schtasks /delete /F /tn "StartAPP"

And that worked. Crazy right! What a pain!


Solution:5

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  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »