Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

How do i do this? (Possibly Windows Messaging related)

  • 12-08-2005 12:13pm
    #1
    Closed Accounts Posts: 4,943 ✭✭✭


    Basically, i have an app which i want to be able to open a webpage in the OS's default browser. If i was to do this by hand, what i'd do is click on start>Run. and i'd type in www.boards.ie and click ok. That would make windows open boards.ie in the default browser.

    How can i do this via code? Is "windows messaging" (or whatever its called) what i'm supposed to use to do this? Or is there something else? Any method that works is fine by me.

    I'm coding in C#, and its a windows application.


Comments

  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    You would shell out to the system the URL. The system should do the rest.


  • Closed Accounts Posts: 4,943 ✭✭✭Mutant_Fruit


    Thats what i'm looking into, i know its possible, i just don't know what command i should be looking for in order to send the URL to the system and let the system take over. I'll keep browsing, i'm sure i'll find it eventually. I'll probably end up experimenting with the Process class and see if i can make something work from that.


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Easy peasy, Process and ProcessStartInfo are what your looking for, they're in System.Diagnostics.

    Here's a basic method I flung together, there's loads of other cool and funky things you can do though:
    private void LaunchBrowser(string uri)
    {
    	try
    	{
    		ProcessStartInfo psi = new ProcessStartInfo();
    		psi.FileName = uri;
    		Process.Start(psi);
    		
    	}
    	catch(Exception ex)
    	{
    		MessageBox.Show(ex.ToString());
    	}
    }
    

    Ah, I see you've found it already.


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    normally something like Shell() or Exec()


  • Closed Accounts Posts: 2,028 ✭✭✭oq4v3ht0u76kf2


    Pardon my ignorance, but would a desktop shortcut not achieve the same effect?


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Not if your trying to launch it programatically no.


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 93,599 Mod ✭✭✭✭Capt'n Midnight


    For most versions of windows at the command prompt/in a batch file you would type

    Start http://www.boards.ie

    so you could figure out how to shell out to dos or call a batch file


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    You could shell it out to dos or cmd but it would require the use of the Win32 API which means writing unmanaged/unsafe code. The .Net framework accounts for most API calls, outside of the really obscure things, and using Process and ProcessStartInfo is the .Net way to do this. Not the only way I'm sure but does seem to be the .Net *replacement* for ShellExec().


  • Closed Accounts Posts: 4,943 ✭✭✭Mutant_Fruit


    Excellante! I wasn't sure if i could use the Process class in that way (and i didn't have time to do extensive googling on it) but i was planning on trying something similar. I was thinking of writing a .url file, then executing it with a Process and then deleting the .url file as opposed to directly executing a url. (if you know what i mean).

    Directly executing the url is by far the better way. Thanks.
    Pardon my ignorance, but would a desktop shortcut not achieve the same effect?
    It would achieve exactly the same affect. But imagine the annoyance of a user when they click on a (dynamic) link in my program, and instead of a webpage opening, a dialog opens and tells them to click on a freshly created shortcut that i put on their desktop :P


  • Registered Users, Registered Users 2 Posts: 6,571 ✭✭✭daymobrew


    I don't know C# but here is the answer in C:
    ShellExecute(NULL, "open", "http://www.boards.ie", NULL, NULL, SW_SHOWNORMAL);
    
    See ShellExecute at msdn.microsoft.com for more information about the NULL parameters.


  • Advertisement
Advertisement