Sign in to follow this  
Followers 0
MrBeatnik

_Date_Time_SetTimeZoneInformation and ERROR_PRIVILEGE_NOT_HELD

11 posts in this topic

Hi folks.

_Date_Time_SetTimeZoneInformation Help Documentation

So the example used in the above help doc doesn't work for us in Windows 7.

Get the old "System time zone cannot be SET" due to "Not all privileges are assigned".

The example also states:

 

; Under Vista the Windows API "SetTimeZoneInformation" may be rejected due to system security

 

Assuming that I am using the example correctly, my questions:

1) The same issue occurs under Win 7, so the "Vista" statement above seems true for Win 7. Since XP is out of support, is the example still accurate and up to date?

2) I see >this post may have a work around, but it is heavily modified from the original example. Specifically, using DLLStruct Calls with a rewritten function. If this method should be used, is the example obsolete?

3) If the example is still valid, how can I remove the "system security"? The application runs as a user in the Admin group, UAC disabled, has #RequireAdmin at top of script.

I can rework it using the example, but I would like some input on what the official method should be.

Thanks


Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

Share this post


Link to post
Share on other sites



Try using #RequireAdmin


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Try using #RequireAdmin

Hi,

As mentioned, I am already using #RequireAdmin, but this doesn't resolve the issue for me.

Thanks.


Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

Share this post


Link to post
Share on other sites

I recompiled with a newer version.

Problem still exists, but a different error. Specifically:

If Not _Date_Time_SetTimeZoneInformation($aOld[1], "GMT Standard Time", $aOld[3], $aOld[4], "GMT Daylight Time", $aOld[6], $aOld[7]) Then
        MsgBox($MB_SYSTEMMODAL, "Error", "System time zone cannot be SET" & @CRLF & @CRLF & _WinAPI_GetLastErrorMessage())
        Exit
    EndIf

Outputs this MSGBOX:

 

System time zone cannot be SET

The operation completed successfully.

 

Clearly the _Date_Time_SetTimeZoneInformation function is returning FALSE to trigger the message box, but strange that the _WinAPI_GetLastErrorMessage function returns "The operation completed successfully" now.

Regardless, the task is not working - timezone is not being set.

Again, I could use the workaround (not tested), but I'm curious as to why the example doesn't work out of box.


Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

Share this post


Link to post
Share on other sites

According to MSDN to set the time zone in WinVista+ requires using different privileges than it did in WinXP, so you'd have to use the work-around in that post to have it work under Vista+. The UDF might require an OS check to make sure you're using the correct privilege setting, which would mean that it's a bug when using it under Vista+.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

According to MSDN to set the time zone in WinVista+ requires using different privileges than it did in WinXP, so you'd have to use the work-around in that post to have it work under Vista+. The UDF might require an OS check to make sure you're using the correct privilege setting, which would mean that it's a bug when using it under Vista+.

 

Considering XP death now, it would require, at least, _Security_SetPrivilege from my tests... to be a valid functioning example.

I'm testing just now and it IS changing the timezone, albeit to something it doesn't like - but that's for me to check and fix for my timezone.

Almost working code (based on _Security_SetPrivilege and _Date_Time_SetTimeZoneInformation examples merged together):

#RequireAdmin
#include <GUIConstantsEx.au3>
#include <Date.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <SecurityConstants.au3>
#include <Security.au3>
#include <WinAPI.au3>



; Under Vista the Windows API "SetTimeZoneInformation" may be rejected due to system security



Global $iMemo

;_Security__SetPrivilege Example Below Here
Local $hToken = _Security__OpenProcessToken(_WinAPI_GetCurrentProcess(), $TOKEN_ALL_ACCESS)
If $hToken Then
    ; $hToken it this process' token with $TOKEN_ALL_ACCESS access

    ; Enable SeDebugPrivilege for this token
    If _Security__SetPrivilege($hToken, $SE_TIME_ZONE_NAME, True) Then
        ;... Do whatever with this token now and here...
                Example()                                                                                       ;<------------- CALL ORIGINAL _Date_Time_SetTimeZoneInformation EXAMPLE
        MsgBox($MB_SYSTEMMODAL, "TokenPrivileges", $SE_TIME_ZONE_NAME & " enabled!")
        ; Disable
        _Security__SetPrivilege($hToken, $SE_TIME_ZONE_NAME, False)
        MsgBox($MB_SYSTEMMODAL, "TokenPrivileges", $SE_TIME_ZONE_NAME & " disabled!")
    EndIf

    ; Close handle when done
    _WinAPI_CloseHandle($hToken)
