Hey,

My want to make creation this time is a program where you would ask the user for a website and then they would input it and then IE/FF would open up and your done!.

Just I'm not sure how I would achieve this.

Just point me in the right direction. Thank you.

Dani AI

Generated

: for a small utility that asks for a URL and opens the user’s browser, prefer asking the OS to open the URL instead of shelling out to a command string. That avoids quoting headaches and command‑injection risks that came up in this thread (see , and ). On Windows the supported API is ShellExecute/ShellExecuteW — it asks the shell to open the URL with the registered handler (the default browser). Example:

#include <windows.h>
#include <shellapi.h>

bool OpenUrl(const std::wstring& url) {
    HINSTANCE r = ShellExecuteW(NULL, L"open", url.c_str(), NULL, NULL, SW_SHOWNORMAL);
    return reinterpret_cast<intptr_t>(r) > 32; // >32 indicates success
}

If running through the shell (what fixed ) remember why the raw URL failed: cmd.exe treats a plain token as a program name, so just typing a URL is not a valid command. Using the shell builtin that knows URL associations worked, but calling the shell directly from C/C++ is fragile — quoted arguments can be misinterpreted as window titles and unvalidated input can lead to injection. Always normalize user input (prepend "http://" if the scheme is missing), validate length and characters, and use OS APIs instead of building command lines when possible.

If the goal is to embed browsing inside the app (not just launch an external browser), use a modern embedding solution: Microsoft WebView2 for Windows, Chromium Embedded Framework (CEF) for cross‑platform, or Qt WebEngine if you use Qt. For ShellExecute documentation and WebView2 getting started, see the Microsoft docs:

Quick troubleshooting checklist: ensure the URL includes a scheme, check API return codes, test on target Windows versions, and avoid passing raw user input to system shells.

Recommended Answers

All 6 Replies

I think you would use the system() function. I'm no expert on the windows command line, but I think you can run programs from it. If so, you could pass a command to run firefox or ie, thought I'm not sure if you can pass the url as a command line parameter.

Once you know the web site, just spawn a process similar to below. Create a string like that, replacing DaniWeb.com with the site you want to go to. Note: this is on my Vista box so your browser might be in a different location on your computer. Right-clikc on your browser's shortcut then select properties. That will tell you the full path to your browser.

system("\"D:\Program Files\Internet Explorer\iexplore.exe\"  www.DaniWeb.com");

On Windows you can just put the website on the command line and it will open in the default browser, i.e. system("http://www.google.com");

On Windows you can just put the website on the command line and it will open in the default browser, i.e. system("http://www.google.com");

doesn't work on Vista

D:\Users\AncientDragon>www.daniweb.com
'www.daniweb.com' is not recognized as an internal or external command,
operable program or batch file.

D:\Users\AncientDragon>

Also tried other variations

Microsoft Windows [Version 6.0.6000]
Copyright (c) 2006 Microsoft Corporation. All rights reserved.

D:\Users\AncientDragon>www.daniweb.com
'www.daniweb.com' is not recognized as an internal or external command,
operable program or batch file.

D:\Users\AncientDragon>http://www.daniweb.com
'http:' is not recognized as an internal or external command,
operable program or batch file.

D:\Users\AncientDragon>"http://www.daniweb.com"
The filename, directory name, or volume label syntax is incorrect.

D:\Users\AncientDragon>

How about?

system("start www.google.com");
system("start http://www.google.com");

That worked on Vista.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.