This function fails with error code 1300 under Vista.
I assume this has something to do with priviledges?
Is there a VISTA approved way to do this?
------------------
Kind Regards
Mike
I assume this has something to do with priviledges?
Is there a VISTA approved way to do this?
Code:
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤' FUNCTION SetTimePrivilege() AS LONG LOCAL hProcess, hToken, BuffLen, BuffNeeded, RetVal AS LONG LOCAL WinErr AS DWORD LOCAL TP, TPnew AS TOKEN_PRIVILEGES LOCAL LD AS LUID hProcess = GetCurrentProcess() RetVal = OpenProcessToken( hProcess, (%TOKEN_ADJUST_PRIVILEGES OR %TOKEN_QUERY), hToken ) IF RetVal THEN RetVal = LookupPrivilegeValue( "", "SeSystemtimePrivilege", LD )' Get the LUID for setSystemTime privilege. IF RetVal THEN 'MSGBOX "LookupPrivilegeValue="+STR$(RetVal),48,"SetTimePrivilege()" ELSE MSGBOX "Unable to Access Time Privilege",48,"SetTimePrivilege()" FUNCTION = RetVal EXIT FUNCTION END IF ELSE MSGBOX "Unable to OpenProcessToken",48,"SetTimePrivilege()" FUNCTION = RetVal EXIT FUNCTION END IF TP.PrivilegeCount = 1 TP.Privileges(0).pLuid = LD TP.Privileges(0).Attributes = %SE_PRIVILEGE_ENABLED ' grant temp access to this function BuffLen = SIZEOF(TPnew) ' The AdjustTokenPrivileges function enables or disables privileges in the specified access token. ' Enabling or disabling privileges in an access token requires TOKEN_ADJUST_PRIVILEGES access. RetVal = AdjustTokenPrivileges( BYVAL hToken, BYVAL 0, TP, BYVAL BuffLen, TPnew, BuffNeeded ) WinErr = GetLastError ' ERROR_SUCCESS = adjusted ALL specified privileges IF RetVal AND WinErr = %ERROR_SUCCESS THEN ' If the function succeeds, the return value is nonzero. FUNCTION = 1 ' success MSGBOX FormatErrMsg(WinErr),48,"SetTimePrivilege()" EXIT FUNCTION ELSE MSGBOX "Unable to AdjustTokenPrivileges: "+FormatErrMsg(WinErr),48,"SetTimePrivilege()" FUNCTION = 0 ' Failed EXIT FUNCTION END IF END FUNCTION
Kind Regards
Mike
Comment