.net console app with hyperlinks? - c#

is it possible ? any samples/patterns or ideas on how to go about it ?
Update -
this essentially becomes a text browser which displays various tables of information based on various commands on the prompt like typing the url in a browser
now instead of typing various commands like
prompt>command arg1 arg2
if only you could say "click" on the text in a certain "column"/"row" which would execute the command say
prompt>commandX arg1
it'd be somewhat faster/easier
Now, before someone mentions doing a typical browser/asp.net mvc/whatever app, i already have that running but have encountered some limitations esp. with accesing network files. etc. Now that's taken care of using a service-broker service which reads the file etc. but having added numerous extensions to it, it'd be somewhat easier if you could just run the app as a console prompt with a mvc pattern and add extensions to it etc. etc.
if only the text is clickable, it'd make it more friendly for use !!

Assuming no mouse, I would just launch the URL as a new process based on some keyboard trigger.
// this will launch the default browser
ProcessStartInfo psi = new ProcessStartInfo("https://stackoverflow.com");
Process p = new Process(psi);
p.Start();
VB syntax:
// this will launch the default browser
Dim psi = New ProcessStartInfo("https://stackoverflow.com")
Dim p As Process = Process.Start(psi)

The window's shell doesn't support clickable hyperlinks, so no, this isn't possible.
What are you trying to do that warrants the need for hyperlinks in the command shell? Perhaps this application would be better built as a WinForms/WPF or ASP.NET application.

I don't know what a "hyperlink" is for you, but in the context of a Console Application, you can have numbers or letters that you are expecting the user to press
(imagine a simple menu with 3 options)
Press one option
1 - Open ServerFault
2 - Open StackOverflow
3 - Open SuperUser
and in the readline you have a switch that start the IExplorer process for example and opens the webpage.
Is that what you call regarding "hyperlinks in a console application"?

For an idea of what it can look like, get your hands on a copy of links. It's a text-mode web browser that works just fine in several operating systems.

you can access the mouse from the console, if you wish to have clickable elements in your console application. you'll have to build the logic yourself of course for the clickable areas.
http://cboard.cprogramming.com/windows-programming/38680-win32-console-app-mouse-input.html

Related

Is it possible to get the Process Start Info of a C# application?

First off, I had this idea from the Windows Command Prompt
I mean.. like:
- If you launch it from Win+R or "RUN", it will say "C:/Windows/system32/cmd.exe " in the title
- If you launch it from Cortana or the Search-type of stuff, it will show "Command Prompt" on its title
Anyways, is it possible to extract that kind of information using C#?
EDIT:
To get things straight, Is it possible to extract the "LAUNCH" information of the application? Like, for example, if I launched it from a shortcut, I am able to know the shortcut name, etc.
If you want to find the start path of the current application you can use the following sniped.
Process.GetCurrentProcess().MainModule.FileName

How to open two separate (default) browser windows instead of new tabs

I'm trying to use C# to open two separate browser windows side by side. I've tried using Process.Start(url) but that causes Chrome to open new tabs instead of new windows. This seems to work on IE, however I'd like to have code that can work with different types of browsers, namely: IE, Chrome, Firefox, and Safari. How do I detect the default browser and then open two separate windows side-by-side? Additionally, I want to be able to position the two windows next to each other, is that possible?
If you want to open new window in chrome instead of new tab, this code worked for me
Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = "chrome";
process.StartInfo.Arguments = <yoururl> + " --new-window";
process.Start();
This is more about the way that the browser is configured than how the process is called from C#. In both cases, the system simply calls the default program assigned to handle the URL. There may or may not be arguments to that command, but typically it will simply invoke chrome.exe <url> and from there, the chrome.exe process decides how to handle the parameter.
The only method I am aware of would be to examine the registry (under HKEY_CLASSES_ROOT\http\shell\open\command) and parse the string value. Once you know the specific browser, you may be able to control the presentation using command-line arguments. Of course, this is specific to Windows and may be a pain to manage.
If the browser does not support setting a geometry from the command line, you will need to use FindWindow and SetWindowPos (using P/Invoke) to manipulate the window locations.
I am not sure about your application, but would embedding a WebBrowser Control meet your needs? Then you would have total control of the presentation.

What would be a good way to collect data from the command prompt in a C# Winforms Application?

