Click here to Skip to main content
15,904,346 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
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.

C++
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 20: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.

1 solution

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!
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900