Pasar parámetros a SHELL.

29/07/2003 - 11:18 por Infor | Informe spam
Buenos días a todos, necesito poder pasar un parámetro a la ejecución de
Shell, adjunto ejemplo de lo que estoy haciendo:

Module Module1

'Definimos la variable que contendrá la ruta del programa.

Dim Clave As String

Dim Back As Long

Sub Main()

Clave = "prueba"

Back = Shell("runas.exe /env /user:es\administrator
c:\windows\system32\calc.exe", AppWinStyle.NormalFocus)

End Sub

End Module

Después de esto, me abre la ventana de MSDOS en la que espera a que yo le
introduzca la contraseña, pero lo que necesito es pasarla por parámetro,
dado que el usuario no debe conocerla.





Un saludo y gracias.
 

Leer las respuestas

#1 Eduardo A. Morcillo [MS MVP]
29/07/2003 - 17:57 | Informe spam
Si lo que deseas es ejecutar una aplicacion usando otra cuenta de usuario
puedes usar esto:

Enum ProcessPriorityClass
RealtimeClass = &H100&
HighClass = &H80&
AboveNormalClass = &H8000&
NormalClass = &H20&
BelowNormalClass = &H4000&
IdleClass = &H40&
End Enum

Private Type STARTUPINFO
cb As Long
lpReserved As Long
lpDesktop As Long
lpTitle As Long
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type

Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type

Private Declare Function CreateProcessWithLogonW Lib "advapi32" ( _
ByVal lpUserName As Long, ByVal lpDomain As Long, _
ByVal lpPassword As Long, ByVal dwLogonFlags As Long, _
ByVal lpApplicationName As Long, ByVal lpCommandLine As Long, _
ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, _
ByVal lpCurrentDirectory As Long, lpStartupInfo As STARTUPINFO, _
lpProcessInfo As PROCESS_INFORMATION) As Long

Private Declare Function CloseHandle Lib "kernel32" ( _
ByVal hObject As Long) As Long

Private Const LOGON_WITH_PROFILE = &H1

Public Function RunAs( _
ByVal CmdLine As String, _
ByVal User As String, _
ByVal Password As String, _
Optional ByVal Priority As ProcessPriorityClass = NormalClass, _
Optional WindowStyle As VbAppWinStyle = vbNormalFocus, _
Optional ByVal Domain As String, _
Optional ByVal WithProfile As Boolean = True) As Long

Dim tSI As STARTUPINFO
Dim tPI As PROCESS_INFORMATION
Dim lFlags As Long
Dim lRes As Long

With tSI
.cb = Len(tSI)
.wShowWindow = WindowStyle
End With

lFlags = Priority
If WithProfile Then lFlags = lFlags Or LOGON_WITH_PROFILE

' Launch the process
lRes = CreateProcessWithLogonW( _
StrPtr(User), _
StrPtr(Domain), _
StrPtr(Password), _
lFlags, 0&, _
StrPtr(CmdLine), _
0, 0, 0, tSI, tPI)

If lRes Then

' Close the process and thread handles
CloseHandle tPI.hProcess
CloseHandle tPI.hThread

' Return process ID
RunAs = tPI.dwProcessId

Else
Err.Raise &H80070000 Or Err.LastDllError
End If

End Function

Por ejemplo:

RunAs "c:\windows\system32\calc.exe","Administrador","Contraseña"

Eduardo A. Morcillo [MS MVP - VB]
http://www.mvps.org/emorcillo

Preguntas similares