Archive: Problem deleting/writing file in system32


Problem deleting/writing file in system32
Hey I am having a problem overwriting a .dll that is located in the system32 folder. The thing is I can overwrite the file if I do the overwrite before I call a certain function I created. Obviously then my function is screwing up my .nsi script but I don't know how. Here is the function (it is for retrieving a version of a .dll file by passing a struct by reference):

Function loadDll
Var /GLOBAL remDLL

#create temp directory
SetOutPath $TEMP\

#copy dll there
DetailPrint "Copying my.dll to temporary directory...$TEMP"
file "..my.dll"

# allocate 12 bytes for struct
System::Alloc 12

#Pop memory location of struct
Pop $0

#initialize struct
System::Call "*$0(i 0, i 0, i 0)" ;Initialization

#Call getVersion in arpts.dll by reference with struct as argument
System::Call "$TEMP\my.dll::getVersion(i r0)"

#Get values from struct and assign to registries
System::Call "*$0(i.r1, i.r2, i.r3)"

# print values (test)
DetailPrint "New Install DLL Version: $1 . $2 . $3"

#free
System::Free $0

# allocate 12 bytes for struct
System::Alloc 12

#Pop memory location of struct
Pop $4

#initialize struct
System::Call "*$4(i 0, i 0, i 0)" ;Initialization

#Call getVersion in arpts.dll by reference with struct as argument
System::Call "$INSTDIR\my.dll::getVersion(i r4)"

#Get values from struct and assign to registries
System::Call "*$4(i.r5, i.r6, i.r7)"

# print values (test)
DetailPrint "Installed DLL Version: $5 . $6 . $7"

#free
System::Free $4

#compare versions, if the same then Goto skip install
${If} $1 == $5
${If} $2 == $6
${If} $3 == $7
DetailPrint "DLL versions the same, skipping install of my.dll..."
StrCpy $remDLL "0"
${Else}
StrCpy $remDLL "1"
DetailPrint "Overwriting my.dll..."
${EndIf}
${EndIf}
${EndIf}
FunctionEnd


Any ideas as to why I am getting the error:

"Error opening file for writing"

C:\WINDOWS\system32\my.dll

Thanks in advance,
Brett


I think you can't overwrite your installed dll because you implicitly loaded it to check its version. You can either unload it, or make a copy of it and check the version of that copy.


Thanks for the help that was exactly the problem :).