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) –