Click here to Skip to main content
14,360,151 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hey, I want to make my program to restart the pc and then play sound.
My Current program is not playing sound after a restart, i have added the program to Startup Folder but it still does not work, someone tell me that the program will not continue after a restart, so how can i do this ?

I want to do like this.

int main()
{
	system("c:\\windows\\system32\\shutdown /r /t 10 \n\n");
	while (true)
	{
		PlaySound(*pathtosound*, NULL, SND_SYNC);
	}
	return 0;
}


What I have tried:

I already tried to add this to StartUp Folder but still not working.
Posted
Updated 8-Nov-19 21:42pm
Comments
ZurdoDev 8-Nov-19 16:28pm
   
1. When the system shuts down how will your sound play?
2. while (true) just means it will play the sound forever, no?
3. It looks like you're trying to write some kind of malware.
[no name] 8-Nov-19 16:29pm
   
1. Okay, so how can i perform playsound function after a restart ?
2. Yes, i want to do this.

Thanks!
ZurdoDev 8-Nov-19 16:32pm
   
1. Put your code in startup, but don't shut the system down in your code.
2. Why? It will lock up your pc.
[no name] 8-Nov-19 16:34pm
   
But i must to restart my PC, my program wont work if i dont restart my PC.
What do you mean by lock up my PC?
ZurdoDev 8-Nov-19 16:38pm
   
1. Why must you restart the pc?
2. And if you must, then write a reg key to store that the next time it comes up it won't run the code for system shutdown. Then reset the flag.
3. Lock up because the code will consume the processor over and over.
4. Why do you want to do any us this? There can't be a good reason.
[no name] 8-Nov-19 16:42pm
   
My program is running at startup and installing files like all the other programs, it must restart for finish installation.
When the program runs it playing a background, they always can stop it by kill the program with taskmanager or just disable it from running at startup.
ZurdoDev 8-Nov-19 17:03pm
   
Then you need to play the music on an asynchronous thread.

I'd recommend using an actual installer package instead of trying to do it on your own. There are ones built that can manage this for you.
Dave Kreskowiak 8-Nov-19 19:44pm
   
"Like all other programs"?? Uhhh.... no, programs running at startup usually do NOT install files.

INSTALLERS will install files and possibly require a restart, but just running an application does not do this.

The rest of what you just posted made no sense at all.

There's a ton of stuff you're not telling us, but worse yet, you're using the wrong terminology and don't know how Windows works.
[no name] 8-Nov-19 16:36pm
   
I saw your edit , lol how can i make a malware by just restarting my pc and play sound ?
Richard MacCutchan 9-Nov-19 3:39am
   
Look at your code:
1. Call shutdown.
2. Play a sound.
So if this app is in the Startup set, what is the first thing it will do when startup runs it?

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

You can't shutdown the computer and then do something - shutdown is just that, it unloads all open apps, closes all files, and turns off the computer. It's like turning the power off at the mains!

If you want to play a sound when the system restarts after you shut it down, then you get your app to play on startup and check a flag you saved in a disk file. If it's set, you clear it and play a sound.
If it isn't, you shut the system down.

But ... apps that shut the system are generally a bad idea - they annoy users a massive amount as you have no idea what else they are using the system for, or in the middle of doing. I'd strongly suggest that you avoid doing it at all: I'd uninstall your app with extreme prejudice if it did that on my system!
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100