Sub change_the_time(ByVal NewDateTime As DateTime)
'
Dim NewDateTime2 As DateTime
'
NewDateTime2 = #5/1/2016 5:52:15 PM# ' try setting the time to this
'
'set the system date and time to this date and time - throw an exception if it can't
Try
TimeOfDay = NewDateTime2
Catch ex As Exception
MessageBox.Show("Could not set time. " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop)
End Try
End Sub
嗨。 新的网站,所以希望我遵循的规则:-) 我的问题是我如何成功地改变系统时间?上面的代码我发现在这个网站上(以及我的项目的其他部分的很多信息 - 谢谢!),并没有错误,但它总是抛出一个异常。我以管理员身份运行,并尝试更改UAC,但仍无法更改时间。我知道我需要设置SE_SYSTEMTIME_NAME权限,但是我拥有这个设置,以便所有用户(即我)都有权利,但没有任何权限。 MS参考here没有提供很多见解。我怀疑这是一个特权问题,但我似乎无法看到如何设置我所需要的。我需要做什么才能让我的应用程序将系统时间更改为某个值?动态更改系统时间win7
更多信息...还有一个问题沿着同样的路线,但它是c#不是Vb,我尝试过类似于下面的代码。仍然
Private Sub change_the_time2(ByRef NewDateTime As DateTime)
Dim d As DateTime
d = #6/10/2011# ' try setting the date to this before using NewDateTime
Dim worked As Boolean
'
Try
worked = setlocaltime(d)
MsgBox(" 1. Did it work " & worked)
Catch ex As Exception
MsgBox(" 2. Did it work " & worked)
End Try
End Sub
<DllImport("kernel32.dll", setLastError:=True)> _
Private Shared Function setlocaltime(ByRef time As System.DateTime) As Boolean
End Function
什么是例外? –
您好SuperPeanut,“无法设置时间。安全权限不足以设置系统时间” –
可能重复[以编程方式更改系统日期](http://stackoverflow.com/questions/650849/change-system-date-programmatically) –