HelpI'm newbie programmer... I need some help.

Posts 1–7 of 7 · Page 1 of 1
I'm newbie programmer... I need some help.
Hi, I'm starting to get around to starting a program, and I'm working on a program that will start some of my applications for me. NOW, the code below does just that, it does exactly what I want it to do expect the fact that it wont start steam or utorrent for some reason ! But the problem is is that I wan't this program to automatically start on login, start up , or what have you. I've been looking around for some answers over the internet but everything seems a bit vague. If anyone would know how to do this I'd be appreciative . If it makes any difference I use vs_ultimate 2013 :/


Code:
#include <iostream>
#include <Windows.h>
using namespace std;


void Message()
{
	HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(h, FOREGROUND_RED | FOREGROUND_INTENSITY);
	cout << "Welcome Swakwan. How was your day?" << endl;
	cout << "You prorgram will begin in one second." << endl;

}
void StartProgram(string filename)
{
	ShellExecute(NULL, "open", filename.c_str(), NULL, NULL, SW_SHOWNORMAL);
}
void Programs()
{
	StartProgram("chrome.exe");
	StartProgram("steam.exe");
	StartProgram("utorrent.exe");
	StartProgram("devenv.exe"); //name is visual studio
	StartProgram("iTunes.exe");
}
int main()
{
	Message();
	Programs();
	system("pause");
	return 0;
}
Quote Originally Posted by swakwan11 View Post
.
utorrent is uTorrent.exe

maybe same case with steam? I don't have it installed. (I think spelling is correct; see below)
Does "steam.exe" expect command-line arguments? Right Click on your shortcut to the game and check the path.

ex.
C:\Users\...\uTorrent\uTorrent.exe <-- no command-line-arguments being passed to the program
C:\Users\...\uTorrent\uTorrent.exe -option1=true -option2=true <--2 are being passed
->ShellExecute has a parameter for 'command line arugments' if that's the issue.

------------------------------------------------
There are 2 ways (that I can think of) to have a program start on Login

Putting it in the "Startup" folder. (I can't remember folder path)
Adding a registry key (where? I can't remember) - I think there is a separate location for "All Users" and "1 specific user".

edit: not sure how I missed that...you're not using absolute file paths..how could it know which file to run? What if multiple files have the same name? ..I'd use absolute file paths, or do as mentioned below.
I think I understand what you are saying. Do you mean like StartProgram("C:\Users\..\uTorrent *blah blah blah*?
Quote Originally Posted by abuckau907 View Post
utorrent is uTorrent.exe

maybe same case with steam? I don't have it installed. (I think spelling is correct; see below)
Does "steam.exe" expect command-line arguments? Right Click on your shortcut to the game and check the path.

ex.
C:\Users\...\uTorrent\uTorrent.exe <-- no command-line-arguments being passed to the program
C:\Users\...\uTorrent\uTorrent.exe -option1=true -option2=true <--2 are being passed
->ShellExecute has a parameter for 'command line arugments' if that's the issue.

------------------------------------------------
There are 2 ways (that I can think of) to have a program start on Login

Putting it in the "Startup" folder. (I can't remember folder path)
Adding a registry key (where? I can't remember) - I think there is a separate location for "All Users" and "1 specific user".

edit: not sure how I missed that...you're not using absolute file paths..how could it know which file to run? What if multiple files have the same name? ..I'd use absolute file paths, or do as mentioned below.
The Windows file system is case insensitive. The real reason why you cannot run Steam or µTorrent is that these applications do not have an App Paths subkey. For starting an application on login, modify the Run key.
Quote Originally Posted by swakwan11 View Post
I think I understand what you are saying. Do you mean like StartProgram("C:\Users\..\uTorrent *blah blah blah*?

yes that's what I meant..usually you use an absolute file path unless the file is in the same directory as the program.

try it and find out.
I'm not saying that wont work, but I think I guess I'll have to change something outside the function for me not to get syntax error. Thanks you
edit: Do you mean put that in the void StartProgram() or the StartProgram :/
Quote Originally Posted by abuckau907 View Post
yes that's what I meant..usually you use a absolute file path unless the file is in the same directory as the program.

try it and find out.
Relative file path vs. absolute file path


void Programs()
{
StartProgram("chrome.exe");
StartProgram("steam.exe");
StartProgram("utorrent.exe");
StartProgram("devenv.exe"); //name is visual studio
StartProgram("iTunes.exe");
}
^^All 'relative' paths, not 'absolute'.
...How on earth could the PC know where the file is located/ if it found the correct one?
...it can't! Use absolute file paths.

change them to absolute paths:
void Programs()
{
StartProgram("firefox.exe"); <-- RELATIVE. what directory is this in?

vs.

StartProgram("C:\Program Files (x86)\Mozilla Firefox\firefox.exe"); <-- ABSOLUTE. we know which directory.
}
 
rant

Quote Originally Posted by swakwan11 View Post
...
edit: Do you mean put that in the void StartProgram() or the StartProgram :/
Read a f***ing book and learn the difference : ) ...that's basic language stuff that you SHOULD learn when learning the language, not half way through your "first major project."
Posts 1–7 of 7 · Page 1 of 1

Post a Reply

Similar Threads

Talk with us