Click here to Skip to main content
12,507,343 members (78,031 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# PowerShell Shell
Hello

I have a question i can't seem to find an answer to, and i hope someone can help :)
I want to create a application similar to Yakuake, Tilda, etc.

Currently i have been able to achive something simelar to this by using a textbox to enter the commands and another textbox to display the results using streams, but thats not a real shell now is it.

Console2(http://sourceforge.net/projects/console/[^]) does pretty much what I want to acheive, but not 100%.

So is there anyone here that know what technique that have been used in Console2? (And similar programs?) Another program that does this is the Powershell ISE, it's divided in 3 sections with a interactive powershell-shell at the bottom(So it should be do-able to do this in other programs aswell, right?)

Anyways, I hope someone here are able to put me in the right direction :)


Sincerely
Karl-Einar
Posted 21-Feb-12 11:29am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

This is a well-known thing, which is implemented in the class System.Management.Automation.PowerShell, please see:
http://msdn.microsoft.com/en-us/library/system.management.automation.powershell%28v=vs.85%29.aspx[^].

You can find a simple code sample here:
http://www.dougfinke.com/blog/index.php/2010/04/08/how-to-embed-powershell-within-a-c-application/[^].

Now, this sample uses a default console as it comes in console applications. You can use console in your Forms applications; you can show no output; or you can show output in some System.Windows.Forms control. I would recommend using ListBox to have the look closest to the traditional console. You can present the work of the shell in any other way.

If the execution of the shell can take some noticeable time, you should run it all in a separate thread. If you need to present some data produced by this PowerShell thread, you will need to use UI thread invocation, which I described in detail in my past solutions:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].

See also more references to my past answers on threading:
How to get a keydown event to operate on a different thread in vb.net[^],
Control events not firing after enable disable + multithreading[^].

—SA
  Permalink  
v2
Comments
ProEnggSoft 21-Feb-12 18:48pm
   
Good Info. Hence Voted 5.
SAKryukov 21-Feb-12 20:47pm
   
Thank you.
--SA
Karl-Einarb 22-Feb-12 4:46am
   
Thank you very much for the answer! :)
I haven't been able to test it yet, but the listbox idéa was a good one.
SAKryukov 22-Feb-12 11:59am
   
You are very welcome.
It works, for sure.

Good luck, call again.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160927.1 | Last Updated 21 Feb 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100