DarkenRahl Posted February 10, 2016 Share Posted February 10, 2016 I am reading dealing with dll in autoit and I came accross this exercise. The setLocalTime function in the kernel32.dll is supposed to set the local time of the machine (at least that's how i understand it). My code runs and echos the new time in the msgbox but the time fails to change on the system. Am i doing anything wrong? $setTime = DllStructCreate("WORD wYear; WORD wMonth; WORD wDayOfWeek; WORD wDay; WORD wHour; WORD wMinute; WORD wSecond; WORD wMilliseconds") DllStructSetData($setTime, "wHour", 3) DllStructSetData($setTime, "wMinute", 35) DllStructSetData($setTime, "wYear", 1608) DllCall("Kernel32.dll", "int", "SetLocalTime", "ptr", DllStructGetPtr($setTime)) MsgBox(64, "Dll Time Function", "The time is " & DllStructGetData($setTime, "wHour")& ':' & DllStructGetData($setTime, "wMinute") & " PM") Link to comment Share on other sites More sharing options...
Radiance Posted February 10, 2016 Share Posted February 10, 2016 Not very experienced on DLLCalls, but changing system time needs admin privileges on most systems. Did you include a #RequireAdmin or run the script as one? Link to comment Share on other sites More sharing options...
Danyfirex Posted February 10, 2016 Share Posted February 10, 2016 Try to check last error... #include <WinAPI.au3> #include <WinAPIDiag.au3> Local $setTime = DllStructCreate("WORD wYear; WORD wMonth; WORD wDayOfWeek; WORD wDay; WORD wHour; WORD wMinute; WORD wSecond; WORD wMilliseconds") DllStructSetData($setTime, "wHour", 3) DllStructSetData($setTime, "wMinute", 35) DllStructSetData($setTime, "wYear", 1608) Local $aRet=DllCall("Kernel32.dll", "int", "SetLocalTime", "ptr", DllStructGetPtr($setTime)) if @error Then MsgBox(16,"Error","Error DllCall") Exit EndIf If $aRet[0]=0 Then Local $iError=_WinAPI_GetLastError() MsgBox(16,"Error SetLocalTime",_WinAPI_GetErrorMessage($iError)) Else MsgBox(64,"Info","Everything should be OK") EndIf Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
DarkenRahl Posted February 10, 2016 Author Share Posted February 10, 2016 I run my programme with the autoit require admin function. Still the same error. Danifirex, I believe the error is from the parameter but I just don't know what to do.. ANy help? Link to comment Share on other sites More sharing options...
DarkenRahl Posted February 10, 2016 Author Share Posted February 10, 2016 Thanks to you all. I figured out the problem with your help. All the parameters of the SYSTEMTIME struct needed be filled with the dllstructsetdata before anything happened. The final script required admin to run. The finished code is so. #RequireAdmin #include <WinAPI.au3> #include <WinAPIDiag.au3> Local $setTime = DllStructCreate("WORD wYear; WORD wMonth; WORD wDayOfWeek; WORD wDay; WORD wHour; WORD wMinute; WORD wSecond; WORD wMilliseconds") DllStructSetData($setTime, 1, 2012) DllStructSetData($setTime, 2, 6) DllStructSetData($setTime, 4, 2) DllStructSetData($setTime, 5, 11) DllStructSetData($setTime, 6, 54) DllStructSetData($setTime, 7, 32) DllStructSetData($setTime, 8, 254) Local $aRet=DllCall("Kernel32.dll", "bool", "SetLocalTime", "ptr", DllStructGetPtr($setTime)) if @error Then MsgBox(16,"Error","Error DllCall") Exit EndIf If $aRet[0]=0 Then Local $iError=_WinAPI_GetLastError() MsgBox(16,"Error SetLocalTime",_WinAPI_GetErrorMessage($iError)) Else MsgBox(64,"Info","Everything should be OK") EndIf Link to comment Share on other sites More sharing options...
Danyfirex Posted February 10, 2016 Share Posted February 10, 2016 Good!!!!!!!!!! Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now