Vista, C#, and Regsvr32

G

Guest

Hello,

We are testing and tweaking some of our software to run on Vista, but it
turns out that we are having problems with one of our programs.

Here is our code:

// attempt an experiment to register an OCX object in silient mode
try
{
System.Diagnostics.Process.Start("regsvr32.exe", " /s \"" +
Environment.CurrentDirectory + "\\myTempLib.ocx\"");
}
catch (Exception exec)
{
....
}

However, this is not registering properly... it fails. I can only do this
in Vista manually if I run the CMD.exe as administrator.

Is there a different way of doing this now? Is there a call to the OS that I
can make that will bring up the confirmation dialog to the user to allow my
program to somehow register this library?

Thanks,

Rob
 
W

Willy Denoyette [MVP]

RobKinney1 said:
Hello,

We are testing and tweaking some of our software to run on Vista, but it
turns out that we are having problems with one of our programs.

Here is our code:

// attempt an experiment to register an OCX object in silient mode
try
{
System.Diagnostics.Process.Start("regsvr32.exe", " /s \"" +
Environment.CurrentDirectory + "\\myTempLib.ocx\"");
}
catch (Exception exec)
{
...
}

However, this is not registering properly... it fails. I can only do this
in Vista manually if I run the CMD.exe as administrator.

Is there a different way of doing this now? Is there a call to the OS that I
can make that will bring up the confirmation dialog to the user to allow my
program to somehow register this library?

Thanks,

Rob


Regsvr32 needs "administrative" privileges to register COM components, so you need to run
your program from a command prompt that was started with "Run As Administrator", or you have
to add an application manifest to your application. This application manifest must set the
"requestedExecutionLevel" to "requireAdministrator".
Application manifests can be added to an assembly by running mt.exe.
For more info read this:
http://msdn2.microsoft.com/en-us/library/aa480150.aspx


Willy.
 
G

Guest

Excellent Willy! Thank you. Now if only I can figure out how to do this
with ClickOnce. This is a ClickOnce app and the manifests created with
MageUI are set at full trust (there is no requireAdministrator that I can
see). I will experiment some more with manifests and see if I can figure
out how to set this. Sounds like a likely culprit. :~}

Thank you for the link to the article. I have been looking for that type of
document for some time now.

Rob
 
G

Guest

Thank you for replying Spencer. I will look into this as soon as I can. I
just have to figure out how to have the application launch as administrator
since it is a ClickOnce app....

Thanks!

Rob
 
W

Willy Denoyette [MVP]

RobKinney1 said:
Excellent Willy! Thank you. Now if only I can figure out how to do this
with ClickOnce. This is a ClickOnce app and the manifests created with
MageUI are set at full trust (there is no requireAdministrator that I can
see). I will experiment some more with manifests and see if I can figure
out how to set this. Sounds like a likely culprit. :~}

Thank you for the link to the article. I have been looking for that type of
document for some time now.

Rob,

Before you start experimenting, you should definitely read this:

http://www.microsoft.com/downloads/...69-A648-49AF-BC5E-A2EEBB74C16B&displaylang=en


Willy.
 
K

Kevin Spencer

Both excellent references. I have had Vista on my home machine for a few
weeks now, and have been wanting to find such guidelines, as it is clear
that certain types of applications will need special priveleges. I have
tried a few of my .Net 2.0 apps on that machine, and they run fine, but they
don't try to do anything that requires Administrative privelege, or access
to the registry. These 2 docs are now in my Favorites and Documents. Thanks
Willy!

--

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

The shortest distance between 2 points is a curve.
 
W

Willy Denoyette [MVP]

Kevin Spencer said:
Both excellent references. I have had Vista on my home machine for a few weeks now, and
have been wanting to find such guidelines, as it is clear that certain types of
applications will need special priveleges. I have tried a few of my .Net 2.0 apps on that
machine, and they run fine, but they don't try to do anything that requires Administrative
privelege, or access to the registry. These 2 docs are now in my Favorites and Documents.
Thanks Willy!

Sure they are, it's a pity they are so hard to find while they are a "must read" for every
Windows developer.

Willy.
 
G

Guest

Hello Willy,

I have been at this all day today... We have been trying to insert the code
<requestedPrivileges>
<requestedExecutionLevel
level="requireAdministrator"
uiAccess="false"/>
</requestedPrivileges>

in our application manifest but we keep getting errors like:

The element 'PermissionSet' in namespace 'urn:schemas-microsoft-com:asm.v2'
has invalid child element 'requestedExecutionLevel' in namespace
'urn:schemas-microsoft-com:asm.v2'. List of possible elements expected:
'IPermission, Permission' in namespace 'urn:schemas-microsoft-com:asm.v2' as
well as any element in namespace '##other'.

We have tried to add the requireAdministrator level everywhere possible in
the security tag and cannot get the application to launch.

...... I then quested to use the RUNAS command in the shell command to run
reg32... no luck.

Then I went and tried running/calling DllRegisterServer in my code... --
that works only if I right click on the executable (this was a small local
test to see if I could get the library to register or at least bring up the
UAC box) and tell it to run as Administrator.

Any other ideas? Am I missing something simple? I am combing the net and
have found about 4 other people that have extremely similar problems, but
they never posted a resolution.

Thanks again for your time.

Rob
 
W

Willy Denoyette [MVP]

RobKinney1 said:
Hello Willy,

I have been at this all day today... We have been trying to insert the code
<requestedPrivileges>
<requestedExecutionLevel
level="requireAdministrator"
uiAccess="false"/>
</requestedPrivileges>

in our application manifest but we keep getting errors like:

The element 'PermissionSet' in namespace 'urn:schemas-microsoft-com:asm.v2'
has invalid child element 'requestedExecutionLevel' in namespace
'urn:schemas-microsoft-com:asm.v2'. List of possible elements expected:
'IPermission, Permission' in namespace 'urn:schemas-microsoft-com:asm.v2' as
well as any element in namespace '##other'.

We have tried to add the requireAdministrator level everywhere possible in
the security tag and cannot get the application to launch.

The assembly manifest should look something like :

<?xml version="1.0" encoding="utf-8" ?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0"
processorArchitecture="X86"
name="xxxxxxxxxxx"
type="win32" />
<description>yyyyyyyyyyyyyyy</description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" />
</requestedPrivileges>
</security>
</trustInfo>
</assembly>

Where xxxxxxxx is the executable name (fi. killerapp) and yyyyyyy some application
description.
Inserting the manifest in the assembly goes with:

mt -manifest said:
..... I then quested to use the RUNAS command in the shell command to run
reg32... no luck.

You have to start the shell with "Run As Adminsistrator"....


Willy.
 
G

Guest

Willy,

We are so close!... well, at least I think we are.

We finally were able to understand the concept of embedding the manifest you
provided for us as part of the executable. And in fact when I look at the
exe icon, it now has a little shield in the lower right-hand corner.

We can launch the program locally and it works great! It brings up the UAC
box and asks if the user wants to continue... and when it does, the
application loads perfectly.

However, we cannot get it to work with the ClickOnce deployment. Every
time we try to use the exe with the embedded manifest, we get the following
error:

Reference in the manifest does not match the identity of the downloaded
assembly [ourApp.exe].

We did some searching on the net but still cannot find the solution. When
we do not use the exe with the embedded manifest, the project downloads and
starts up fine (although the library is not able to load and the program soon
crashes as was the original problem).

Do you know if there is a problem using an embedded manifest in the exe
while deploying through ClickOnce? If so, is there a workaround?

Thanks again Willy. We really appreciate the help :~}

Rob
 

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