I need my application to start with administrator
privilege. When I do it in app.manifest:

'<requestedExecutionLevel
level="asInvoker" uiAccess="false" />'

to

'<requestedExecutionLevel
level="RequireAdministrator"
uiAccess="false" />'

I can start my application with administrator privilege.
But it starts every time the application starts. I need to
start the application with administrator privilege only once at
the first time of application usage.

Actually, I need to make the application to start with
windows instead of starting manually. So to do that I
used:

'My.Computer.Registry.LocalMachine.OpenSubK
("SOFTWARE\Microsoft\Windows\CurrentVersio
\Run", True).SetValue
(Application.ProductName,
Application.ExecutablePath)'

But it requires administrator privilege else it fails.

I suggest you create some sort of installation package which runs with admin rights to deal with registry.

But if your actual app needs to also manipulate reg HKLM then that will need admin rights too.

As suzie999 said, the only way to do that is to have a installer app.
So create a installer app in c# and make it copy your main app to its location and then create the registry key.

In your main app, check if the installer app is there and delete it.

Is theren't any ways to edit app.manifest file in runtime?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.