IWshRuntimeLibrary

J

Jay Dee

I was trying to create an application that was a simple setup wizard
for an application.
The outcome I was looking for was to allow a user to be able to drag
an (.exe) file from a network drive to the desktop and double click
it. this would copy the rest of the application from the network drive
onto the local computer installing the application.

The reason for this approach is because the application will not run
direct from the network drive due to permeations.

I encountered a problem creating the shortcuts required because
IWshRuntimeLibrary also required copying to the desktop along with the
exe file otherwise the setup would fail.

Using .NET Reflector to extract the content of IWshRuntimeLibrary I
attempted to imbed it into the setup application.

The first problem that I encountered was 7 errors that stated

“ref and out are not valid in this context”

A code example that produces this error is as follows;

[ComImport, Guid("F935DC21-1CF0-11D0-ADB9-00C04FD58A0B"), TypeLibType
((short) 0x1050)]
public interface IWshShell
{
[DispId(200)]
IWshEnvironment this[ref object Type] { [return: MarshalAs
(UnmanagedType.Interface)] [MethodImpl(MethodImplOptions.InternalCall,
MethodCodeType=MethodCodeType.Runtime), DispId(200)] get; }
//...
}

I would be grateful if anyone could explain this problem to me in more
detail.

If I remove the “ref” from the above code I am then faced with a lot
of errors stating;

'IWshRuntimeLibrary.DriveClass.IWshRuntimeLibrary.IDrive.AvailableSpace':
virtual or abstract members cannot be private.
The modifier 'virtual' is not valid for this item.
The modifier 'public' is not valid for this item.

A code example that produces this error is as follows;

[ComImport, Guid("C7C3F5B1-88A3-11D0-ABCB-00A0C90FFFC0"), DefaultMember
("Path"), ClassInterface((short) 0)]
public class DriveClass : IDrive, Drive
{
[DispId(0x2715)]
public virtual object IWshRuntimeLibrary.IDrive.AvailableSpace
{ [return: MarshalAs(UnmanagedType.Struct)] [MethodImpl
(MethodImplOptions.InternalCall,
MethodCodeType=MethodCodeType.Runtime), DispId(0x2715)] get; }
//...
}

Basically what I am asking is, is there something simple I can change
that will enable the code produced by .NET Reflector to run in my
application or am I barking up the wrong tree.

I have actually accomplished the task in question by using
{smartassembly} to embed the dll into the executable after creation
but I would like to understand why the code from .Net Reflector
doesn’t compile.

Many thanks to anyone with some input.

Jay Dee
 
P

Peter Duniho

Jay said:
[...]
Basically what I am asking is, is there something simple I can change
that will enable the code produced by .NET Reflector to run in my
application or am I barking up the wrong tree.

Why aren't you just using one of the normal .NET installation mechanisms
intended for this purpose, such as ClickOnce, or even just a plain old
setup project?
I have actually accomplished the task in question by using
{smartassembly} to embed the dll into the executable after creation
but I would like to understand why the code from .Net Reflector
doesn’t compile.

For best results, you should ask someone that has something to do with
the "IWshRuntimeLibrary", whatever that is.

As a general answer: C# supports most of, but not 100%, the features the
..NET CLR supports. So, it's entirely possible to find a managed
executable file (EXE or DLL) that contains some MSIL that can't be
represented in C#.

In the code you posted, it appears that the DLL has COM interop features
in it, which is code that probably was not originally created using C#.
So it may be impossible to recreate it using C#.

Pete
 
J

Jeff Gaines

For best results, you should ask someone that has something to do with the
"IWshRuntimeLibrary", whatever that is.

It's the Windows Script Host Object Model.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top