Delphi Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
델파이 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
FreePascal/Lazarus
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
델마당
볼랜드포럼 광고 모집

델파이 Q&A
Delphi Programming Q&A
[2497] [기타] 시스템을 학실히(?) 죽이는법
나우시스 [ ] 1636 읽음    1998-04-22 07:44
예전에 제가 시스템을 학실히(?) 죽일려고 했던적이 있었는데,
실력이 딸려서 포기한 적이 있습니다.
우연히 인터넷에서 관련 자료가 있어서 올립니다.
시스템을 도저히 살려둘수가 없는분은 참고하시기 바랍니다.

Some programs require Windows to be restarted once it is installed
              on the system for the first time. If your program has a similar need,
              you could use the following function -- WinExit() -- to shut down
              Windows, restart Windows, or log off the current user from Windows.

              function SetPrivilege(
                sPrivilegeName : string;
                bEnabled : boolean )
                  : boolean;
              var
                TPPrev,
                TP         : TTokenPrivileges;
                Token      : THandle;
                dwRetLen   : DWord;
              begin
                Result := False;

                OpenProcessToken(
                  GetCurrentProcess,
                  TOKEN_ADJUST_PRIVILEGES
                  or TOKEN_QUERY,
                  @Token );

                TP.PrivilegeCount := 1;
                if( LookupPrivilegeValue(
                      Nil,
                      PChar( sPrivilegeName ),
                      TP.Privileges[ 0 ].LUID ) )then
                begin
                  if( bEnabled )then
                  begin
                    TP.Privileges[ 0 ].Attributes  :=
                      SE_PRIVILEGE_ENABLED;
                  end else
                  begin
                    TP.Privileges[ 0 ].Attributes  :=
                      0;
                  end;

                  dwRetLen := 0;
                  Result := AdjustTokenPrivileges(
                              Token,
                              False,
                              TP,
                              SizeOf( TPPrev ),
                              TPPrev,
                              dwRetLen );
                end;

                CloseHandle( Token );
              end;

              //
              // iFlags:
              //
              //  one of the following must be
              //  specified
              //
              //   EWX_LOGOFF
              //   EWX_REBOOT
              //   EWX_SHUTDOWN
              //
              //  following attributes may be
              //  combined with above flags
              //
              //   EWX_POWEROFF
              //   EWX_FORCE    : terminate processes
              //
              function WinExit( iFlags : integer ) : boolean;
              begin
                Result := True;
                if( SetPrivilege( 'SeShutdownPrivilege', True ) )then
                begin
                  if( not ExitWindowsEx( iFlags, 0 ) )then
                  begin
                    // handle errors...
                    Result := False;
                  end;
                  SetPrivilege( 'SeShutdownPrivilege', False )
                end else
                begin
                  // handle errors...
                  Result := False;
                end;
              end;



              WinExit() function was desinged to be used with 32 bit Windows
              programs (Win32) and it does not support restarting Windows without
              rebooting or logging off. If you're writing a program that will be run
              under Windows 3.x or Windows 95 and you want to restart windows
              without rebooting the machine (after installing device drivers, for
              example), you can use ExitWindows() Win16 function (don't forget to
              add WinProcs and WinTypes units to your uses section):

              ExitWindows( EW_RESTARTWINDOWS, 0 );


               .


+ -

관련 글 리스트
2497 [기타] 시스템을 학실히(?) 죽이는법 나우시스 1636 1998/04/22
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.