Posted By: mstefan | Feb 11th, 2007 @ 4:16 AM
page 1 of 1
Comments: 5 | Views: 5119
mstefan
mstefan
Windows SDK coders do it without a .NET
PowerShell has the ability to load an assembly and create an instance of a class; is there a way for the assembly to know that it has been loaded in PS rather than, for example, as a reference in a Windows Forms based application?
Yggdrasil
Yggdrasil
Pour me a cab, 'cause I can't drink no more.
How about this:

Assembly.GetEntryAssembly().GetName().Name == "PowerShell";

Is that what you're looking for?

Yggdrasil
Yggdrasil
Pour me a cab, 'cause I can't drink no more.
mstefan wrote:

Yggdrasil wrote: How about this:

Assembly.GetEntryAssembly().GetName().Name == "PowerShell";

Is that what you're looking for?



Unfortunately that won't work. GetEntryAssembly returns null, presumably because the assembly is being loaded from unmanaged code.

It looks like I'm going to have to use an interop hack and call GetModuleFileName, but I'd prefer to not have to do that.


Process.GetCurrentProcess().MainModule.FileName?

page 1 of 1
Comments: 5 | Views: 5119
Microsoft Communities