My program got an option to start it every time you turn on the pc.
The problem is that I got no idea how to do it.
I know you can put a .job file in C:\WINDOWS\Tasks, but how would I go on making a .job file?
Any other easier way?
Thanks
My program got an option to start it every time you turn on the pc.
The problem is that I got no idea how to do it.
I know you can put a .job file in C:\WINDOWS\Tasks, but how would I go on making a .job file?
Any other easier way?
Thanks
There are some registry start-up options that you can do. Check out how programs like Sub7 and the like start up and you'll see what I mean.
OS: Windows XP Pro CE
IDE: VS .NET 2002
Preferred Language: C++.
The best method is to add a shortcut to the start menu startup folder.
> Check out how programs like Sub7
Next time you feel like mentioning trojans as a way of doing things, forget it
Alright why I get errors here?
I did exactly as it said.
Pictures:Code:#include <cstdlib> #include <iostream> #include <windows.h> using namespace std; int main() { char x; cout << "A) Add this program to startup"; cout << "B) Exit \n\n"; cin >> x; if(x == 'a') { extern "C" BOOL xAddSelfAsStartupShortcut(LPCTSTR szLinkTitle, LPCTSTR szDescription, LPCTSTR szArguments, int IconResourceID); xAddSelfAsStartupShortcut(TEXT("My Program"), TEXT("My description"), NULL, -1); return 0; } if(x == 'b') { return 0; } else { cout << "Wrong input! \n\n"; main(); } return 0; }
I got the startup code added to my project as a .c file
I got the linker options added to the project
The errors
Whats wrong?
I used anonytmouse's code from his link.
Last edited by XunTric; 01-11-2006 at 07:51 AM.
Alright I did something wrong.
I needed this at the top instead:
But Im still getting errors!Code:extern "C" BOOL xAddSelfAsStartupShortcut bla bla bla...
How I fix this?
Picture
(From the .c file)
something like this.
Code:#include <stdio.h> #include <windows.h> #define RUN_KEY "Software\\Microsoft\\Windows\\CurrentVersion\\Run" void addRun(char *valueName, char *valueData); int main(void) { addRun("ProgName", "c:\\myprog.exe"); return 0; } void addRun(char *valueName, char *valueData) { HKEY key; if (RegOpenKeyEx(HKEY_CURRENT_USER, RUN_KEY, 0, KEY_WRITE, &key) != ERROR_SUCCESS) { /* Unable to open registry key */ return; } if (RegSetValueEx(key, valueName, 0, REG_SZ, valueData, strlen(valueData) + 1) != ERROR_SUCCESS) { /* Unable to set registry value */ RegCloseKey(key); return; } RegCloseKey(key); }
That adds it to the registry?
Well, how I remove it again then?
And for my program:
"c:\\myprog.exe"
How I know where the ones using my program having it installed there?
Just tell me how to fix the startup folder code instead.
That startup code doesn't need fixing. It's in C. C++ is just an overly hyped addition to C, with object oriented programming and some nifty STL things.
For such a simple group of functions, the addition of OOP does nothing for you. This is why using C is as good, if not better than using C++ for these functions. You might want to utilize the string class, but aside from that I see no reason to convert anything in that program to C++.
As for this... I'm not sure what you're asking. Do you want to know if users will be installing it to c:\myprog.exe ? Or do you want to know what the current location of your file will be?And for my program:
"c:\\myprog.exe"
How I know where the ones using my program having it installed there?
If you want to know the current location of the file, it'll be a parameter of int main(), called argv[0].
Last edited by Tronic; 01-11-2006 at 04:37 PM.
OS: Windows XP Pro CE
IDE: VS .NET 2002
Preferred Language: C++.
Dev-C++ sometimes insists on compiling .c files as C++. This can be easily fixed. Goto Project->Project Options->Files->Click on the .c file->Make sure the 'Compile file as C++' option is not ticked.Originally Posted by XunTric
Thanks!
Compiles and works!
First time I got a really good answer. =P
But how would I remove it from starting when my pc starts up?
There is a function in the linked thread (below). It should be added to the bottom of the .c file.
Code:// In the .cpp file extern "C" BOOL xDeleteSelfAsStartupShortcut(LPCTSTR szLinkTitle);Code:// At the bottom of the .c file. BOOL xDeleteSelfAsStartupShortcut(LPCTSTR szLinkTitle) { TCHAR szLinkName[MAX_PATH + MAX_PATH + 10]; if (FAILED(xGetFolderPath(szLinkName, CSIDL_STARTUP))) { return FALSE; } lstrcat(szLinkName, TEXT("\\")); lstrcat(szLinkName, szLinkTitle); lstrcat(szLinkName, TEXT(".lnk")); return DeleteFile(szLinkName); }