Setup - Run As Administrator?

I'm working with VB.Net 2010 (Pro)

I've written a couple of applications for our engineers.  It seems like once a week or so I get an defect call (from different engineers) saying the app can't read from it's settings folder.  I have traced this down to the fact that the app has to be run "as administrator".  

One would think that an engineer would pay attention to the install and run directions, but that's neither here nor there.

Suffice it to say, I'm getting tired of repeating myself and telling the engineers to rtfm.

Is there any way I can setup the deployment so that my app will always "run as administrator"?

The setup project I've been using is "Visual Studio Installer" / "Setup Project", and I would like to retain that, if possible.

LVL 10
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can make your program request elevation by adding a manifest.  (This won't work if the system is running XP)

Go to project properties.  Select application tab.  Click the button for "View Windows Settings"

Find the line in the manifest that says
<requestedExecutionLevel  level="asInvoker" uiAccess="false" />
and change it to
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ClifAuthor Commented:
This will solve my problem (on Windows 7)?

There is no solution when running under Win XP?
The solution for XP seems to be to create an extra program that launches the main program with a "runas" command.
Dim psi As New ProcessStartInfo
psi.Verb = "runas"
psi.UseShellExecute = True
psi.FileName = "notepad.exe"


Open in new window

Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

ClifAuthor Commented:
Is it possible to put this in the startup routine of my app that will re-start my app in administrator mode, and of course shut down the first instance once the second has been started?
Maybe...  Try this.  Your project has to use Sub Main to launch:
    Public Sub Main()

        If IsRunningAsLocalAdmin() Then

            Dim psi As New ProcessStartInfo
            psi.Verb = "runas"
            psi.UseShellExecute = True
            psi.FileName = Application.ExecutablePath

        End If

    End Sub

    'Function from here:
    Function IsRunningAsLocalAdmin() As Boolean
        Dim cur As WindowsIdentity = WindowsIdentity.GetCurrent()
        For Each role As IdentityReference In cur.Groups
            If role.IsValidTargetType(GetType(SecurityIdentifier)) Then
                Dim sid As SecurityIdentifier = DirectCast(role.Translate(GetType(SecurityIdentifier)), SecurityIdentifier)
                If sid.IsWellKnown(WellKnownSidType.AccountAdministratorSid) OrElse sid.IsWellKnown(WellKnownSidType.BuiltinAdministratorsSid) Then
                    Return True
                End If

            End If

        Return False
    End Function

Open in new window

ClifAuthor Commented:
If you can answer my last question, fine.  If not, that's ok.

Thanks.  :)
ClifAuthor Commented:
Thanks.  :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.