Hey guys,
I'm having this problem of trying to open shortcuts, i.e (.lnk) files and am also trying to open powerpoint slideshows (.pps) files through turbo c++. It didn't work so what i did was write a .bat file to open those programs and then converted that .bat file to a .exe file. When double clicking the exe file runs great and is able to achieve what i want.
But when i call the file ( the executable file) through turbo c++ it tells me 'bad command or file name'.

The code i'm using to call the file is :

system("\"D:\\runsnake.exe\"");

The file runsnake.exe is actually the .bat file that is converted to .exe to run another program which is a game shortcut(.lnk)
The code used in the .bat file is :

"D:\snake.exe"

P.S - I am using turbo c++ as this is part of my school project and it has to be compiled using that...

First things first:
Why are you trying to open a .lnk file?
Why don't you just open what it points to?

First things first:
Why are you trying to open a .lnk file?
Why don't you just open what it points to?

Yea, i know sounds really stupid.. but im giving a link to the Microsoft games and i cant really find their executable files... So instead of searching my whole system for it, i just thought i'd make a shortcut and run that... After all the output is the same...
Im running Windows 7 Home Basic.. So u have any idea where those executables are? Coz that'd just avoid using the above.. But still, not deviating from the topic, why is the problem arising ?

P.S - I'd really like the location of those games

No, but if you browse to the link location and copy it from abcd.lnk to abcd.dat, you can then open it with notepad or Textpad and it will show you the location.

...since you'll only need to do that once, right?

No, but if you browse to the link location and copy it from abcd.lnk to abcd.dat, you can then open it with notepad or Textpad and it will show you the location.

...since you'll only need to do that once, right?

Umm... yea.. that was if i created the shortcut by copying the location or something.
If you go to the 'games' option in windows 7, it just shows u the games and there is no way to view their properties to figure out the location. So all i did was drag and drop the icon.. So a shortcut to the game was formed, which again doesnt show the location.

----------------- Deviating from the topic ------------------

Is there anything wrong with the syntax used to open the exe files using c++ ?

Is there anything wrong with the syntax used to open the exe files using c++ ?

Your example calls it Runsnake.exe, but it should be Runsnake.bat if it is a batch file.
Also, since it does not have spaces in the name, you do not need to wrap it in extra quotes.

Your example calls it Runsnake.exe, but it should be Runsnake.bat if it is a batch file.
Also, since it does not have spaces in the name, you do not need to wrap it in extra quotes.

I know i dont need to use spaces, but since in this case it doesnt reside in the parent directory i need to. Coz if i dont, it'll consider looking for an identifier, basically a function name(eg:start). I can avoid using it if i write the following :

start d:\runsnake.exe    (if writing directly in cmd)
system("start\ d:\\runsnake.exe");   ( if written in c++)

Regarding the batch file, i mentioned earlier, i wrote the batch file (.bat) and then converted it to a .exe using a program on the net... (I did this bcoz turbo c++ doesnt recognise .bat files)

I was talking about this:

system("\"D:\\runsnake.exe\"");

Dude ur not getting me...
runsnake.exe is an executable file which runs runsnake.bat which further runs snake.exe
So, in lehmans terms...

Runsnake.exe wakes up runsnake.bat to get up and give snake.exe a call to get up from sleep

Just look in the .lnk file or right-click and select Properties. Then copy the location right out of the link file and put it into your 'launch' program. Then you don't need all this Rube Goldberg crap.

An .exe to call a .bat file to call a .lnk file to open a program? Get real!

Just look in the .lnk file or right-click and select Properties.

I guess I was assuming that had already been done :$

Just look in the .lnk file or right-click and select Properties. Then copy the location right out of the link file and put it into your 'launch' program. Then you don't need all this Rube Goldberg crap.

An .exe to call a .bat file to call a .lnk file to open a program? Get real!

Dude.. u think i havent tried it ??
Try it for urself.. open games in windows 7 and drag and drop the freecell icon to the desktop.. It creates a shortcut... When u view the properties.. all it says is

Target Location : Games

But where the hell is games ?

And yes, i am... there is no other way to directly call a windows game other than call its shortcut from turbo c++, but it dusnt recognise .lnk files leaving me no choice... !!
Any other suggestions ?

-------------------------- Solved --------------------------
Thanks for the help guys anyways! Oh n yea, for all people with this problem...
You CANNOT run any other file other than executable files through C++ using the system and the spawnl function... If u would like to do that.. Do the following :

1) Open notepad and type the command you would use to open through Command Prompt and save as filename.bat (where filename is your files name) and save the type of the files to All files and the coding to ANSI

2)Download a program that converts .bat files to .exe files, hence allowing the file to become a .exe file(Yes, this doesnt sound real, but this is the only way i've come across it, please let me know if u find any other)

3)Call the exe file from c++ using system or spawnl and it works like magic !!

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.