Hey, I have a slight problem. I have managed to figure out how to copy and move files to XP's start up folder, and in some accounts Vista's startup folder. Now with Vista I can successfully copy and move the file to my own user account, but how do I move it to a another users account if I don't know the name?

CopyFile("welcome.exe","C:\\Users\\miclo\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\welcome.exe",0);

That works fine, but like I said, how do I do it if I don't know the users name? I have googled and found very few places that mention something about it but I'm finding it very hard to understand.

I hope you understand what I am trying to do, if not as a small example:

C:\\Users\\*\\AppData\\Roaming\\
C:\\Users\\%s\\AppData\\Roaming\\

Kind of like wildcards and matches, but what actually works in C++, this is a win32 app just in case you need to know, not an MFC.

Recommended Answers

All 3 Replies

Hey, I have a slight problem. I have managed to figure out how to copy and move files to XP's start up folder, and in some accounts Vista's startup folder. Now with Vista I can successfully copy and move the file to my own user account, but how do I move it to a another users account if I don't know the name?

CopyFile("welcome.exe","C:\\Users\\miclo\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\welcome.exe",0);

That works fine, but like I said, how do I do it if I don't know the users name? I have googled and found very few places that mention something about it but I'm finding it very hard to understand.

I hope you understand what I am trying to do, if not as a small example:

C:\\Users\\*\\AppData\\Roaming\\
C:\\Users\\%s\\AppData\\Roaming\\

Kind of like wildcards and matches, but what actually works in C++, this is a win32 app just in case you need to know, not an MFC.

To get user name:

char COMPNAME[MAX_COMPUTERNAME_LENGTH +1];
DWORD cbCOMPNAME = sizeof(compNAME);

GetComputerName(COMPNAME, &CBCOMPNAME);

or just add it here: HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run\\YourProjectName

also to get AppData path its as simple as char *appdata = getenv("APPDATA")

Why are you trying to do this? I hope you aren't trying to write a virus :\

Thanks for the help.

Also no, I am not writing a virus. I'm just trying to make a few small exclusive programs for our pro account members and one idea I had was for a simple welcome speech message, and while I don't know that much about C++ yet, I thought it would be a good idea to add to starup so they can easily remove it. Plus it helps me learn more.

Thanks again for the help.

It might be easier to create your program for everyone, and when it loads, check to see if the current user is a pro account. If he/she is, then display the message, otherwise exit. Just put the check before the main form appears, so nothing pops on the screen if you don't want to be seen.

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.