VB.NET WInform为啥更新INI文件不行呢?
Public Function WriteINI(ByVal Section As String, ByVal AppName As String, ByVal lpDefault As String, ByVal FileName As String) As Long
WriteINI = WritePrivateProfileString(Section, AppName, lpDefault, FileName)
End Function
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Int32, ByVal lpFileName As String) As Int32
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Int32
下面是更新INI文件的一段代码
Dim cpath2 As String
Dim ncc as string="新值"
cpath2 = Application.StartupPath + "\Mversion.ini"
'cpath2 = "D:\aaaa\Mversion.ini"
WriteINI("ULI", "Mversion", ncc, cfile2)
以上更新ini文件不行。但如果我将cpath="D:\aaaa\Mversion.ini" 则可以。
注:我的D:盘是有可写的权限的。 请指教一下,谢谢!
[解决办法]
帮顶一下。
错误提示是啥?
cpath2 = Application.StartupPath + "\Mversion.ini"
cpath2路径下Mversion.ini确定是对的不
Application.StartupPath 之前用过一次。。出现问题了。AppDomain.CurrentDomain.SetupInformation.ApplicationBase+ "\Mversion.ini"
这样试一下。。
[解决办法]
低级错误:
Dim cpath2 As String
Dim ncc as string="新值"
cpath2 = Application.StartupPath + "\Mversion.ini"
'cpath2= "D:\aaaa\Mversion.ini"
WriteINI("ULI", "Mversion", ncc, cfile2)
[解决办法]
VB.Net读取ini文件和读取xml文件的例子。两种方法的比较。建议还是用Xml比较好。
http://www.uudisc.com/user/evenlin/file/1917654
源代码直接下载。
[解决办法]
你成功的那个是直接把cpath赋值为"D:\aaaa\Mversion.ini"吗?
你把cpath直接赋值为你程序所在路径然后加上Mversion.ini应该也可以。
msgbox得到的是自动去掉/0和空格的路径。
你trim一下试试吧
[解决办法]
Public Declare Function writeprivateprofilestring Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Integer
Sub WriteIni(ByVal AppName As String, ByVal KeyName As String, ByVal Value1$, ByVal IniFileName As String)
writeprivateprofilestring(AppName, KeyName, Value1, IniFileName)
End Sub