Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to restart windows xp from vfp6 ?
Message
 
To
17/06/2003 01:32:13
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00800687
Message ID:
00800695
Views:
21
This message has been marked as the solution to the initial question of the thread.
I hope the mentioned below code should do your work.
Aashish
LPARAMETERS tlShutdownRequested, tlInteractiveShutdown
*  Default - reboot and force all apps to terminate without dialogs
*
*  Parameters:
*
*  tlShutdownRequested -   .T. Shuts down Windows, .F. (default) reboots
*  tlInteractiveShutdown - .T. Runs shutdown dialogs, .F. (default) forces exit

* This program will attempt to reboot Windows from within VFP;  it will make the API call to make
* necessary privilege adjustments to permit the reboot to occur under Windows NT 4.0 or Windows 2000
* if it can.  The function will return .F. if it is unable to make the required adjustment to the
* process token to permit the SE_SHUTDOWN_NAME privilege to be granted;  it will force a reboot of
* the system under Win9x or if the privilege is granted to VFP by the OS.  Tested under WinNT 4.0 SP6,
* Win2K Pro, Win98 and WinME.  It should work for VFP 5.0 or 6.0
*

*  Common constant definitions

#DEFINE SE_SHUTDOWN_NAME "SeShutdownPrivilege"   && Privilege to shut down windows
#DEFINE SE_PRIVILEGE_ENABLED 2                   && Enable privilege flag
#DEFINE TOKEN_QUERY 2                            && Token may query status
#DEFINE TOKEN_ADJUST_PRIVILEGE 0x20              && Token may adjust privileges
#DEFINE EWX_SHUTDOWN 1
#DEFINE EWX_REBOOT 2                             && Initiate a reboot
#DEFINE EWX_FORCE 4                              && Force processes to close
#DEFINE SIZEOFTOKENPRIVILEGE 16

*  Windows Shutdown API - all platforms
DECLARE ExitWindowsEx IN WIN32API INTEGER uFlags, INTEGER dwReserved && API call to shut down Windows

*  Check the OS to see if we need to request the privilege
IF  ('4.0' $ OS() OR '5.0' $ OS() OR 'NT' $ OS())
   *  API Calls below are NT/2K specific or only needed to manipulate process permissions
   
   *  Retrieve the LUID of a specific privilege name - changes each time Windows restarts
   DECLARE SHORT LookupPrivilegeValue IN ADVAPI32 ;
      INTEGER lpSystemName, ;
      STRING @ lpPrivilegeName, ;
      STRING @ pluid

   *  Get an hToken with specific permission sets for a given process handle
   DECLARE SHORT OpenProcessToken IN Win32API ;
      INTEGER hProcess, ;
      INTEGER dwDesiredAccess, ;
      INTEGER @ TokenHandle
   
   *  Alter the privileges granted to a Process via a specific hToken
   DECLARE INTEGER AdjustTokenPrivileges IN ADVAPI32 ;
      INTEGER hToken, ;
      INTEGER bDisableAllPrivileges, ;
      STRING @ NewState, ;
      INTEGER dwBufferLen, ;
      INTEGER PreviousState, ;
      INTEGER @ pReturnLength
   
   *  Get the Process handle for this process
   DECLARE INTEGER GetCurrentProcess IN WIN32API

   LOCAL cLUID, nhToken, cTokenPrivs, nFlag

   cLUID = REPL(CHR(0),8)  && 64 bit Locally Unique IDentifier for the Privilege

   IF LookupPrivilegeValue(0, SE_SHUTDOWN_NAME, @cLUID) = 0
      RETURN .F.  &&  Privilege not defined for this process
   ENDIF

   nhToken = 0  &&  Process Token to be used to manipulate process privilege set

   IF OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY + TOKEN_ADJUST_PRIVILEGE , @nhToken) = 0
      RETURN .F.  &&  OS will not grant handle with necessary rights
   ENDIF

   *  Create a TOKEN_PRIVILEGES structure, a 4 byte DWORD indicating # permissions,
   *  followed by an array of 8 byte LUIDs and the 4 byte DWORD permission attributes
   *  for it.  One privilege, the LUID retrieved for shutdown, enable attribute set
   cTokenPrivs = CHR(1) + REPL(CHR(0),3) + cLUID + CHR(SE_PRIVILEGE_ENABLED) + REPL(CHR(0), 3)
   IF AdjustTokenPrivileges(nhToken, 0, @cTokenPrivs, SIZEOFTOKENPRIVILEGE, 0, 0) = 0
      RETURN .F.  && Privilege denied
   ENDIF
ENDIF

CLOSE ALL    &&  Start shutting down VFP tables
FLUSH        &&  Suggest that the OS flush all buffers
CLEAR EVENTS &&  Avoid VFP being obstinate
ON SHUTDOWN  &&  don't try to run anything extra
*  Select shutdown flags
DO CASE
CASE tlShutdownRequested AND tlInteractiveShutdown
   nFlag = EWX_SHUTDOWN
CASE tlShutdownRequested
   nFlag = EWX_SHUTDOWN + EWX_FORCE
CASE tlInteractiveShutdown
   nFlag = EWX_REBOOT
OTHERWISE
   nFlag = EWX_REBOOT + EWX_FORCE
ENDCASE
=ExitWindowsEx(nFlag, 0)  && Force a reboot to be initiated
QUIT  &&  Start an orderly shutdown of VFP 
>How to restart windows xp from vfp6 ?
>
>Thanks for your help.
>
>Martin
--
--
Aashish Sharma
Tele Nos: +1-201-490-5405
Mobile: +91-9821053938
E-Mail:
aashish@aashishsharma.com
write2aashish@gmail.com

You better believe in yourself... if you don't, who else will ?
TODAY is a gift, that's why it's called PRESENT
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform