cplusplus.com cplusplus.com
cplusplus.com   C++ : Forums : Windows Programming : system() command on vista
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Forums
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Articles
Lounge
Jobs

-

post  system() command on vista

ekw
Hello, ive searched many times and i cannot find a solution to my issue.
Im creating a program that starts on startup, launching programs after x seconds.
But i have an issue when i use system()
1
2
      system ("C:\\PROGRA~1\\vistaa~1\\val.exe"); //Works ok
      system ("C:\\PROGRA~1\\windows sidebar\\sidebar.exe"); //Fails to work 


when i dont use shortnames,

system("C:\\program files\\...")

i get an error message C:\PROGRAM' is not recognized as an internal or external command, operable program or batch file.

i cant use the shortname for windows sidebar because there are 8 other's that begin with window, and window~8 doesnt work goes up to ~4

any solution other than renaming things or launching shortcuts?
Thanks for the help!
|
Grey Wolf
you could try:
system("\"C:\\program files\\...\"")

ie put \" at each end of your string.
|
soldstatic
i think you need to escape the spaces. ie
system("C:\\program files\\...")
becomes
system("C:\\program\ files\\...")
|
rpgfan3233
Grey Wolf's suggestion should work. I don't think escaped spaces shouldn't work in Windows because of the fact that '\' is the directory separator in Windows, and using the single '\' like that in C makes it think it is an escape sequence, which it isn't. In fact, gcc prints a warning when I use
system("dir C:\\Program\ Files");

Output:
test.c:5:10: warning: unknown escape sequence: '\040'

040 is the octal representation of the decimal number 32, which corresponds to the space character. Obviously that means it won't work either.

Grey Wolf's suggestion works though:
system("dir \"C:\\Program Files\"");

Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 Volume in drive C has no label.
 Volume Serial Number is 42E9-9C76

 Directory of C:\Program Files

2008-04-27  14:47    <DIR>          .
2008-04-27  14:47    <DIR>          ..
2008-02-20  01:56    <DIR>          CCleaner
2008-01-04  19:08    <DIR>          Java
2008-04-22  21:47    <DIR>          Microsoft Office
2008-03-04  10:51    <DIR>          Notepad++
2008-03-18  19:46    <DIR>          Safari
2008-01-01  21:50    <DIR>          Skype
2008-04-20  23:49    <DIR>          The World
2008-01-02  03:27    <DIR>          Unlocker
               0 File(s)              0 bytes
              15 Dir(s)   2,040,344,576 bytes free
|

Registered users can reply in this forum.
Home page | Privacy policy
© cplusplus.com, 2000-2008 - All rights reserved - v2.2
Spotted an error? contact us