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
さらに詳しい情報...同じ行に別の質問がありますが、それは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) –