在C#中更改窗口10次 [英] Changing windows 10 time in C#

查看:105
本文介绍了在C#中更改窗口10次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前创建了一个应用程序,用于将c#中的窗口时间更改为之前的时间,并且它曾经在Windows 7上正常工作,但现在在Windows 10上它将无法正常工作。



我的尝试:



I had previously made an app to change windows time in c#, to a previous time, and it used to work fine on windows 7, but now on windows 10 it will just not work.

What I have tried:

private void button1_Click_1(object sender, EventArgs e)
        {
            
            h1 = h;//hours
            m1 = m;//minutes
            s1 = s;//seconds
            //booleano is my boolean value that starts in true
            //MessageBox.Show(""+booleano);
            if (booleano)
            {
                foreach (String st in tokens1)
                {
                    time = tokens1[0] + "," + tokens1[1] + "," + tokens1[2] + "," + h1 + "," + m1 + "," + s1 + "," + false.ToString() + "," + true.ToString();
                }

                System.IO.File.WriteAllText(Application.StartupPath + "\\time.txt", time);
                //MessageBox.Show(Application.StartupPath);               
                st.wYear = short.Parse(""+2014); // must be short
                st.wMonth = short.Parse(""+1);
                st.wDay = short.Parse(""+1);
                SetSystemTime(ref st);
                booleano = false;
            }
            else
            {
                booleano = true;
                FileStream file = new FileStream(Application.StartupPath+"\\time.txt", FileMode.Open, FileAccess.Read);
                StreamReader sr = new StreamReader(file);
                sr.ReadLine();
                var textLines = File.ReadAllLines(Application.StartupPath + "\\time.txt");
                foreach (var line in textLines)
                {
                    string[] dataArray = line.Split(',');
                    st.wYear= short.Parse(dataArray[0]);
                    st.wMonth = short.Parse(dataArray[1]);
                    st.wDay = short.Parse(dataArray[2]);
                    st.wHour = short.Parse(dataArray[3]);
                    st.wMinute = short.Parse(dataArray[4]);
                    st.wSecond = short.Parse(dataArray[5]);                    
                }
                file.Close();
                SetSystemTime(ref st);
            }
            
        }



这是我在一个改变时间的按钮上的代码


This is the code I have on a button to change time

推荐答案

首先,你不要;想要这样做 - 没有充分的理由改变时间,因为大多数Windows安装现在默认使用NTP服务器来准确地维持系统时间 - 并且NTP服务器无论如何都会覆盖你的应用程序。



此外,正如Jochen所说,你需要管理员权限来改变Win10上的系统时间,部分原因是因为使用了NTP服务器,部分原因是保持正确的时间对于应用程序而言越来越重要时间戳数据。



使用系统日期和/或时间的主要原因是绕过试用软件到期时间 - 这不是合法用法。我们不以任何方式,形式或方式宽恕,支持或协助生成恶意代码。这是专业开发人员的专业网站。所以,除非你有合法的用途,你可以向我们解释,你不会在这里得到帮助。
First off, you dont; want to do that - there is no good reason for altering the time, since most Windows installations now use a NTP server by default to maintain the system time accurately - and the NTP server will override your app anyway.

In addition, as Jochen said, you need admin privileges to change the system time on Win10, partly because of the use of NTP servers, and partly because keeping the time right is increasingly important to applications which timestamp data.

The main reasons for playing with the system date and / or time is to bypass trial software expiry periods - and that is not a legitimate usage. We do not condone, support, or assist in the production of malicious code in any way, form, or manner. This is a professional site for professional developers. So unless you have a very legitimate use you can explain to us, you will not get help here.


这篇关于在C#中更改窗口10次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