?
Solved

Setup - Run As Administrator?

Posted on 2012-04-05
7
Medium Priority
?
376 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 38

Accepted Solution

by:
PaulHews earned 2000 total points
ID: 37812813
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
ID: 37812965
This will solve my problem (on Windows 7)?

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

Expert Comment

by:PaulHews
ID: 37812983
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Author Comment

by:Clif
ID: 37813192
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
ID: 37813347
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
ID: 37813349
If you can answer my last question, fine.  If not, that's ok.

Thanks.  :)
0
 
LVL 10

Author Comment

by:Clif
ID: 37813661
Thanks.  :)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

800 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