🔒 Locked
Shuting down windows
Advertisement
Original Post
Does anyone know how I can shutdown windows from within my program? I''d like it to shut down correctly, but I''d actually go for anything that would render the computer useless for a bit (crash, whatever).
We have some public PC''s that people use at my work, and we have a problem with people not getting off of them while we''re about to close. It would be nice if I could write a program that would shut it down (or crash, or whatever) at a specified time each day so the person has to get off the computer. We get way too many "I''ll be done in 5 minutes I promise," only to come back in 5 minutes and get, "I''ll be done in 2 minutes I promise."
Surely there''s some way to render the system inactive, leaving only an option to shutdown or use a password to get back to the desktop, rather than causing it to crash which would be a bit nasty.
pan narrans
Study + Hard Work + Loud Profanity = Good Code
pan narrans
Study + Hard Work + Loud Profanity = Good Code
#include <windows.h>
void main ()
{
ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0);
}
I tried this, and it doesn''t do anything. I read msdn and it said the calling program has to have certain permissions in Win2k, and that''s what I''m running at home, but the machines at work have Win98. I''ll give it a try on my Win98 machine later today (have to go to school now). Thanks.
you have some public machines:
what operating system are you using? are they secure? do people have to log on to use them? are they on a network?
if they do then use your root privileges to limit how and when people can use them.
if not then putting a program on that will shut the machine down is useless because a user will be able to turn it off.
really, what i''d suggest is talking to the people and asking them to get off. you won''t win any friends if the machine crashes without warning.
rather than writing a program just go and give a warning that you will be turning the computers off in about 5 minutes and if they''re not off in 2 minutes there is a chance they''ll lose any work they are doing. if they complain just say, ''i''m being polite and you''re making my job difficult. at some point i won''t be able to be polite anymore. lets just leave it here, okay?''
what operating system are you using? are they secure? do people have to log on to use them? are they on a network?
if they do then use your root privileges to limit how and when people can use them.
if not then putting a program on that will shut the machine down is useless because a user will be able to turn it off.
really, what i''d suggest is talking to the people and asking them to get off. you won''t win any friends if the machine crashes without warning.
rather than writing a program just go and give a warning that you will be turning the computers off in about 5 minutes and if they''re not off in 2 minutes there is a chance they''ll lose any work they are doing. if they complain just say, ''i''m being polite and you''re making my job difficult. at some point i won''t be able to be polite anymore. lets just leave it here, okay?''
quote:
what operating system are you using? are they secure? do people have to log on to use them? are they on a network?
Windows 98, not secure (they have some thing that takes away the start button and disables right click), they don't have to log on (it's the library), and they have internet access if that qualifies as "on a network."
quote:
really, what i'd suggest is talking to the people and asking them to get off.
This is the problem. Computers are supposed to shut down 15 minutes before closing, and we make an announcement, and people simply won't get off and we have people staying after closing time every night. I guess I could carry around a baseball bat, or call the police every night, but I'd prefer to just have the machines shutdown automatically (or lock up, so the person has to get up).
This is beyond an "ask nicely" situation. I ask nicely, and most people get up within a few minutes. The problem is the few who just sit there like they didn't hear me after I've asked 4 or 5 times, then stay after closing time.
If all else fails I guess I can go turn the electricity off for the whole building for a moment
[edited by - Russell on December 10, 2002 3:23:40 PM]
here's the code to enable shutdown privilege.
[edited by - niyaw on December 10, 2002 7:06:18 PM]
inline BOOL TogglePrivilegeForToken(HANDLE TokenHandle, LPCTSTR PrivilegeName, BOOL Enable)
{
LUID luid;
if (!LookupPrivilegeValue(0, PrivilegeName, &luid))
return FALSE;
TOKEN_PRIVILEGES tp;
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = (Enable ? SE_PRIVILEGE_ENABLED : 0);
return AdjustTokenPrivileges(TokenHandle, FALSE, &tp, 0, 0, 0);
}
inline BOOL TogglePrivilegeForProcess(HANDLE ProcessHandle, LPCTSTR PrivilegeName, BOOL Enable)
{
HANDLE ProcessToken;
if (!OpenProcessToken(ProcessHandle, TOKEN_ADJUST_PRIVILEGES, &ProcessToken))
return FALSE;
BOOL ret = TogglePrivilegeForToken(ProcessToken, PrivilegeName, Enable);
CloseHandle(ProcessToken);
return ret;
}
// in your code
TogglePrivilegeForProcess(GetCurrentProcess(), SE_SHUTDOWN_NAME, TRUE);
ExitWindowsEx();
[edited by - niyaw on December 10, 2002 7:06:18 PM]
If they refuse to get off, try telling them your policy is to call the police if they don''t get off the computer by closing. Oh, and be sure to actually do it if they don''t.
You should probably check with the police to make sure you can really do this, but I think you can. Charge them with trespassing.
This is just an idea, and I have no idea how well it will work.
You should probably check with the police to make sure you can really do this, but I think you can. Charge them with trespassing.
This is just an idea, and I have no idea how well it will work.
quote:
Original post by Evil Bill
I think it''d be easier just to stand next to them with your finger on the power button...![]()
Don''t be silly! You wouldn''t be "shutting Windows down properly" which surely would result in you aquiring a large spanking from Colonel Microsoft! :0 :D
:::: Lektrix ::::
[ Google || ACCU || BarrysWorld || E-Mail Me ]
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement