Jump to content
Sign in to follow this  
stev379

Unable to manipulate an XLA file

Recommended Posts

stev379

This is failing to overwrite the SofieAddIn.xla file. I've rewritten this trying to FileDelete, FileMove, DirDelete the whole directory and recreate, FileAttrib, but no luck. The DLL and the XLA both have the same attributes, but the dll gets overwritten no problem. Both are READ-ONLY and "File is ready for archiving" and "For fast searching, allow Indexing Service to index this file" are checked on both fiels. The return on the FileInstall for the XLA is always 0.

The date and tested return date on the XLA is 2009/03/10.

How can I overwrite or move or replace the XLA file? Thanks!

$SofieDir = (@ProgramFilesDir & "\Sofie")
$SofieAddIn = ("SofieAddIn.xla")
$AspEncryptDLL = ("AspEncrypt.dll")

If Not FileExists($SofieDir) Then DirCreate($SofieDir)

;AspEncrypt.dll  installation
If FileExists($SofieDir & "\" & $AspEncryptDLL) Then    
    ;Check date
    $DLLt = FileGetTime($SofieDir & "\" & $AspEncryptDLL)
    $DLLyyyymd = $DLLt[0] & "/" & $DLLt[1] & "/" & $DLLt[2]
    If $DLLyyyymd <> "2009/5/14" Then       
        Fileinstall("AspEncrypt.dll", $SofieDir & "\" & $AspEncryptDLL, 1)
        Sleep(3000)
        Run(@ComSpec & " /c regsvr32 /s " & $SofieDir & "\" & $AspEncryptDLL, "", @SW_HIDE)
    EndIf
Else
    Fileinstall("AspEncrypt.dll", $SofieDir & "\" & $AspEncryptDLL, 1)
    Sleep(3000)
    Run(@ComSpec & " /c regsvr32 /s " & $SofieDir & "\" & $AspEncryptDLL, "", @SW_HIDE)
EndIf


;SofieAddIn.xla  add-in installation
If FileExists($SofieDir & "\" & $SofieAddIn) Then
    ;Check date
    $t = FileGetTime($SofieDir & "\" & $SofieAddIn)
    $yyyymd = $t[0] & "/" & $t[1] & "/" & $t[2]

    If $yyyymd = "2010/5/25" Then
        Exit 
    Else
        MsgBox(0,"", "$yyyymd = " & $yyyymd)
        MsgBox(0,"", "About to install " & $SofieDir & "\" & $SofieAddIn)
        
        FileSetAttrib("""C:\Program Files\Sofie\SofieAddIn.xla""", "-RA")
        FileDelete("""C:\Program Files\Sofie\SofieAddIn.xla""")
        
        $SofieAddInFILEINSTLL = FileInstall("SofieAddIn.xla", $SofieDir & "\SofieAddIn.xla", 1)
        
        MsgBox(0,"","$SofieAddInFILEINSTLL " & $SofieAddInFILEINSTLL)
        
    EndIf
Else
    FileInstall("SofieAddIn.xla", $SofieDir & "\" & $SofieAddIn, 1)
EndIf



Sleep(5000)
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Excel\Options", "OPEN", "REG_SZ", """C:\Program Files\Sofie\SofieAddIn.xla""")
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Excel\Options", "OPEN", "REG_SZ", """C:\Program Files\Sofie\SofieAddIn.xla""")

Share this post


Link to post
Share on other sites
evilertoaster

The Filedelete and setattrib have to many " marks, but they shouldn't be needed anyway.

Are you running a compiled .exe or .au3 file?

Have you checked @error?

Is there an anti-virus preventing the script from deleting files?

Share this post


Link to post
Share on other sites
GEOSoft

eviltoaster noticed the same thing I did. You have variables holding the proper path but you still try to use the full path, that makes no sense at all.

$SofieDir = (@ProgramFilesDir & "\Sofie")
$SofieAddIn = ("SofieAddIn.xla")
$AspEncryptDLL = ("AspEncrypt.dll")
FileSetAttrib("""C:\Program Files\Sofie\SofieAddIn.xla""", "-RA")
FileDelete("""C:\Program Files\Sofie\SofieAddIn.xla""")
Else
    FileInstall("SofieAddIn.xla", $SofieDir & "\" & $SofieAddIn, 1)
EndIf
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Excel\Options", "OPEN", "REG_SZ", """C:\Program Files\Sofie\SofieAddIn.xla""")
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Excel\Options", "OPEN", "REG_SZ", """C:\Program Files\Sofie\SofieAddIn.xla""")

Should be

$SofieDir = @ProgramFilesDir & "\Sofie\"
$SofieAddIn = "SofieAddIn.xla"
$AspEncryptDLL = "AspEncrypt.dll"
FileSetAttrib($SofieDir & $SofieAddIn, "-RA")
FileDelete($SofieDir & $SofieAddIn)
Else
    FileInstall("SofieAddIn.xla", $SofieDir & $SofieAddIn, 1)
EndIf
RegWrite("HKCU64\Software\Microsoft\Office\11.0\Excel\Options", "OPEN", "REG_SZ", $SofieDir & $SofieAddIn)
RegWrite("HKCU64\Software\Microsoft\Office\12.0\Excel\Options", "OPEN", "REG_SZ", $SofieDir & $SofieAddIn)

Obviously those lines are not in their proper positions so you will have to find them in your script and make the changes.

In fact I would change

$SofieAddIn = ("SofieAddIn.xla")
$AspEncryptDLL = ("AspEncrypt.dll")

To

$SofieAddIn = $SofieDir & "SofieAddIn.xla"
$AspEncryptDLL = $SofieDir & "AspEncrypt.dll"

Then make the appropriate changes in the code I just gave you. A few message boxes for testing can help you out as well.

The last remaining item is, you can't delete a file that is in use by anything so make sure there are no open file handles and that the files are not currently in use by an application or service.

EDIT: My prefered method of doing this would be to use a proper installer like Inno Setup to handle it all. It's a very simple script in Inno and if that file can't be changed because something has it locked you can have it replaced on restart and force (or not) the restart. There is even a File_in_use extension available for Inno.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×