Dim rc As Long, sError As String
Dim lngResult As Long, lngDisposition As Long
Dim udtSECURITY_ATTRIBUTES As SECURITY_ATTRIBUTES
Dim temp As String, tempLong As Long
Dim dat(256) As Byte
Dim dwLabel(1) As String
'レジストリにキーを作成する
rc = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Run", 0&, vbNullString, _
REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, udtSECURITY_ATTRIBUTES, lngResult, lngDisposition)
If rc = ERROR_SUCCESS Then
temp = Me.Text1.Text
a = 0
For b = 1 To Len(temp)
c = Asc(Mid(temp, b, 1))
If c > &H39 Or c < &H30 Then a = 1: Exit For
Next
If a = 1 Then
rc = RegSetValueEx(lngResult, "Startup", 0, REG_SZ, ByVal temp, Len(temp) + 1)
End If
If rc <> 0 Then
'エラーコードからエラーメッセージを取得
sError = String(260, vbNullChar)
Call FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, ByVal 0&, rc, 0, sError, Len(sError), 0)
MsgBox sError
Else
MsgBox "「HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run」に設定しました"
End If
Else
'エラーコードからエラーメッセージを取得
sError = String(260, vbNullChar)
Call FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, ByVal 0&, hKey, 0, sError, Len(sError), 0)
MsgBox sError
End If
|