How to get an Unix like atexit in Powershell? -


When creating an OLE object it is necessary to release it at the end of the program. Otherwise this process continues in the background.

I have written the following example:

  $ excel = new-object -ComObject Excel.Application # The code running for some long time is finally {"going on {end} "[System.Runtime.Interopservices.Marshal] :: ReleaseComObject ($ excel)}  

When I stop the script with Ctrl - "Long-lasting code" in between the C does not end in the block. Whenever I do this, I get another Excel .EXE process in the process table.

How can I release the COM object reliably even if the user has Ctrl - C ?

Try (works only in the console, not PowerHail ISE):

  Set auto-functionality on exit # engine. Register-Engineer PowerShell.Exporting -Support Event -Action {[System.Runtime.Interopservices.Marshal] :: Release Com Object ($ excel)}  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -