Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

vb6.0 how can I modify the .ini file which is in c:windows ?

zyliaoyangzyliaoyang Member Posts: 1
Now,I have a problem when I want to modify the .ini file which is in c:windows.



In Vb6.0, I use winapi to access .ini file as follow:

//Declare Function

Declare Function ModifyIniFile Lib "Kernel32" Alias "WritePrivateProfileStringA" (

ByVal lpApplicationName As String,

ByVal lpKeyName As Any,

ByVal lpString As Any,

ByVal lplFileName As String) As Long



// Call Function to modify .ini file

// For example: strModifySectionName = "System"

// strModifyKeyName = "lochostname"

// strSetKeyValue = "NewLocHostName"

// strIniFileInfo = "Test.ini" **not a full path**



dim iRes as Long = ModifyIniFile(strModifySectionName,

strModifyKeyName,

strSetKeyValue,

strIniFileInfo)



The "Test.ini" file is saved in c:windows.

The content of Test.ini as follow:

[System]

lochostname = OldLocHostName



I run the program but it is strange.



The "Test.ini" of c:windows is not changed.

But the new "Test.ini" is created to the directory of

C:Documents and SettingsAdministratorsWINDOWS.

**** The current user account is "Administrtor".

Why?



It should be to access the "c:windows"

if the lpFileName is not a full path by the WinAPI Document.

But it seems like it copy the "c:windowTest.ini" to

C:Documents and SettingsAdministratorsWINDOWS firstly,

then it modify the new "Test.ini" in C:Documents and SettingsAdministratorsWINDOWS.



If you konw the reason .Please help me.

Many Thanks.



Sign In or Register to comment.