Setting System Time without API

  • Thread starter Thread starter Steve Ricketts
  • Start date Start date
Steve said:
Many thanks!

Um. Since the function that Mark referred you to is part of the Windows
API, how does that answer your question? Are you using some definition
of "Windows API" other than the usual one?
 
Steve Ricketts said:
Is there any way to set the system time without using the Windows API?

Why? You could change the CMOS time in the BIOS and reboot, but if you
want to change the OPERATING SYSTEM time, then you need to tell the
OPERATING SYSTEM, don't you think?
 
Nope, same definition... just was out of the office and couldn't check out
the details until now. So, nope... doesn't answer the question. I'm
wanting to change the time through a pure .Net way.

sr
 
Yes, that's the intent... to change the operating system's time. I just
don't want to use the Windows API. The application will be run through Mono
so I need a .Net approach to operate on Windows, Mac's and Linux.

sr
 
Didn't think justification of "why" was necessary and didn't want to muddy
the request with more information than necessary... been guilty of that
before. ;-) I thought the question was simple enough, how to change time
without using the Windows API and expected either: No, can't be done or
Here's how. Didn't want to focus on the "why" as much as the "how".

sr
 
Steve said:
Nope, same definition... just was out of the office and couldn't check
out the details until now. So, nope... doesn't answer the question.
I'm wanting to change the time through a pure .Net way.

That's confusing too. .NET is part of the Windows API as well. Your
question _seemed_ to be asking for a low-level solution that bypasses
all Windows features altogether.

That said, I don't think .NET has a specific time-setting API. But it
does provide a wrapper for WMI, which is the unmanaged feature Mark
referred you to. So rather than writing p/invoke code to access WMI
directly, it should be just as simple to go through the .NET WMI API.

Pete
 
Steve said:
Didn't think justification of "why" was necessary and didn't want to
muddy the request with more information than necessary... been guilty of
that before. ;-) I thought the question was simple enough, how to
change time without using the Windows API and expected either: No, can't
be done or Here's how. Didn't want to focus on the "why" as much as
the "how".

The problem is that the phrase "without using the Windows API" is vague,
and without the further details, impossible to know for sure what your
_actual_ restriction is.

I believe the bottom line is: you can't do it. Even without p/invoke,
you're using what is essentially a Windows features (WMI). I would be
very surprised if .NET on other platforms supported the WMI features.

But, I admit: I don't know for sure what Mono supports. If it has at
least minimal mapping for WMI to the native OS features, you might be
able to do it.

Pete
 
Steve Ricketts said:
Didn't think justification of "why" was necessary and didn't want to muddy
the request with more information than necessary... been guilty of that
before. ;-) I thought the question was simple enough, how to change time
without using the Windows API and expected either: No, can't be done or
Here's how. Didn't want to focus on the "why" as much as the "how".

As the one who asked the question "why" and triggered this confusion, I
admit to a shocking case of tunnel vision. You asked about changing the
time "without using the Windows API". In the context of a Windows
newsgroup, I interpreted your question to say "how can I change the time in
a Windows computer by going underneath the API and writing straight to the
BIOS or hardware?"

I completely overlooked the obvious alternate interpretation, "how can I
change the time using the CLR without dropping directly to the API?"

My fault, and I apologize.
 
Back
Top