每次加载管理单元时如何运行初始化代码? [英] How can I run initialization code each time my snap-in is loaded?

查看:105
本文介绍了每次加载管理单元时如何运行初始化代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PowerShell管理单元,并且每次加载管理单元时(即对于每个启动的powershell.exe进程一次),我想运行一些初始化代码(挂钩一些AppDomain事件).如何做到这一点?

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?

推荐答案

一种方法(实际上可能有点像rube-goldberg)是挂接到提供程序的启动代码.假定在管理单元配置中已声明一个默认驱动器进行初始化.碰巧的是,在PSCX中,我们使用提供程序来存储所有设置和全局变量,以最大程度地减少对用户的全局会话空间的影响.此设置驱动器的初始化为我们提供了一个方便的位置,使我们可以挂接到其他初始化代码.

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.

这篇关于每次加载管理单元时如何运行初始化代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