'使用INI File保存配置,不过不安全 Public Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As LongPublic Function GetINIString(ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal nSize As Long, ByVal lpFileName As String) As StringOn Error GoTo On_Error
Private Sub Command7_Click() '保存数据库连接信息 Open App.Path & "\login.txt" For Output As #1 Print #1, Text5.Text Print #1, Text6.Text Print #1, Text7.Text Print #1, Text8.Text Close #1 MsgBox "保存成功,请重新开启程序", vbInformation, "保存" Unload Me End SubPrivate Sub Command7_Click() Dim Ts as string dim Strdatabase AS STRING dim Struid as stringdim Strpwd as stringdim Strserver as string If Dir(App.Path & "\Login.txt") <> "" Then Open App.Path & "\login.txt" For Input As #1 Line Input #1, Ts Text5.Text = Ts Strdatabase = Ts Line Input #1, Ts Text6.Text = Ts Struid = Ts Line Input #1, Ts Text7.Text = Ts Strpwd = Ts Line Input #1, Ts Text8.Text = Ts Strserver = Ts Close #1 Else MsgBox "数据配置文件丢失!", vbExclamation, "丢失" GoTo err: End Ifexit sub err: end sub
RegCreateKey :建注册表项
RegSetValueEx :为某项赋值
RegCloseKey :赋值后请关闭
RegQueryValueEx :查找该值
就是把你现在连接的SQL信息写文件是还是不是?
Public Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As LongPublic Function GetINIString(ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal nSize As Long, ByVal lpFileName As String) As StringOn Error GoTo On_Error
Dim strTemp As String * 255
Dim lngLength As Long
lngLength = GetPrivateProfileString(lpApplicationName, lpKeyName, "", strTemp, nSize, lpFileName)
GetINIString = Left(strTemp, lngLength) Exit FunctionOn_Error: MsgBox Err.Description, vbInformation
Exit Function
End Function
'保存数据库连接信息
Open App.Path & "\login.txt" For Output As #1
Print #1, Text5.Text
Print #1, Text6.Text
Print #1, Text7.Text
Print #1, Text8.Text
Close #1
MsgBox "保存成功,请重新开启程序", vbInformation, "保存"
Unload Me
End SubPrivate Sub Command7_Click()
Dim Ts as string
dim Strdatabase AS STRING
dim Struid as stringdim Strpwd as stringdim Strserver as string
If Dir(App.Path & "\Login.txt") <> "" Then
Open App.Path & "\login.txt" For Input As #1
Line Input #1, Ts
Text5.Text = Ts
Strdatabase = Ts
Line Input #1, Ts
Text6.Text = Ts
Struid = Ts
Line Input #1, Ts
Text7.Text = Ts
Strpwd = Ts
Line Input #1, Ts
Text8.Text = Ts
Strserver = Ts
Close #1
Else
MsgBox "数据配置文件丢失!", vbExclamation, "丢失"
GoTo err:
End Ifexit sub
err:
end sub