I assume that you are not trying to prevent the user from changing the file manually, you just want to prevent an additional step that specifically assigns rights to the file.
Most likely you are writing a file located in a protected area (the area that was protected after entering UAC). To avoid this, write the file to one of the "approved" areas, for example% APPDATA%. Here is a list of a few more (assuming C is your boot disk):
C:\Users\username\Documents C:\Users\username\AppData\Local C:\Users\username\AppData\Roaming C:\Users\Public\Documents C:\ProgramData
This article has a whole bunch of information around from which you can blacken bits of choice.
source share