-
May 22nd, 2003, 01:50 AM
#1
Change System Date/Time with C#
session™
//Developing the Future
//Power of the Vision
-
May 22nd, 2003, 03:46 PM
#2
Just start the extern process cmd.exe with the time argument, i.e.
String arg = @"/C \"time hh:min:sec\"";
Similar with date:
extern process : cmd.exe
arg =@ "/C \"data dd-mm-[yy]yy\"";
Hope this helps
-
May 22nd, 2003, 04:51 PM
#3
Originally posted by Holiday
Just start the extern process cmd.exe with the time argument, i.e.
String arg = @"/C \"time hh:min:sec\"";
Similar with date:
extern process : cmd.exe
arg =@ "/C \"data dd-mm-[yy]yy\"";
Hope this helps
can you please explain a lil bit more???
session™
//Developing the Future
//Power of the Vision
-
May 22nd, 2003, 05:38 PM
#4
it is better way to use
P/Invoke functions using Win32 API.
define this structure in your form's main class
------------------------ [StructLayout(LayoutKind.Sequential)]
public struct SYSTEMTIME
{
public short wYear;
public short wMonth;
public short wDayOfWeek;
public short wDay;
public short wHour;
public short wMinute;
public short wSecond;
public short wMilliseconds;
}
[DllImport("kernel32.dll", SetLastError=true)]
public static extern bool SetSystemTime( [In] ref SYSTEMTIME st );
----------------------
now somewhere you can test following
SYSTEMTIME st = new SYSTEMTIME();
st.wYear = 2003; // must be short
st.wMonth = 5;
st.wDay = 22;
st.wHour = 0;
st.wMinute = 0;
st.wSecond = 0;
SetSystemTime(ref st); // invoke this method.
-hope this helps,
Paresh
- Software Architect
-
May 23rd, 2003, 03:11 AM
#5
Originally posted by session
can you please explain a lil bit more???
The way parshgh proposed is the more sophisticated. You should use this way.
Just for satisfying your request:
args as in the first post!
string command= "cmd";
string args = string.Format("/C \"{0}\"",argument.Trim());
System.Diagnostics.ProcessStartInfo psi =
new System.Diagnostics.ProcessStartInfo(command,args);
psi.UseShellExecute = false;
System.Diagnostics.Process proc = null;
proc = System.Diagnostics.Process.Start(psi);
-
August 16th, 2006, 06:25 AM
#6
Re: Change System Date/Time with C#
Originally Posted by pareshgh
it is better way to use
P/Invoke functions using Win32 API.
define this structure in your form's main class
------------------------ [StructLayout(LayoutKind.Sequential)]
public struct SYSTEMTIME
{
public short wYear;
public short wMonth;
public short wDayOfWeek;
public short wDay;
public short wHour;
public short wMinute;
public short wSecond;
public short wMilliseconds;
}
[DllImport("kernel32.dll", SetLastError=true)]
public static extern bool SetSystemTime( [In] ref SYSTEMTIME st );
----------------------
now somewhere you can test following
SYSTEMTIME st = new SYSTEMTIME();
st.wYear = 2003; // must be short
st.wMonth = 5;
st.wDay = 22;
st.wHour = 0;
st.wMinute = 0;
st.wSecond = 0;
SetSystemTime(ref st); // invoke this method.
-hope this helps,
Paresh
-------------------------------------------------------
Hi
I want to use your code in my project too. but I don't know where I have to write these parts
would you please give me a single example of using these instructions in C#.NET 2005 ? I really need this so emergency
I'm looking forward your respond
thanks
-
August 20th, 2006, 04:43 AM
#7
Re: Change System Date/Time with C#
what's the meaning of this error?????????????
Error 2 The type or namespace name 'StructLayout' could not be found (are you missing a using directive or an assembly reference?) F:\Documents and Settings\admin\My Documents\Visual Studio 2005\Projects\changesystemtime\changesystemtime\Form1.cs 13 12 changesystemtime
-
August 20th, 2006, 09:35 AM
#8
Re: Change System Date/Time with C#
Add this line at the top of your code where you use StructLayout attribute.
Code:
using System.Runtime.InteropServices;
-
January 22nd, 2008, 05:43 AM
#9
Re: Change System Date/Time with C#
Originally Posted by Holiday
extern process :cmd.exe arg
arg=@ "/C \"data dd-mm-[yy]yy\"";
this is what language code i cant run it in C# can you write the whole function
instead of writing snapet
process: cmd .exe
does not support by Process class
argumets also
plz tell breafly
plz explan it.
-
May 12th, 2020, 12:27 PM
#10
Re: Change System Date/Time with C#
Originally Posted by nidostyle
plz explan it.
How do I reset the system datetime back to the current date time?
-
May 16th, 2020, 10:30 PM
#11
Re: Change System Date/Time with C#
Originally Posted by TonyPag
How do I reset the system datetime back to the current date time?
It the computer connected to a network domain?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|