A very interesting tip..
For my current project, I need to set the system time with some reference time. Quite easy!!. The SetSytemTime (). The syntax is like this
BOOL WINAPI SetSystemTime(
__in          const SYSTEMTIME* lpSystemTime
);
The time must be in the form of SYSTEMTIME struct.  And I implement it in my code as
SYSTEMTIME st = NewTime;
bSuccess = SetSystemTime(&st);
:). The problem is on the way.
The SetSystemTime function enables the SE_SYSTEMTIME_NAME privilege before changing the system time. This privilege is disabled by default. (©MSDN)
for changing the privileges, we need to implement some authorization functions. In the following order
1-  OpenProcessToken() – opens the access token associated with a process
2-  LookupPrivilegeValue() – Retrieves the locally unique identifier (LUID) used on a specified system to locally represent the specified privilege name
3-   AdjustTokenPrivileges()-enables or disables privileges in the specified access token.
After that, change the system time with SetSystemTime() method.
Then again reset the privileges by using the function AdjustTokenPrivileges().
It works well in WindowsXP. No problems for setting the new time.  J
But , the problem comes from Windows 7 and Windows Vista.
Then, I start debugging my code in Windows 7. All authorization functions works fine for me.  Like OpenProcessToken(),LookupPrivilegeValue() and AdjustTokenPrivileges(). But I felt something bad about the execution of the last method. AdjustTokenPrivileges()..
I checked the GetLastError() return value. Instead of ERROR_SUCCESS
, it returns ERROR_NOT_ALL_ASSIGNED J
So my investigation is now in that way. How to handle that? Its all because of UAC (User Access Control) problems. Because the SE_SYSTEMTIME_NAME require administrative privilege.
My colleague gave me a tip about Manifests.
The description from MSDN is like Manifests are XML files that accompany and describe side-by-side assemblies or isolated applications. Manifests uniquely identify the assembly through the assembly’s <assemblyIdentity> element. They contain information used for binding and activation, such as COM classes, interfaces, and type libraries, that has traditionally been stored in the registry. Manifests also specify the files that make up the assembly and may include Windows classes if the assembly author wants them to be versioned. Side-by-side assemblies are not registered on the system, but are available to applications and other assemblies on the system that specify dependencies in manifest files.
Manifest files enable administrators and applications to manage side-by-side assembly versions after deployment. Every side-by-side assembly must have a manifest associated with it. The installation of Windows XP installs the supported Microsoft side-by-side assemblies with their manifests. If you develop your own side-by-side assemblies, you must also install manifest files
I turn on the manifests for my application also. Its very simple.
Project Settings > Linker > Manifest File.
And make the options as indicated in the figure.
Including manifest for project
The Rebuild All  and Execute..
🙂
BijU
Gravity is not responsible for people to fall in love. It just happens.

A very interesting tip..

For my current project, I need to set the system time with some reference time. Quite easy!!. Using SetSytemTime (). The syntax is like this

BOOL WINAPI SetSystemTime(

__in          const SYSTEMTIME* lpSystemTime

);

The time must be in the form of SYSTEMTIME struct.  And I implement it in my code as

SYSTEMTIME st = NewTime;

bSuccess = SetSystemTime(&st);

:). The problem is on the way.

The SetSystemTime function enables the SE_SYSTEMTIME_NAME privilege before changing the system time. This privilege is disabled by default. (©MSDN)

for changing the privileges, we need to implement some authorization functions. In the following order

1-  OpenProcessToken() – opens the access token associated with a process

2-  LookupPrivilegeValue() – Retrieves the locally unique identifier (LUID) used on a specified system to locally represent the specified privilege name

3-   AdjustTokenPrivileges()-enables or disables privileges in the specified access token.

After that, change the system time with SetSystemTime() method.

Then again reset the privileges by using the function AdjustTokenPrivileges().

It works well in WindowsXP. No problems for setting the new time.  🙂 But , the problem comes from Windows 7 and Windows Vista.

Then, I start debugging my code in Windows 7. All authorization functions works fine for me.  Like OpenProcessToken(),LookupPrivilegeValue() and AdjustTokenPrivileges(). But I felt something bad about the execution of the last method. AdjustTokenPrivileges()..

I checked the GetLastError() return value. Instead of ERROR_SUCCESS, it returns ERROR_NOT_ALL_ASSIGNED J

So my investigation is now in that way. How to handle that? Its all because of UAC (User Access Control) problems. Because the SE_SYSTEMTIME_NAME require administrative privilege.

My colleague gave me a tip about Manifests.

The description from MSDN is like Manifests are XML files that accompany and describe side-by-side assemblies or isolated applications. Manifests uniquely identify the assembly through the assembly’s <assemblyIdentity> element. They contain information used for binding and activation, such as COM classes, interfaces, and type libraries, that has traditionally been stored in the registry. Manifests also specify the files that make up the assembly and may include Windows classes if the assembly author wants them to be versioned. Side-by-side assemblies are not registered on the system, but are available to applications and other assemblies on the system that specify dependencies in manifest files.

Manifest files enable administrators and applications to manage side-by-side assembly versions after deployment. Every side-by-side assembly must have a manifest associated with it. The installation of Windows XP installs the supported Microsoft side-by-side assemblies with their manifests. If you develop your own side-by-side assemblies, you must also install manifest files

I turn on the manifests for my application also. Its very simple.

Project Settings > Linker > Manifest File. And make the options as indicated in the figure.

Project Settings>Linker Options > Manifest

Project Settings>Linker Options > Manifest

Including manifest for project

The Rebuild All  and Execute..

🙂

for https://vctipsplusplus.wordpress.com/

BijU

Gravity is not responsible for people to fall in love. It just happens.

Advertisements