最简单的写INI文件
Private 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
Private Declare Function WritePrivateProfileString Lib "Kernel32" Alias "WritePrivateProfileStringA" (ByVal AppName As String, ByVal KeyName As String, ByVal keydefault As String, ByVal Filename As String) As LongPrivate sDefInitFileName As String'读取Ini文件
Public Function GetInitEntry(ByVal sSection As String, ByVal sKeyName As String, Optional ByVal sDefault As String = "", Optional ByVal sInitFileName As String = "") As StringDim sBuffer As String
Dim sInitFile As String    If Len(sInitFileName) = 0 Then
        If Len(sDefInitFileName) = 0 Then
            sDefInitFileName = App.Path
            If Right$(sDefInitFileName, 1) <> "\" Then
                sDefInitFileName = sDefInitFileName & "\"
            End If
            sDefInitFileName = sDefInitFileName & App.EXEName & ".ini"
        End If
        sInitFile = sDefInitFileName
    Else
        sInitFile = sInitFileName
    End If
    
    sBuffer = String$(2048, " ")
    GetInitEntry = Left$(sBuffer, GetPrivateProfileString(sSection, ByVal sKeyName, sDefault, sBuffer, Len(sBuffer), sInitFile))End Function'写Ini文件
Public Function SetInitEntry(ByVal sSection As String, Optional ByVal sKeyName As String, Optional ByVal sValue As String, Optional ByVal sInitFileName As String = "") As LongDim sInitFile As String    If Len(sInitFileName) = 0 Then
        If Len(sDefInitFileName) = 0 Then
            sDefInitFileName = App.Path
            If Right$(sDefInitFileName, 1) <> "\" Then
                sDefInitFileName = sDefInitFileName & "\"
            End If
            sDefInitFileName = sDefInitFileName & App.EXEName & ".ini"
        End If
        sInitFile = sDefInitFileName
    Else
        sInitFile = sInitFileName
    End If
    
    If Len(sKeyName) > 0 And Len(sValue) > 0 Then
        SetInitEntry = WritePrivateProfileString(sSection, ByVal sKeyName, ByVal sValue, sInitFile)
    ElseIf Len(sKeyName) > 0 Then
        SetInitEntry = WritePrivateProfileString(sSection, ByVal sKeyName, vbNullString, sInitFile)
    Else
        SetInitEntry = WritePrivateProfileString(sSection, vbNullString, vbNullString, sInitFile)
    End IfEnd Function