EndIf




;_Date_Time_SetTimeZoneInformation Example Below Here
Func Example()
    Local $aOld, $aNew

    ; Create GUI
    GUICreate("Time", 400, 300)
    $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 296, $WS_VSCROLL)
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    GUISetState(@SW_SHOW)

    ; Show current time zone information
    $aOld = _Date_Time_GetTimeZoneInformation()
    ShowTimeZoneInformation($aOld, "Current")
    ; Set new time zone information
    If Not _Date_Time_SetTimeZoneInformation($aOld[1], "GMT Standard Time", $aOld[3], $aOld[4], "GMT Daylight Time", $aOld[6], $aOld[7]) Then
        MsgBox($MB_SYSTEMMODAL, "Error", "System time zone cannot be SET" & @CRLF & @CRLF & _WinAPI_GetLastErrorMessage())
        Exit
    EndIf

    ; Show new time zone information
    $aNew = _Date_Time_GetTimeZoneInformation()
    ShowTimeZoneInformation($aNew, "New")

    ; Reset original time zone information
   ; _Date_Time_SetTimeZoneInformation($aOld[1], $aOld[2], $aOld[3], $aOld[4], $aOld[5], $aOld[6], $aOld[7])

    ; Show current time zone information
    ;$aOld = _Date_Time_GetTimeZoneInformation()
    ;ShowTimeZoneInformation($aOld, "Reset")

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

; Write a line to the memo control
Func MemoWrite($sMessage)
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

; Show time zone information
Func ShowTimeZoneInformation(ByRef $aInfo, $comment)
    MemoWrite("******************* " & $comment & " *******************")
    MemoWrite("Result ............: " & $aInfo[0])
    MemoWrite("Current bias ......: " & $aInfo[1])
    MemoWrite("Standard name .....: " & $aInfo[2])
    MemoWrite("Standard date/time : " & _Date_Time_SystemTimeToDateTimeStr($aInfo[3]))
    MemoWrite("Standard bias......: " & $aInfo[4])
    MemoWrite("Daylight name .....: " & $aInfo[5])
    MemoWrite("Daylight date/time : " & _Date_Time_SystemTimeToDateTimeStr($aInfo[6]))
    MemoWrite("Daylight bias......: " & $aInfo[7])
EndFunc   ;==>ShowTimeZoneInformation

Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

Share this post


Link to post
Share on other sites

Even though Microsoft doesn't support it, AutoIt is still being developed to work with XP SP3.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Even though Microsoft doesn't support it, AutoIt is still being developed to work with XP SP3.

 

Fair enough, that answers the question about the example; it's still valid for supported OS.

So, now I am setting the correct priv using the AutoIT UDF, and it appears to be working, any advice why the control panel isn't happy even after a reboot?

post-12112-0-75622800-1401897181_thumb.p

EVen if I use _Date_Time_GetTimeZoneInformation() to get the current details (when everything is happy with the clock), and then use _Date_Time_SetTimeZoneInformation() to paste the exact same details back in, the above "error" occurs.


Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

Share this post


Link to post
Share on other sites

Try it using the information on this page. It seems that newer versions of Windows require a different method.

 

Specific to Windows 7 and Windows 8, call SetDynamicTimeZoneInformation to set system time zone information instead of SetTimeZoneInformation. support provided for dynamic daylight savings time in. In a scenario where an application calls SetTimeZoneInformation instead, dynamic daylight saving time support is disabled for the calling application.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Try it using the information on this page. It seems that newer versions of Windows require a different method.

Yes, I had wondered - timezones are set via UTC rather than GMT in Windows 7.

However, there is no UDF for this? Can you confirm?

So again have to revert back to the DLL calls....

(and thanks for all your help on this post!)

Edited by MrBeatnik

Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

Share this post


Link to post
Share on other sites

The UDFs you've been using have DLLCalls in them, so all you're doing is creating a new one. Maybe if it works, it can be added to the Date.au3 UDF.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0