This is my first day on StackOverflow as a member, and I have to say I've enjoyed how well the idea behind this website works! Anyway, the question:
I am creating a C# Windows Forms Application that keeps an eye on all of the network statistics of a computer. This can be done by entering "netstat" into the command prompt, but to the normal computer user these days, that black rectangle is rather daunting, and the output does not update regularly, instead the user has to retype the command to get the most up-to-date information.
What I am wanting to do is have a code that is triggered every second to use a "netstat -noa" command in the command prompt and feed the data back into a DataGridView control with the columns "PID", "Foreign Address", and "Process State". The problem is, I've never done much using the command prompt in a GUI App and have absolutely no clue as to how to get the text table that pops up to the command into an organized fashion and into my DataGridView columns. I believe there may have been one similar posting on the site, but I also believe that it may have been Linux based.
Thanks for any help everyone!
Edit: Wow, I wasn't expecting so much input after two hours! You guys are great! It's been a lot better of an experience here than it has been on -shiver- other sites. I'm really looking forward to trying out the personal netstat implementation for the application and/or revving up Windows PowerShell. However, I'm not going to be able to attempt anything until tomorrow because it's getting late where's I'm at. I suppose we'll see what works out tomorrow. Cheers everyone.
I know you've tagged c#, but have you considered using Powershell at all? It's pretty much perfect for requesting data back from foreign boxes.
Suggested reading:
http://blogs.msdn.com/b/spike/archive/2010/02/04/how-to-query-for-netstat-info-using-powershell.aspx
Alternatively, google for: powershell netstat
In terms of C#, you probably want GetActiveTcpConnections():
http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ipglobalproperties.getactivetcpconnections(v=VS.80).aspx
scraping the output of a command prompt is one approach - here's a stackoverflow post about copy & pasting from a console window
a more substantial approach would be build your own netstat implementation like this guy did
Use a Process to run the command and capture its output:
How to spawn a process and capture its STDOUT in .NET?
A bit of a hack, but you could redirect the output of netstat to a file "netstat -noa > c:\netstat.txt" and then load the file and parse it...
Then a future version of Windows will change the format of netstat's output and it'll break your program. Instead of doing a "screenscraping" hack why don't you just call actual Windows APIs that will provide you the data that you are looking for? This is what Windows Managmenent Instrumentation is for.
How can I access netstat-like Ethernet statistics from a Windows program
You can use System.Diagnostics.Process and set the RedirectStandardOutput property of startinfo to true. This way you will be able to get the StandardOutput as streamreader. Make sure to set the UseShellExecute property to false and the CreateNoWindow property to true.

C# Start from search programs

How can I execute a search as if it was the search programs and files box in the start menu?
I want to start an application with a partial word search.
To be more specific.
If I put in the word skype.
I want skype to run.
Normally I can do this by entering the word into the search bar in the start menu and pressing enter. But I want to do this though some less obvious means.
Guess you could try opening an exporer with this string search-ms:displayname=Search%20Results&crumb=$$$$SEARCHSTRING$$$$
http://msdn.microsoft.com/en-us/library/h6ak8zt5.aspx to open an explorer.
You could take a look at the Windows API Code Pack. It makes it much easier to integrate a managed application with Window 7/Vista.
If you are asking how to launch an external program from your own C# program, you can do this:
Process launchProcess = new Process();
launchProcess.StartInfo.FileName = "Notepad.exe";
launchProcess.Start();
Here are couple links that get you started on using Windows Search:
Windows Search Overview http://msdn.microsoft.com/en-us/library/aa965362.aspx,
Using Managed Code with Shell Data and Windows Search http://msdn.microsoft.com/en-us/library/bb286799.aspx
Use Windows Vista Search API from a WPF Application http://www.codeproject.com/KB/WPF/Vista_Search_in_WPF.aspx.

Integrate C# Desktop Application With Browsers

I have developed an application(downloader) using C# now i want to integrate it to browser like i want to place a button in browsers if user press that button then my app should execute & start downloading the required file.
I'm largely guessing, but it sounds like you are talking about a "protocol handler", i.e. to handle hyperlinks to "yourapp:some-stuff-here". If so, try looking at Registering an Application to a URL Protocol on MSDN, which gives a C# example of this.
I don't think that what you want is possible, you can however place a link to the executable and tell your users to execute it via the Browser download options (The Dialog that pops up when you click on some download link that asks wether you want to open oder save the file).
It is not possible to immedatly run your GUI application on a browser button click.

Categories