Force Shutdown XP ?

Hi experts, how can I force shutdown XP ?

Since I've tried :

ExitWindowsEx(EWX_SHUTDOWN or EWX_FORCE,0);

which doesn't work...
comicboyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ginsonicCommented:
listening
MadshiCommented:
Basically your code is correct. However:

First of all you need to be logged in with a user that has the right to shut XP down. Then you need to enable the right privilege. I was tired of this privilege problem, so I wrote a little function which simply enabled all privileges your current user has:

function EnableAllPrivileges : string;
var c1, c2, c3 : dword;
    ptp        : PTokenPrivileges;
    i1         : integer;
    arrCh      : array [0..MAX_PATH] of char;
begin
  result := '';
  if OpenProcessToken(windows.GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, c1) then
    try
      c2 := 0;
      GetTokenInformation(c1, TokenPrivileges, nil, 0, c2);
      if c2 <> 0 then begin
        ptp := AllocMem(c2);
        if GetTokenInformation(c1, TokenPrivileges, ptp, c2, c2) then begin
          for i1 := 0 to integer(ptp^.PrivilegeCount) - 1 do begin
            c3 := MAX_PATH;
            if LookupPrivilegeName(nil, ptp^.Privileges[i1].Luid, arrCh, c3) then
                 result := result + #$D#$A + arrCh + ' '
            else result := result + #$D#$A + '??? ';
            result := result + booleanToChar(ptp^.Privileges[i1].Attributes and SE_PRIVILEGE_ENABLED <> 0);
            ptp^.Privileges[i1].Attributes := ptp^.Privileges[i1].Attributes or SE_PRIVILEGE_ENABLED;
          end;
          AdjustTokenPrivileges(c1, false, ptp^, c2, PTokenPrivileges(nil)^, cardinal(pointer(nil)^));
        end;
        FreeMem(ptp);
      end;
    finally CloseHandle(c1) end;
  Delete(result, 1, 2);  
end;

Regards, Madshi.
DelFreakCommented:
Listening...
Announcing the Winners!

The results are in for the 15th Annual Expert Awards! Congratulations to the winners, and thank you to everyone who participated in the nominations. We are so grateful for the valuable contributions experts make on a daily basis. Click to read more about this year’s recipients!

comicboyAuthor Commented:
Hi Madshi your answer surely a tough one :) GREAT!!

I'm sure don't understand it since it's a very arcane one for me, anyway I'm trying it now.

What is booleanToChar ? I stuck there... please
MadshiCommented:
Ooops, sorry:

function BooleanToChar(bool: boolean) : string;
begin
  if bool then result := '+' else result := '-';
end;

Regards, Madshi.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
comicboyAuthor Commented:
Well Madshi GURU :) your code simply BULLET PROOF !!!

IT's WORK!!

Thanks you so much :) I'm glad I can shut down my win XP computer via my program, and this is very usefull :)

You are the best ever :)
comicboyAuthor Commented:
Well Madshi GURU :) your code simply BULLET PROOF !!!

IT's WORK!!

Thanks you so much :) I'm glad I can shut down my win XP computer via my program, and this is very usefull :)

You are the best ever :)
MadshiCommented:
:-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.