Foro de elhacker.net

Programación => 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
  1. '---------------------------------------------------------------------------------------
  2. ' Module      : mShellElevated
  3. ' DateTime    : 15/07/2008 07:32
  4. ' Author      : Cobein
  5. ' Mail        : cobein27@hotmail.com
  6. ' WebPage     : http://cobein27.googlepages.com/vb6
  7. ' Purpose     : Execute an app requesting admin rights
  8. ' Usage       : At your own risk
  9. ' Requirements: None
  10. ' Distribution: You can freely use this code in your own
  11. '               applications, but you may not reproduce
  12. '               or publish this code on any web site,
  13. '               online service, or distribute as source
  14. '               on any media without express permission.
  15. '
  16. ' History     : 15/07/2008 First Cut....................................................
  17. '---------------------------------------------------------------------------------------
  18. Option Explicit
  19.  
  20. Private Type SHELLEXECUTEINFO
  21.    cbSize          As Long
  22.    fMask           As Long
  23.    hwnd            As Long
  24.    lpVerb          As String
  25.    lpFile          As String
  26.    lpParameters    As String
  27.    lpDirectory     As String
  28.    nShow           As Long
  29.    hInstApp        As Long
  30.    lpIDList        As Long
  31.    lpClass         As String
  32.    hkeyClass       As Long
  33.    dwHotKey        As Long
  34.    hIcon           As Long
  35.    hProcess        As Long
  36. End Type
  37.  
  38. Private Declare Function ShellExecuteEx Lib "shell32.dll" (SEI As SHELLEXECUTEINFO) As Long
  39.  
  40. Public Function ShellElevated( _
  41.       ByVal sPath As String, _
  42.       Optional ByVal sParameters As String, _
  43.       Optional ByVal sDirectory As String, _
  44.       Optional ByVal eWindowstyle As VbAppWinStyle = vbNormalFocus) As Long
  45.  
  46.    Dim tSHELLEXECUTEINFO As SHELLEXECUTEINFO
  47.  
  48.    With tSHELLEXECUTEINFO
  49.        .cbSize = Len(tSHELLEXECUTEINFO)
  50.        .lpVerb = "runas"
  51.        .lpFile = sPath
  52.        .lpParameters = sParameters
  53.        .lpDirectory = sDirectory
  54.        .nShow = eWindowstyle
  55.        .hInstApp = App.hInstance
  56.    End With
  57.  
  58.    ShellElevated = ShellExecuteEx(tSHELLEXECUTEINFO)
  59. End Function
  60.  
  61.