Solved

Setup - Run As Administrator?

Posted on 2012-04-05
7
356 Views
Last Modified: 2012-04-05
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.

TIA
0
Comment
Question by:Clif
  • 4
  • 3
7 Comments
 
LVL 38

Accepted Solution

by:
PaulHews earned 500 total points
Comment Utility
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" />
0
 
LVL 10

Author Comment

by:Clif
Comment Utility
This will solve my problem (on Windows 7)?

There is no solution when running under Win XP?
0
 
LVL 38

Expert Comment

by:PaulHews
Comment Utility
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"

Process.Start(psi)

Open in new window

0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 10

Author Comment

by:Clif
Comment Utility
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?
0
 
LVL 38

Expert Comment

by:PaulHews
Comment Utility
Maybe...  Try this.  Your project has to use Sub Main to launch:
    Public Sub Main()

        If IsRunningAsLocalAdmin() Then
            Application.Run(Form1)
        Else

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

            Process.Start(psi)
        End If

       
    End Sub

    'Function from here: http://blogs.msdn.com/b/jaredpar/archive/2007/08/01/detecting-if-you-are-an-admin.aspx
    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
        Next

        Return False
    End Function

Open in new window

0
 
LVL 10

Author Closing Comment

by:Clif
Comment Utility
If you can answer my last question, fine.  If not, that's ok.

Thanks.  :)
0
 
LVL 10

Author Comment

by:Clif
Comment Utility
Thanks.  :)
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now