Solved Shutting Down Command

Hexui Undetected CSGO Cheats PUBG Accounts

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

I'm not your friend
Administrator
Jan 21, 2014
12,981
78,998
2,464
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.
 
Community Mods