Is it possible to embed a Powershell screen in my application?
I want to see the screen itself, just like Visual Studio does. I cannot use a console redirect as that option would not allow me to interact with programs or view programs displaying colors and the like.
Capture both standard input and standard output is not a possible solution. I am using programs that use colors and progress bars.
It would be something similar to being able to implement a Windows Terminal, or https://github.com/dwmkerr/consolecontrol
I also tried this code, but it does not allow me to embed to Terminal server although I can use it with Notepad Run extended programs GUI on my own c# form
Looking for information, I found a project that apparently could be what I am looking for but it does not work with Winforms and I cannot find a simple example of use. https://github.com/PowerShell/PowerShellEditorServices
Related
I have a console application (.bat file) which starts in a console window. I have a shortcut to this app on my desktop, which contains several properties which I need to change programmatically (in example font of this specific window).
How can I do this? The best option for me would be to do it using cmd.exe commands, or using .net environment, is that even possible?
I was playing around with Microsoft Spy++ and noticed that not only does it find the open processes, but can find the individual components running in each process. For example there is this application that allows you to open a window in which there is a textbox for an IP address and textbox for a port. Spy++ can detect these components. Knowing that Spy++ can detect them, is there anyway possible to find them in a separate c# application and go on to MODIFY their contents and otherwise interact with the program? (such as firing a click event on a button)
This is feasible. Try use PInvoke (InterOp) or AutomationElement, or AutomationPeer (for WPF applications) to automate all you wish to do.
Also you might wish to try Inspect and UISpy application as well.
Automation elements/peer is a non-intrusive mechanism to control UI using accessibility framework. One of the weaknesses in windows is its lack of defence against code injection. Put simply:
As a privileged user,
- You can Open and Modify a running Process image
- Make it load your OWN DLL
- Make it run your OWN thread (that potentially listens to commands from your process) and
- allows you to read any bits of memory you want.
Look at detours (http://research.microsoft.com/en-us/projects/detours/) for how to do it with Managed Processes.. Unfortunately, Microsoft removed the inject at runtime features.
Also look at http://msdn.microsoft.com/en-us/magazine/cc163617.aspx for doing things in the managed world (Apps like Snoop utilise that)
I'm currently programming a logon server for an application, I will need all the objects I made in another server that I made in the same project, but now I want some way to split both applications up in sepertate console screens up, without running 2 serperate c# applications
You'll need to create a form to display your output, as there is a strict limit of one true win32 console per process.
Your comment mentioning "1 console with 2 separate screens" suggests an alternative. The Win32 Console API has rich functionality for placement of text within the console window. You can change color, background color, intensity as well. But for this purpose the most interesting capability is to scroll only part of the console window. I've actually done this before to create two separate output streams in a single console window. Unfortunately, there's no easy way to access this functionality from .NET -- you'd have to use p/invoke extensively (or write your own wrapper using C++ interop). And it doesn't have any concept of focus to allow two independent input streams; it only works for multiple outputs.
I would like to integrate an existing program (ex: notepad, explorer, etc.) into a new window I want to create. The purpose would be to have 2 different programs in 1 window.
Do you know if it is something possible?
If it is, what kind of technology could I use? (I can use C++, C# in windows 7/Visual)
Thanks.
If you wish to add an external program then I suggest you have a look at SetParent, ShowWindow and SetWindowLong. The theory is to set your window (or a control within your window) to be the parent of another window/control.
This question has been asked in many different ways out there, but I have not found the answer yet. I want to add a control in my WPF window that simulates a console (for writting and reading text, possibly with colors). OK... if there is no control out there already (which is very strange since it's kind of basic), how would I go about building one?
My final goal is to build a Powershell host where I can type commands and get output.
You can always make your application a Console application, which gives you a true console.
Otherwise, if you just want to have input and output, typically this can be done via TextBox and/or RichTextBox or the WPF Document Support.