Try this
Public Class Form1
Private Function IsAdmin() As Boolean
Return My.User.IsInRole( _
Microsoft.VisualBasic.ApplicationServices. _
BuiltInRole.Administrator)
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If IsAdmin() = False Then
If System.Environment.OSVersion.Version.Major = 6 Then
MsgBox("Sorry... my app need to run as administrator" & vbCr & "Press ok to Restart in Administrator mode", MsgBoxStyle.Information)
Dim process As System.Diagnostics.Process = Nothing
Dim processStartInfo As System.Diagnostics.ProcessStartInfo
processStartInfo = New System.Diagnostics.ProcessStartInfo()
processStartInfo.FileName = "myapp.exe"
If System.Environment.OSVersion.Version.Major >= 6 Then
processStartInfo.Verb = "runas"
Else
End If
processStartInfo.Arguments = ""
processStartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal
processStartInfo.UseShellExecute = True
Try
process = System.Diagnostics.Process.Start(processStartInfo)
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
If Not (process Is Nothing) Then
process.Dispose()
End If
End Try
End If
End
End If