解决方案 »

  1.   

    写到注册表里面去或者写到INI文件中,或者写到数据库中.系统启动的时候读取.
      

  2.   

    用数据库、注册表、INI文件,或自定义文件都行,根据你的系统要求。
      

  3.   

    1。保存在TXT中
    2。保存在注册表中
    3。保存在数据库中
    4。保存在你想要的任何地方
      

  4.   

    将密码存放在系统目录下的一个隐藏文件里就可以了

    open "filename" for output as 1'写
    open "filename" for input as 1'读
      

  5.   

    数据库、注册表、INI文件,或自定义文件都行
    可别让人找到
      

  6.   

    to: gump2000(阿甘) 
    给我发个实例吧
    [email protected]
    多谢!
    TO:netghost  你该会做了我就不多说了:)
      

  7.   

    您的信件已经成功发送到 [email protected]
      

  8.   

    Private Sub cmdLogin_Click()
        Dim pwd As String
        
        'pwd = Encrypt_String(GetInitEntry("SYSTEM", "PASSWORD", "", App.Path & "\system.ini"))
        pwd = Encrypt_String(GetSetting("Test App", "SYSTEM", "Password", ""))
        If Text1.Text <> pwd Then
            MsgBox "Error Password!"
            Text1.SetFocus
            SendKeys "{HOME}+{END}"
            Exit Sub
        End If
        frmMDPW.Show
        Unload Me
    End Sub
    Private Sub cmdChg_Click()
        Dim oldpwd As String
        
        'oldpwd = Encrypt_String(GetInitEntry("SYSTEM", "PASSWORD", "", App.Path & "\system.ini"))
        oldpwd = Encrypt_String(GetSetting("Test App", "SYSTEM", "Password", ""))
        
        If Text1.Text <> oldpwd Then
            MsgBox "Invalid Old Password!"
                    Text1.SetFocus
            SendKeys "{HOME}+{END}"
            Exit Sub
        End If
        
        'SetInitEntry "SYSTEM", "PASSWORD", Encrypt_String(Text2.Text), App.Path & "\system.ini"
        SaveSetting "Test App", "SYSTEM", "Password", Encrypt_String(Text2.Text)
        MsgBox "Password Changed!"
        Unload Me
        frmLogin.Show
    End Sub您吧那两个过程改成以上就是写注册表了
      

  9.   

    读写INI文件的四个函数'文件名SourceDB.ini文件
    Private 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
    Private Declare Function WritePrivateProfileString Lib "kernel32" Alias 
    "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal 
    lpString As Any, ByVal lpFileName As String) As Long'以下两个函数,读/写ini文件,固定节点setting,in_key为写入/读取的主键
    '仅仅针对是非值
    'Y:yes,N:no,E:error
    Public Function GetIniTF(ByVal In_Key As String) As Boolean
    On Error GoTo GetIniTFErr
    GetIniTF = True
    Dim GetStr As String
    GetStr = VBA.String(128, 0)
    GetPrivateProfileString "Setting", In_Key, "", GetStr, 256, App.Path & "\SourceDB.ini"
    GetStr = VBA.Replace(GetStr, VBA.Chr(0), "")
    If GetStr = "1" Then
       GetIniTF = True
       GetStr = ""
    Else
       GoTo GetIniTFErr
    End If
    Exit Function
    GetIniTFErr:
       Err.Clear
       GetIniTF = False
       GetStr = ""
    End FunctionPublic Function WriteIniTF(ByVal In_Key As String, ByVal In_Data As Boolean) As Boolean
    On Error GoTo WriteIniTFErr
    WriteIniTF = True
    If In_Data = True Then
     WritePrivateProfileString "Setting", In_Key, "1", App.Path & "\SourceDB.ini"
    Else
     WritePrivateProfileString "Setting", In_Key, "0", App.Path & "\SourceDB.ini"
    End If
    Exit Function
    WriteIniTFErr:
       Err.Clear
       WriteIniTF = False
    End Function
    '以下两个函数,读/写ini文件,不固定节点,in_key为写入/读取的主键
    '针对字符串值
    '空值表示出错
    Public Function GetIniStr(ByVal AppName As String, ByVal In_Key As String) As String
    On Error GoTo GetIniStrErr
    If VBA.Trim(In_Key) = "" Then
       GoTo GetIniStrErr
    End If
    Dim GetStr As String
    GetStr = VBA.String(128, 0)
     GetPrivateProfileString AppName, In_Key, "", GetStr, 256, App.Path & "\SourceDB.ini"
      GetStr = VBA.Replace(GetStr, VBA.Chr(0), "")
    If GetStr = "" Then
       GoTo GetIniStrErr
    Else
       GetIniStr = GetStr
       GetStr = ""
    End If
    Exit Function
    GetIniStrErr:
       Err.Clear
       GetIniStr = ""
       GetStr = ""
    End FunctionPublic Function WriteIniStr(ByVal AppName As String, ByVal In_Key As String, ByVal In_Data As String) As Boolean
    On Error GoTo WriteIniStrErr
    WriteIniStr = True
    If VBA.Trim(In_Data) = "" Or VBA.Trim(In_Key) = "" Or VBA.Trim(AppName) = "" Then
       GoTo WriteIniStrErr
    Else
     WritePrivateProfileString AppName, In_Key, In_Data, App.Path & "\SourceDB.ini"
    End If
    Exit Function
    WriteIniStrErr:
       Err.Clear
       WriteIniStr = False
    End Function
           以上代码来自: 源代码数据库(SourceDataBase)
               复制时间: 2002-04-12 13:30:57
               当前版本: 1.0.575
                   作者: Shawls
               个人主页: Http://Shawls.Yeah.Net
                 E-Mail: [email protected]
                     QQ: 9181729
      

  10.   

    我要的是写到EXE 文件理的方法.!!谢了!
      

  11.   

    www.21code.com上有例子
    找找...:)
      

  12.   

    您的信件已经成功发送到 [email protected]处理的例子
      

  13.   

    [email protected] 这是我的,也给我发发吧.!谢谢
      

  14.   

    SaveSetting "MyPassWord", system,Password, 密码
      

  15.   

    eflags(EFLAGS):
    如何将密码写到EXE中??
    请赐教~~