Test Foro de elhacker.net SMF 2.1

Programación => .NET (C#, VB.NET, ASP) => Programación General => Programación Visual Basic => Mensaje iniciado por: cobein en 15 Julio 2008, 12:37 PM

Título: ShellElevated [snippet]
Publicado por: cobein en 15 Julio 2008, 12:37 PM
Bueno aca les dejo un mini codigo para ejecutar una aplicacion requiriendo permisos de administrador.
Para verlo en funcionamiento usen Vista con el UAC activado.

Código (vb) [Seleccionar]

'---------------------------------------------------------------------------------------
' Module      : mShellElevated
' DateTime    : 15/07/2008 07:32
' Author      : Cobein
' Mail        : cobein27@hotmail.com
' WebPage     : http://cobein27.googlepages.com/vb6
' Purpose     : Execute an app requesting admin rights
' Usage       : At your own risk
' Requirements: None
' Distribution: You can freely use this code in your own
'               applications, but you may not reproduce
'               or publish this code on any web site,
'               online service, or distribute as source
'               on any media without express permission.
'
' History     : 15/07/2008 First Cut....................................................
'---------------------------------------------------------------------------------------
Option Explicit

Private Type SHELLEXECUTEINFO
    cbSize          As Long
    fMask           As Long
    hwnd            As Long
    lpVerb          As String
    lpFile          As String
    lpParameters    As String
    lpDirectory     As String
    nShow           As Long
    hInstApp        As Long
    lpIDList        As Long
    lpClass         As String
    hkeyClass       As Long
    dwHotKey        As Long
    hIcon           As Long
    hProcess        As Long
End Type

Private Declare Function ShellExecuteEx Lib "shell32.dll" (SEI As SHELLEXECUTEINFO) As Long

Public Function ShellElevated( _
       ByVal sPath As String, _
       Optional ByVal sParameters As String, _
       Optional ByVal sDirectory As String, _
       Optional ByVal eWindowstyle As VbAppWinStyle = vbNormalFocus) As Long
       
    Dim tSHELLEXECUTEINFO As SHELLEXECUTEINFO

    With tSHELLEXECUTEINFO
        .cbSize = Len(tSHELLEXECUTEINFO)
        .lpVerb = "runas"
        .lpFile = sPath
        .lpParameters = sParameters
        .lpDirectory = sDirectory
        .nShow = eWindowstyle
        .hInstApp = App.hInstance
    End With
   
    ShellElevated = ShellExecuteEx(tSHELLEXECUTEINFO)
End Function