Announcement

Collapse
No announcement yet.

GUI to reboot with count down timer and included abort reboot option

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • GUI to reboot with count down timer and included abort reboot option

    program runs one instance to reboot the computer this runs on using a countdown timer
    GUI runs on top and cannot be exited with normal close windows options once the reboot timer has started.
    There are two ways in the program to start the count down timer and each is preset and only one is made available hard coded.

    I would suppose there could be an action inserted to send reboot notice to other programs but this one does not have in one of the ways
    because it just uses the ExitWindowsEx API.
    The other option uses the InitiateSystemShutdown API and can be set but this code uses the ExitWindowsEx API.
    One variable controls which one you chose.
    I am not sure why my computer had some issues when i used the InitiateSystemShutdown API.
    I wrote a console program that does an immediate reboot using the ExitWindowsEx API and I never had a problem with a computer rebooting except
    when a computer component had apparently failed in the computer while it was running.
    One issue was a bad power supply had gone bad and another was where a secondary hard drive did not spin back up on a SATA connection.
    I do not remember the other times but it was hardware failure and it was recognize when the computer was booting.
    Code:
    'rbootnow.bas
    'compiled with powerbasic pbwin90
    
    'credit to Scott Turchin for reboot                                       http://www.powerbasic.com/support/pbforums/showthread.php?t=015320
    'credit to Gary Beene    for stopping duplicate instance                  http://www.powerbasic.com/support/pbforums/showthread.php?t=042789
    'credit to Dave Biggs    for mouse over label simulating a button control http://www.powerbasic.com/support/pbforums/showthread.php?t=049944
    'set the reboot method using variable g_irebootstarted to 1 or 2
    'search for reboot-method to find where the variable is set
    '1 is set the reboot method countdowntimer using  InitiateSystemShutdown
    '2 is set the reboot method with a countdowntimer using ExitWindowsEx( %EWX_REBOOT, 0 )
    
    
    #COMPILE EXE
    #DIM ALL
    
    #RESOURCE "rbootnow.pbr"
    #INCLUDE ONCE "WIN32API.INC"
    #INCLUDE ONCE "COMMCTRL.INC"
    
    %IDD_DIALOG1  =  101
    %IDC_LABEL1   = 1001
    %IDC_LABEL2   = 1002
    %IDC_TEXTBOX1 = 1003
    %IDC_LABEL3   = 1004
    %IDC_LABEL4   = 1005
    
    
    %TOKEN_ADJUST_PRIVILEGES = &H20
    %TOKEN_QUERY = &H8
    %SE_PRIVILEGE_ENABLED = &H2
    
    GLOBAL g_irebootstarted AS LONG
    GLOBAL g_iseconds_till_reboot AS LONG
    GLOBAL g_hFont1 AS DWORD
    GLOBAL g_hFont2 AS DWORD
    GLOBAL g_hFont3 AS DWORD
    
    'Gary Beene's instance tester
    FUNCTION InstanceTest() AS LONG
       'returns 0 if instance exits or cannot create mutex. otherwise returns 1.
       LOCAL UniqueName AS ASCIIZ * %Max_Path
       UniqueName = LCASE$(EXE.NAMEX$)
       IF CreateMutex(BYVAL %Null, 0, UniqueName) = 0 OR GetLastError = %ERROR_ALREADY_EXISTS THEN EXIT FUNCTION  ELSE FUNCTION = 1
    END FUNCTION
    
    
    FUNCTION IsNt()  AS LONG
        'returns %TRUE on NT and Win2000
        DIM tOsVersion AS OSVERSIONINFO
    
        tOsVersion.dwOSVersionInfoSize = SIZEOF(tOsVersion)
        IF ISTRUE(GetVersionEx(tOsVersion)) THEN
            FUNCTION = (tOsVersion.dwPlatformId = %VER_PLATFORM_WIN32_NT)
        END IF
    END FUNCTION
    
    FUNCTION GetPrivilege( Privilege AS ASCIIZ ) EXPORT AS LONG
        LOCAL hdlProcessHandle    AS LONG
        LOCAL hToken              AS LONG
        LOCAL tmpLuid             AS LUID
        LOCAL tp                  AS TOKEN_PRIVILEGES
        LOCAL tpNBI               AS TOKEN_PRIVILEGES
        LOCAL BufferLength        AS LONG
        LOCAL lBufferNeeded       AS LONG
    
        hdlProcessHandle = GetCurrentProcess()
        CALL OpenProcessToken( hdlProcessHandle, (%TOKEN_ADJUST_PRIVILEGES OR %TOKEN_QUERY), hToken )
    
        ' Get the LUID for the privilege.
        LookupPrivilegeValue "", Privilege, tmpLuid
        tp.PrivilegeCount = 1
    
        ' One privilege to set
        tp.Privileges(0).pLuid = tmpLuid
        tp.Privileges(0).Attributes = %SE_PRIVILEGE_ENABLED
    
        ' Enable the privilege in the access token of this process.
        BufferLength = SIZEOF(tpNBI)
        FUNCTION= AdjustTokenPrivileges( BYVAL hToken,BYVAL 0,tp,BYVAL BufferLength ,tpNBI,lBufferNeeded )
    END FUNCTION
    
    
    FUNCTION TimerProc( BYVAL hDlg AS LONG, BYVAL Msg AS LONG, BYVAL EvntID AS LONG, BYVAL Time AS LONG ) AS LONG
        STATIC istarttimer AS LONG
        STATIC inowtimerprior AS LONG
        LOCAL inowtimer AS LONG
        LOCAL icountdownseconds AS LONG
        LOCAL iday AS LONG
        LOCAL ihour AS LONG
        LOCAL iminute AS LONG
        LOCAL isecond AS LONG
    
        IF g_irebootstarted=0& THEN EXIT FUNCTION
        IF istarttimer THEN
            inowtimer=TIMER
            IF inowtimer<istarttimer THEN inowtimer+=86400&
            IF inowtimer=inowtimerprior THEN
                EXIT FUNCTION
            ELSE
                inowtimerprior=inowtimer
            END IF
            icountdownseconds=istarttimer+g_iseconds_till_reboot-inowtimer
            isecond=icountdownseconds
            IF isecond>86399& THEN
                     iday=isecond \86400&
                     isecond-=iday*86400&
            END IF
            IF isecond>3599& THEN
                     ihour=isecond \3600&
                     isecond-=ihour*3600&
            END IF
            IF isecond>59& THEN
                     iminute=isecond \60&
                     isecond-=iminute*60&
            END IF
    
            IF iday THEN
                CONTROL SET TEXT hDlg, %IDC_LABEL4,TRIM$(STR$(iday))+ " day "+$CRLF+TRIM$(STR$(ihour))+ ":"+TRIM$(STR$(iminute))+ ":"+TRIM$(STR$(isecond))
                ELSEIF ihour THEN
                CONTROL SET TEXT hDlg, %IDC_LABEL4,TRIM$(STR$(ihour))+" hour"+$CRLF+RIGHT$("0"+TRIM$(STR$(iminute)),2)+ ":"+RIGHT$("0"+TRIM$(STR$(isecond)),2)
                ELSEIF iminute THEN
                CONTROL SET TEXT hDlg, %IDC_LABEL4,TRIM$(STR$(iminute))+ ":"+RIGHT$("0"+TRIM$(STR$(isecond)),2)
                ELSE
                CONTROL SET TEXT hDlg, %IDC_LABEL4,TRIM$(STR$(isecond))+" seconds"
            END IF
            CONTROL REDRAW  hDlg, %IDC_LABEL4
        ELSE
            istarttimer=TIMER
            EXIT FUNCTION
        END IF
        IF g_irebootstarted<2& THEN EXIT FUNCTION
    
        IF icountdownseconds<1& THEN
            g_irebootstarted=0&
            rebootcomputerusing_exitwindowsex
            EXIT FUNCTION
        END IF
    END FUNCTION
    
    DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
    DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
    
    FUNCTION PBMAIN()
        LOCAL stemp AS STRING
    
        IF INSTR(COMMAND$,"?") THEN
            ? "place reboot count down in seconds up to 172799 on the command tail"
            EXIT FUNCTION
        END IF
         'Gary Beene's instance checker
        IF InstanceTest = 0 THEN EXIT FUNCTION  ' check for a second instance running and if so, exit
        'check for windows operating system and if not NT and if is not then exit
        LOCAL vi                AS OSVERSIONINFO
        vi.dwOsVersionInfoSize = SIZEOF(vi)
        GetVersionEx vi
        IF vi.dwPlatformId <> %VER_PLATFORM_WIN32_NT THEN
            ? "This program will not run on this system"
            EXIT FUNCTION
        END IF
        IF GetPrivilege("SeShutdownPrivilege") = %FALSE THEN
             ? "This program is not able to acquire the correct privildges to run"
                EXIT FUNCTION
        END IF
    
        'check for counter down timer in seconds was given on the comamnd line
        'use a default of 30 seconds if none igiven
        stemp=TRIM$(COMMAND$(1))
        IF REMOVE$(stemp,ANY "0123456789") = "" THEN g_iseconds_till_reboot=VAL(stemp)
        IF g_iseconds_till_reboot>172799& THEN
            ? "Seconds cannot be larger that 172799, basically less than 2 days"
                EXIT FUNCTION
        END IF
        IF g_iseconds_till_reboot<1& THEN g_iseconds_till_reboot=30&
        IF g_iseconds_till_reboot<10& THEN g_iseconds_till_reboot=10&
    
        ShowDIALOG1 %HWND_DESKTOP
    END FUNCTION
    
    FUNCTION abortreboot() AS LONG
        LOCAL l_Result          AS LONG
        LOCAL lpPrivilege      AS ASCIIZ * 20
        LOCAL lpMachineName    AS ASCIIZ * 25
        LOCAL lpMessage        AS ASCIIZ * 50
    
        IF  g_irebootstarted=2& THEN
            g_irebootstarted=0&
            EXIT FUNCTION
        END IF
    
        lpPrivilege = "SeShutdownPrivilege"
        l_Result = GetPrivilege(lpPrivilege)
        'l_Result = GetComputerName(lpMachineName, SIZEOF(lpMachineName))
        'lpMessage = "This computer will reboot in 100 seconds"
        'l_Result = InitiateSystemShutdown(lpMachineName, lpMessage, 100, %TRUE, 1) 'Force,Reboot
        'l_Result = AbortSystemShutdown(lpMachineName)
        l_Result = AbortSystemShutdown("")
        g_irebootstarted=0&
    END FUNCTION
    
    
    FUNCTION rebootcomputerusingInitiateSystemShutdown() AS LONG
        LOCAL l_Result          AS LONG
        LOCAL lpPrivilege      AS ASCIIZ * 20
        LOCAL lpMachineName    AS ASCIIZ * 25
        LOCAL lpMessage        AS ASCIIZ * 50
    
        lpPrivilege = "SeShutdownPrivilege"
        l_Result = GetPrivilege(lpPrivilege)
        'l_Result = GetComputerName(lpMachineName, SIZEOF(lpMachineName))
        'lpMessage = "This computer will reboot in"+str$(g_iseconds_till_reboot)+"seconds"
        'l_Result = InitiateSystemShutdown(lpMachineName, lpMessage, 100, %TRUE, 1) 'Force,Reboot
        l_Result = InitiateSystemShutdown("", lpMessage, g_iseconds_till_reboot, %TRUE, 1) 'Force,Reboot
    END FUNCTION
    
    
    FUNCTION rebootcomputerusing_exitwindowsex() AS LONG
          CALL ExitWindowsEx( %EWX_REBOOT, 0 )
    END FUNCTION
    
    
    
    
    CALLBACK FUNCTION ShowDIALOG1Proc()
        STATIC hTimer AS LONG
        LOCAL hC AS DWORD
        LOCAL stextbox AS STRING
    
        SELECT CASE AS LONG CB.MSG
            CASE %WM_INITDIALOG
                ' Initialization handler
                STATIC hFont1, lID AS LONG
                lID = %IDC_TEXTBOX1
                SetWindowPos CBHNDL, %HWND_TOPMOST, 0,0,0,0, %SWP_NOMOVE OR %SWP_NOSIZE
                hTimer = SetTimer( CBHNDL, 1, 250, CODEPTR(TimerProc) )
    
            CASE %WM_NCACTIVATE
    
                STATIC hWndSaveFocus AS DWORD
                IF ISFALSE CB.WPARAM THEN
                    ' Save control focus
                    hWndSaveFocus = GetFocus()
                ELSEIF hWndSaveFocus THEN
                    ' Restore control focus
                    SetFocus(hWndSaveFocus)
                    hWndSaveFocus = 0
                END IF
                    CASE %WM_SETCURSOR                        ' Change cursor over label..
    
         SELECT CASE AS LONG GetDlgCtrlId(CBWPARAM)
            CASE %IDC_LABEL1, %IDC_LABEL2
              lID = GetDlgCtrlId(CBWPARAM)
              hC = SetCursor(LoadCursor(%NULL, BYVAL %IDC_HAND))
              CONTROL SET FONT CBHNDL, lID, hFont1
              CONTROL REDRAW CBHNDL, lID
              FUNCTION = 1
            CASE ELSE
              SetCursor hC                        ' <- set old cursor back
              CONTROL SET FONT CBHNDL, lID, 0
              CONTROL REDRAW CBHNDL, lID
          END SELECT
    
    
            CASE %WM_COMMAND
                IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN    ' (%STN_CLICKED = %BN_CLICKED)
                    SELECT CASE AS LONG CBCTL
                        CASE %IDC_LABEL1
                         IF g_irebootstarted=0& THEN
                            CONTROL GET TEXT CBHNDL, %IDC_TEXTBOX1 TO stextbox
                            IF UCASE$(TRIM$(stextbox))="BOOT" THEN
                                ' reboot-method
                                'set the reboot method using variable g_irebootstarted to 1 or 2
                                '1 is set the reboot method countdowntimer using  InitiateSystemShutdown
                                '2 is set the reboot method with a countdowntimer using ExitWindowsEx( %EWX_REBOOT, 0 )
                                g_irebootstarted=2&
                                IF g_irebootstarted=1& THEN rebootcomputerusingInitiateSystemShutdown
                                CONTROL SET TEXT  CBHNDL, %IDC_LABEL1, "Reboot in"+$CRLF+"process"
                                CONTROL SHOW STATE CBHNDL, %IDC_LABEL3, %SW_HIDE
                                CONTROL SHOW STATE CBHNDL, %IDC_TEXTBOX1, %SW_HIDE
                                CONTROL SET TEXT  CBHNDL, %IDC_LABEL2, "Abort Reboot"
                                CONTROL SET FONT CBHNDL, %IDC_LABEL2, g_hFont2
                                CONTROL REDRAW  CBHNDL, %IDC_LABEL1
                                CONTROL REDRAW  CBHNDL, %IDC_LABEL2
                                CONTROL REDRAW  CBHNDL, %IDC_LABEL3
                                CONTROL REDRAW  CBHNDL, %IDC_TEXTBOX1
                                CONTROL SET TEXT CBHNDL, %IDC_LABEL4, ""
                                CONTROL SHOW STATE CBHNDL, %IDC_LABEL4, %SW_SHOW
                                CONTROL REDRAW  CBHNDL, %IDC_LABEL4
                            END IF
                        END IF
    
    
                        CASE %IDC_LABEL2
                            IF g_irebootstarted=0& THEN
                                CONTROL SET TEXT  CBHNDL, %IDC_LABEL1, "Start Reboot"
                                CONTROL SET TEXT  CBHNDL, %IDC_TEXTBOX1, ""
                                CONTROL REDRAW  CBHNDL, %IDC_LABEL1
                                CONTROL REDRAW  CBHNDL, %IDC_TEXTBOX1
                            ELSE
                                IF g_irebootstarted=1& THEN abortreboot
                                IF g_irebootstarted=2& THEN abortreboot
                                g_irebootstarted=0&
                                CONTROL SET COLOR  CBHNDL, %IDC_LABEL1, -1, %GREEN
                                CONTROL SET TEXT  CBHNDL, %IDC_LABEL1, "Reboot Aborted"
                                CONTROL SET TEXT  CBHNDL, %IDC_TEXTBOX1, ""
                                CONTROL REDRAW  CBHNDL, %IDC_LABEL1
                                CONTROL REDRAW  CBHNDL, %IDC_TEXTBOX1
                                CONTROL SET FONT CBHNDL, %IDC_LABEL2, g_hFont3
                                CONTROL SET TEXT  CBHNDL, %IDC_LABEL2, "This program"+$CRLF+"will close"+$CRLF+"in 9 seconds"
                                CONTROL REDRAW  CBHNDL, %IDC_LABEL2
                                CONTROL SET TEXT  CBHNDL, %IDC_LABEL4, ""
                                CONTROL REDRAW  CBHNDL, %IDC_LABEL4
                                SLEEP 10000
                                DIALOG END CBHNDL, 0
                            END IF
                    END SELECT
                END IF
    
                SELECT CASE AS LONG CB.CTL
                    CASE %IDC_TEXTBOX1
    
                END SELECT
            CASE %WM_SYSCOMMAND
                IF (CBWPARAM AND &HFFF0) = %SC_CLOSE THEN
                   IF g_irebootstarted=0& THEN
                        DIALOG END CB.HNDL
                      ELSE
                          FUNCTION = 1
                          EXIT FUNCTION
                    END IF
                END IF
    
        END SELECT
    END FUNCTION
    
    FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
        LOCAL lRslt  AS LONG
        LOCAL hDlg   AS DWORD
    
        DIALOG NEW hParent, EXE.NAME$, 200,100, 200, 120, %WS_POPUP OR %WS_BORDER OR _
            %WS_DLGFRAME OR %WS_SYSMENU OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR _
            %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, _
            %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
            %WS_EX_RIGHTSCROLLBAR, TO hDlg
        CONTROL ADD LABEL,   hDlg, %IDC_LABEL1, "Start Reboot", 5, 4, 84, 25, _
           %WS_CHILD OR %WS_VISIBLE OR %SS_CENTER OR %SS_NOTIFY, %WS_EX_LEFT OR %WS_EX_LTRREADING
        CONTROL SET COLOR    hDlg, %IDC_LABEL1, -1, %RED
        CONTROL ADD LABEL,   hDlg, %IDC_LABEL2, "Abort Reboot", 5, 40, 190, 75, _
                  %WS_CHILD OR %WS_VISIBLE OR %SS_CENTER OR %SS_NOTIFY, %WS_EX_LEFT OR %WS_EX_LTRREADING
        CONTROL SET COLOR    hDlg, %IDC_LABEL2, -1, %YELLOW
        CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX1, "", 93, 10, 50, 15, _
            %WS_CHILD OR %WS_VISIBLE OR %ES_LEFT, _
            %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR %WS_EX_LTRREADING
        CONTROL ADD LABEL,   hDlg, %IDC_LABEL3, "The word BOOT must be placed inside the box.", 145, 10, 55, 25
        CONTROL ADD LABEL,   hDlg, %IDC_LABEL4, "", 89, 4, 110, 38, _
                  %WS_CHILD OR %WS_VISIBLE OR %SS_CENTER OR %SS_NOTIFY , %WS_EX_LEFT OR %WS_EX_LTRREADING
    
        FONT NEW "Lucida Console", 15, 1, %ANSI_CHARSET TO g_hFont1
        FONT NEW "Lucida Console", 45, 1, %ANSI_CHARSET TO g_hFont2
        FONT NEW "Lucida Console", 23, 1, %ANSI_CHARSET TO g_hFont3
    
    
        CONTROL SET FONT hDlg, %IDC_LABEL1, g_hFont1
        CONTROL SET FONT hDlg, %IDC_LABEL2, g_hFont1
        CONTROL SET FONT hDlg, %IDC_LABEL4, g_hFont3
        CONTROL SET FONT hDlg, %IDC_TEXTBOX1, g_hFont1
        CONTROL SHOW STATE hDlg, %IDC_LABEL4, %SW_HIDE
        CONTROL SET TEXT hDlg, %IDC_LABEL2, "Count down to reboot"+$CRLF+$CRLF+"is set for"+$CRLF+$CRLF+STR$(g_iseconds_till_reboot)+" seconds"
    
        DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
    
        FONT END g_hFont1
        FONT END g_hFont2
        FONT END g_hFont3
    
        FUNCTION = lRslt
    END FUNCTION
    Attached Files
    Last edited by Paul Purvis; 30 Oct 2019, 04:54 PM.
    p purvis

  • #2
    In the event somebody got the code downloaded quickly.
    In the PBMAIN section, i had set the g_iseconds_till_reboot variable to do some testing.
    To set the count down timer to something other that the default 30 seconds, place the seconds on the command line as a first parameter.
    I was going to have the timer counter go up to more than 2 days, but it just did not work out and there are other ways using the SHUTDOWN.EXE windows command to do it.
    You cannot have a value less than 10 seconds for the count down timer.
    If you start this program as is written and use some option to kill the program, it will not reboot the computer.
    I did not want to minimize the program.
    This program was written to replace my batch file reboot methods that where ok for a while but i knew it could be much better.
    The screen will also display the count down timer once you press the button/label to start the reboot timer working.
    p purvis

    Comment


    • #3
      sorry people, i had to remove one last piece of test code that slipped by.
      it had to do with not allowing seconds to be paced on the command tail.
      the code was in pbmain function

      removed the below line and i went ahead and removed the other 2 lines that i rem out that was for test code too
      g_iseconds_till_reboot=0&
      p purvis

      Comment


      • #4
        From research, I found out that if you want to use the computer name to be the same as the computer you running the
        InitiateSystemShutdown and/or AbortSystemShutdown API functions on, there is not need to set the computer name. Leave it blank
        as below

        declare variables and 100 seconds count down till action taken
        Code:
        LOCAL l_Result AS LONG
        LOCAL lpPrivilege AS ASCIIZ * 20
        LOCAL lpMachineName AS ASCIIZ * 25
        LOCAL lpMessage AS ASCIIZ * 50
        the InitiateSystemShutdown API function
        Code:
         l_Result = GetComputerName(lpMachineName, SIZEOF(lpMachineName))
         lpMessage = "This computer will reboot in"+str$(100)+"seconds"
         l_Result = InitiateSystemShutdown(lpMachineName, lpMessage, 100, %TRUE, 1) 'Force,Reboot
        same effect without using the computer name
        Code:
         lpMessage = "This computer will reboot in"+str$(100)+"seconds"
         l_Result = InitiateSystemShutdown("", lpMessage, 100, %TRUE, 1) 'Force,Reboot

        the AbortSystemShutdown API function
        Code:
        l_Result = GetComputerName(lpMachineName, SIZEOF(lpMachineName))
        'l_Result = AbortSystemShutdown(lpMachineName)
        same effect without using the computer name
        Code:
         l_Result = AbortSystemShutdown("")

        also in using the InitiateSystemShutdown API function, you can disable the API from creating a window message by leaving the message blank
        Code:
         l_Result = InitiateSystemShutdown("", "", 100, %TRUE, 1) 'Force,Reboot
        I am not aware of any means of disabling a message box when aborting the shutdown using the AbortSystemShutdown API function.

        If you liked the GUI and wanted a hybrid method of shutting down, you could use the above code in the timer and apply the
        InitiateSystemShutdown API at a certain given seconds remaining in the code above, because any seconds in the timer function that are equal.
        I just EXIT the function so there are no duplicate second numbers passing down thru the function. That was mostly done to keep from updating
        the CONTROL LABEL with the seconds(time) remaining to keep the CPU low and remove the flickering effect for sending the same text to
        the LABEL
        p purvis

        Comment


        • #5
          hello Paul Purvis
          I am getting an Undefined TYPE in line 60: LOCAL tmpLuid AS LUID
          what am I missing?
          as the salmon fish is compelled to go back to it's birthplace to spawn, so comes a day when man is compelled to go back to it's source.. GOD

          Comment


          • #6
            Hi Johan, which compiler are you using and I will download what i posted and see what happens
            p purvis

            Comment


            • #7
              I am using PB win 10.04
              as the salmon fish is compelled to go back to it's birthplace to spawn, so comes a day when man is compelled to go back to it's source.. GOD

              Comment


              • #8
                Johan
                see Jose Roca post in
                https://forum.powerbasic.com/forum/u...-windows/61117

                changes in definitions of types and using pointers

                new code for GetPrivelege in PBWin10 changed from PBWin90

                Code:
                FUNCTION GetPrivilege( Privilege AS ASCIIZ ) EXPORT AS LONG
                    LOCAL hdlProcessHandle    AS LONG
                    LOCAL hToken              AS LONG
                    LOCAL tmpLuid             AS QUAD
                    LOCAL tp                  AS TOKEN_PRIVILEGES
                    LOCAL tpNBI               AS TOKEN_PRIVILEGES
                    LOCAL BufferLength        AS LONG
                    LOCAL lBufferNeeded       AS LONG
                
                    hdlProcessHandle = GetCurrentProcess()
                    CALL OpenProcessToken( hdlProcessHandle, (%TOKEN_ADJUST_PRIVILEGES OR %TOKEN_QUERY), hToken )
                
                    ' Get the LUID for the privilege.
                    LookupPrivilegeValue "", Privilege, tmpLuid
                    tp.PrivilegeCount = 1
                
                    ' One privilege to set
                    tp.Privileges(0).Luid = tmpLuid
                    tp.Privileges(0).Attributes = %SE_PRIVILEGE_ENABLED
                
                    ' Enable the privilege in the access token of this process.
                    BufferLength = SIZEOF(tpNBI)
                    FUNCTION= AdjustTokenPrivileges( BYVAL hToken,BYVAL 0,BYVAL VARPTR(tp),BYVAL BufferLength ,BYVAL VARPTR(tpNBI),lBufferNeeded )
                END FUNCTION

                p purvis

                Comment


                • #9
                  thank you
                  as the salmon fish is compelled to go back to it's birthplace to spawn, so comes a day when man is compelled to go back to it's source.. GOD

                  Comment


                  • #10
                    The real thanks is for Jose.
                    Johan. Because of the huge depth of knowledge and ode in the forums.
                    Purchasing all the compilers is not a big cost and it can help you see your way through troubles such as this.
                    In my view, having all the compiles of powerrbasic is the only way to go. You might see the value in that now.
                    But there will come a day when you wished you did.

                    Acquiring the last version of POFFS software with the older set of database is a huge help too.
                    The saved time and having no headaches for applying code found with older compilers is a real gold mine.
                    p purvis

                    Comment

                    Working...
                    X