There are at least two wrong things here:
- you are using
system() ; - You hardcode the path.
For the first problem, I wrote a long story for a long time, you can look at it here ; a long story, in order to start the process, you have to go with the platform-specific way, namely in Windows, CreateProcess or, if you want to open the file using the application associated with it, ShellExecute .
For the second problem, you assume (1) that c:\windows exists, (2) that it is the Windows directory of the current Windows instance, (3) that notepad.exe actually exists, and (4) that it is in such a directory.
While notepad.exe is pretty much guaranteed to exist with every Windows installation, it is not clear where to look for it. Since Windows 3.0 it was in the Windows directory, but in the NT family it remained in the system32 subdirectory. Thus, from some version of Windows, Microsoft placed two copies of notepad, both in the windows directory and in the system32 directory (see this blog ).
Additional fun: a copy was deleted from Windows Server 2008 from the Windows directory (the link is, by the way, the message header What idiot will hardcode the path to Notepad?: :D ), so your program will not be able to open notepad , even if Windows is in c:\windows .
But the biggest problem is that Windows is not guaranteed to install in c:\windows ; on every Windows NT family prior to Windows XP, it was actually installed by default in c:\winnt , so your code will not work here.
In addition, if you have more than one copy of Windows installed (for example, Windows 7 64 bit on c: 32-bit version of Windows XP on d: c:\windows may actually exist, but may contain a copy of Windows other than the one is currently running, so you open notepad from another copy of Windows (and if this copy is 64-bit and the working one is 32 bit, it will not work).
This can happen when installing Windows on a disk that already contains the windows directory; in this case, the installation will put Windows in the Windows(01) directory Windows(01) (or something like that), and c:\windows may be empty.
Shortly speaking:
avoid using system : among other disadvantages, in all of these scenarios your application would have no clue that notepad not starting;
avoid hardcoded paths: c:\windows not guaranteed; if you need to get the path to the Windows directory, you can expand the environment variable %windir% (or %systemroot ) or use the GetWindowsDirectory API;
if your application is in PATH , you can take advantage of this fact: the windows and system32 directory is in the PATH environment variable, which means that if you just try to start notepad , you can avoid specifying the full path; on the other hand, you are exposed to vulnerabilities if an attacker puts a dangerous application in the working directory of your application;
if you want to open the file, use ShellExecute : it will automatically open this file with the corresponding application.