Loading EXE in the Application [Assembly]?

S

sajin

Hi,

I am trying to load an executable as assembly (this exe is not .net
made, it is just an exe made using install shield). I am using the
following code to load

Assembly myAssembly = Assembly.LoadFrom(@"C:\setup.exe");
it is giving me the error that "BadImageFormatException"


Plzzzz Help...
Regards
-Sajin
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Of course, because it;s not an assembly. It's not even managed code.

What are you trying to do?

I think that you want to execute the program, if that;s so use Process.Start
 
N

Nicholas Paldino [.NET/C# MVP]

Sajin,

If the assembly is not managed, then you can not call the static methods
on the Assembly class to execute it.

If you need to execute the assembly, you will want to pass the path of
the executable to the static Start method on the Process class, like so:

Process.Start(@"C:\setup.exe");

Hope this helps.
 
S

sajin

Hi,
I have a setup file which is created by Install shield, it is signed
with test.cert and a private key, i want to read the public key from
the exe.if i use .net exe, it is giving me the answer


public X509Certificate GetAuthenticodeCertificate(Assembly target)
{
X509Certificate certificate = null;
foreach (object item in target.Evidence)
{
Publisher publisher = item as Publisher;
if (publisher != null)
{
certificate = publisher.Certificate;
break;
}
}

return certificate;
}

i have to pass the exe as assembly to this function.
 
N

Nicholas Paldino [.NET/C# MVP]

That's the thing, it won't give you an answer because the Assembly is a
^managed^ assembly in the GetAuthenticodeCertificate method. You are not
working with a managed assembly, it's that simple.

You have to get the certificate through other means.
 
S

sajin

So is there any solution?

That's the thing, it won't give you an answer because the Assembly is a
^managed^ assembly in the GetAuthenticodeCertificate method. You are not
working with a managed assembly, it's that simple.

You have to get the certificate through other means.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




Hi,
I have a setup file which is created by Install shield, it is signed
with test.cert and a private key, i want to read the public key from
the exe.if i use .net exe, it is giving me the answer
public X509Certificate GetAuthenticodeCertificate(Assembly target)
{
X509Certificate certificate = null;
foreach (object item in target.Evidence)
{
Publisher publisher = item as Publisher;
if (publisher != null)
{
certificate = publisher.Certificate;
break;
}
}
return certificate;
}
i have to pass the exe as assembly to this function.

- Show quoted text -
 

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