Solved Shutting Down Command

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

maptwo3

Newbie
Full Member
May 24, 2012
20
292
0
I'm not sure if this is the best place to put this, but oh well....

I'm trying to create a program that shuts my computer down after a specified amount of time. I figured everything out, but I believe you have to add parameters when you launch shutdown.exe so that it actually shuts down ("/s" and "/f"). This is what I have so far:

C++:
ShellExecute(NULL, NULL, "C:/Windows/System32/shutdown.exe", NULL, NULL, SW_SHOWNORMAL);
This launches notepad.exe and other programs just fine, so I'm assuming I would need a parameter for it.
Does anyone know how to add parameters to shutdown.exe? Or a better way to do this?

Thanks.
 

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,380
78,998
2,414
Use this

C++:
// Get the process token
HANDLE hToken;
OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
    &hToken);

// Build a token privilege request object for shutdown
TOKEN_PRIVILEGES tk;
tk.PrivilegeCount = 1;
tk.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
LookupPrivilegeValue(NULL, TEXT("SeShutdownPrivilege"), &tk.Privileges[0].Luid);

// Adjust privileges
AdjustTokenPrivileges(hToken, FALSE, &tk, 0, NULL, 0);

// Go ahead and shut down
InitiateSystemShutdownEx(NULL, NULL, 0, FALSE, FALSE, 0);
from Stack Overflow How to turn off pc via windows API?
 

maptwo3

Newbie
Full Member
May 24, 2012
20
292
0
I found out that you can shutdown your computer by using system("shutdown").

I'm still kinda wondering if its possible to do it the other way though.
 

maptwo3

Newbie
Full Member
May 24, 2012
20
292
0
How would I do it using createprocess? I would still need to add the parameters to the process for shutdown.exe to actually work.
 
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods