How can I run initialization code each time my snap-in is loaded?

旧巷老猫 提交于 2019-12-24 10:19:28

问题


I have a PowerShell snapin, and I would like to run a bit of initialization code (hooking some AppDomain events) each time my snapin is loaded (i.e. once for each powershell.exe process that is started). How can this be accomplished?


回答1:


One approach, and this is probably a bit rube-goldberg in nature, is to hook into a provider's startup code. This assumes that in your snapin configuration you have declared a default drive to initialize. It just so happens that in PSCX we use a provider to store all of our settings and global variables to minimize impact on the user's global session space. The initialization of this settings drive provided a convenient place for us to hook in other initialization code.

Now if we weren't creating a provider, I assume there is some other way to initialize code early but I don't know off the top of my head.



来源:https://stackoverflow.com/questions/3551771/how-can-i-run-initialization-code-each-time-my-snap-in-is-loaded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!