By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,338 Members | 1,350 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,338 IT Pros & Developers. It's quick & easy.

Vista, C#, and Regsvr32

P: n/a
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
Jan 31 '07 #1
Share this Question
Share on Google+
11 Replies


P: n/a
Your app is either going to have to run as Administrator, or impersonate an
Administrator.

--
HTH,

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

The shortest distance between 2 points is a curve.

"RobKinney1" <Ro********@discussions.microsoft.comwrote in message
news:9F**********************************@microsof t.com...
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


Jan 31 '07 #2

P: n/a
"RobKinney1" <Ro********@discussions.microsoft.comwrote in message
news:9F**********************************@microsof t.com...
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.
Jan 31 '07 #3

P: n/a
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

"Willy Denoyette [MVP]" wrote:
"RobKinney1" <Ro********@discussions.microsoft.comwrote in message
news:9F**********************************@microsof t.com...
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.
Jan 31 '07 #4

P: n/a
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

"Kevin Spencer" wrote:
Your app is either going to have to run as Administrator, or impersonate an
Administrator.

--
HTH,

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

The shortest distance between 2 points is a curve.

"RobKinney1" <Ro********@discussions.microsoft.comwrote in message
news:9F**********************************@microsof t.com...
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


Jan 31 '07 #5

P: n/a
"RobKinney1" <Ro********@discussions.microsoft.comwrote in message
news:5E**********************************@microsof t.com...
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/d...displaylang=en
Willy.

Feb 1 '07 #6

P: n/a
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.

"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:OL**************@TK2MSFTNGP04.phx.gbl...
"RobKinney1" <Ro********@discussions.microsoft.comwrote in message
news:5E**********************************@microsof t.com...
>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/d...displaylang=en
Willy.

Feb 1 '07 #7

P: n/a
Hi Rob,

The following article may be of some help:

http://msdn2.microsoft.com/en-us/lib...xw(VS.80).aspx

--
HTH,

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

The shortest distance between 2 points is a curve.

"RobKinney1" <Ro********@discussions.microsoft.comwrote in message
news:F6**********************************@microsof t.com...
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

"Kevin Spencer" wrote:
>Your app is either going to have to run as Administrator, or impersonate
an
Administrator.

--
HTH,

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

The shortest distance between 2 points is a curve.

"RobKinney1" <Ro********@discussions.microsoft.comwrote in message
news:9F**********************************@microso ft.com...
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




Feb 1 '07 #8

P: n/a
"Kevin Spencer" <un**********@nothinks.comwrote in message
news:e2**************@TK2MSFTNGP04.phx.gbl...
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.
Feb 1 '07 #9

P: n/a
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

"Willy Denoyette [MVP]" wrote:
>
Sure they are, it's a pity they are so hard to find while they are a "must read" for every
Windows developer.

Willy.
Feb 1 '07 #10

P: n/a
"RobKinney1" <Ro********@discussions.microsoft.comwrote in message
news:70**********************************@microsof t.com...
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 <manifestfilename-outputresource:killerapp.exe;#1
..... 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.

Feb 1 '07 #11

P: n/a
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
"Willy Denoyette [MVP]" wrote:
"RobKinney1" <Ro********@discussions.microsoft.comwrote in message
news:70**********************************@microsof t.com...
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 <manifestfilename-outputresource:killerapp.exe;#1
..... 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.
Feb 2 '07 #12

This discussion thread is closed

Replies have been disabled for this discussion.