| |||
Re: Llamada de Apis de Windows Hola, Del tema se dice mucho, si estas trabajando con WinXP te recomiendo que busques informacion sobre Crear escritorios (CreateDesktop()), ahorita tengo un programa que hace mas o menos lo que quires, escribeme a [email protected] y te paso el proyecto completo (VB6.0 y VB.NET 2003) y es muy probable que funcione para VB.NET 2005 te lo adjuntaria aqui pero no se como hacerlo asi que mejor enviame un mensaje a mi cuenta y |
| ||||
Re: Llamada de Apis de Windows Cita: Hola,
Iniciado por boluart ![]() Hola, Del tema se dice mucho, si estas trabajando con WinXP te recomiendo que busques informacion sobre Crear escritorios (CreateDesktop()), ahorita tengo un programa que hace mas o menos lo que quires, escribeme a [email protected] y te paso el proyecto completo (VB6.0 y VB.NET 2003) y es muy probable que funcione para VB.NET 2005 te lo adjuntaria aqui pero no se como hacerlo asi que mejor enviame un mensaje a mi cuenta y No me parece correcta tu forma de ayudar por e-mail porque seguro que más de 1 usuario estarían interesados de tu solución. Saludos ![]() |
| ||||
Re: Llamada de Apis de Windows Podrías crear un .rar o .zip y subirlo a algun hosting de archivos como www.megaupload.com tambien esta rapidshare, y muchos más. Siempre hay que tener en cuenta que un foro no es algo para 2 (cosa que si ocurre con el mail) Salu2! |
| |||
Re: Llamada de Apis de Windows Ante todo disculpas por mi corta respuesta, es que me encontraba de vacaciones asi que en esos momentos no contaba con el código a la mano. Les cuento que esta idea se inicio cuando navegando me encontré con la siuiente con este artículo codeproject.com/win32/AntonioWinLock.asp , pero el problema que tenia era que el código estba en VC6.0 aunque si mal no recuerdo tambien hay una replica del mismo en VC.NET, pero yo queria el codigoen VB.NET porque el ejemplo que baje de ahi llamaba a una DLL (era aqui donde estaba lo importante "CreateDesktop") , asi que trate de interpretarlo y segui buscando hasta que me encontré con este otro artículo vbaccelerator.com/home/vb/code/Libraries/Windows/Creating_New_Desktops/article.asp, bueno el código que aquí expongo originalmente salio de esta ultima dirección. 'Código para VB.NET 2003 'En una Clase Option Explicit On Imports System.Runtime.InteropServices Imports System.Security.Permissions Imports System.Reflection Public Class Class1 <StructLayout(LayoutKind.Sequential)> _ Public Structure PROCESS_INFORMATION Public hProcess As IntPtr Public hThread As IntPtr Public dwProcessID As Integer Public dwThreadID As Integer End Structure 'PROCESS_INFORMATION <StructLayout(LayoutKind.Sequential)> _ Public Structure STARTUPINFO Public cb As Integer Public lpReserved As String Public lpDesktop As String Public lpTitle As String Public dwX As Integer Public dwY As Integer Public dwXSize As Integer Public dwYSize As Integer Public dwXCountChars As Integer Public dwYCountChars As Integer Public dwFillAttribute As Integer Public dwFlags As Integer Public wShowWindow As Short Public cbReserved2 As Short Public lpReserved2 As IntPtr Public hStdInput As IntPtr Public hStdOutput As IntPtr Public hStdError As IntPtr End Structure 'STARTINFO <DllImport("Kernel32.DLL", SetLastError:=True)> _ Public Shared Function CreateProcess(ByVal lpApplicationName As String, ByVal lpCommandLine As String, ByVal lpProcessAttributes As IntPtr, ByVal lpThreadAttributes As IntPtr, ByVal bInheritHandles As Boolean, ByVal dwCreationFlags As Integer, ByVal lpEnvironment As IntPtr, ByVal lpCurrentDriectory As String, ByRef lpStartupInfo As STARTUPINFO, ByRef lpProcessInformation As PROCESS_INFORMATION) As Long End Function <DllImport("kernel32.DLL", SetLastError:=True)> _ Public Shared Function CloseHandle(ByVal hObject As IntPtr) As Long End Function <DllImport("user32.DLL", SetLastError:=True)> _ Public Shared Function GetThreadDesktop(ByVal dwThread As Integer) As Integer End Function <DllImport("kernel32.DLL", SetLastError:=True)> _ Public Shared Function GetCurrentThreadId() As Integer End Function <DllImport("user32.DLL", SetLastError:=True)> _ Public Shared Function OpenInputDesktop(ByVal dwFlags As Integer, ByVal fInherit As Boolean, ByVal dwDesiredAccess As Integer) As Integer End Function <DllImport("Kernel32.DLL", SetLastError:=True)> _ Public Shared Function WaitForSingleObject(ByVal hHandle As IntPtr, ByVal dwMilliseconds As Long) As Long End Function <DllImport("user32.DLL", SetLastError:=True)> _ Public Shared Function CreateDesktop(ByVal lpszDesktop As String, ByVal lpszDevice As Integer, ByVal pDevmode As Integer, ByVal dwFlags As Integer, ByVal dwDesiredAccess As Integer, ByVal lpsa As Integer) As Integer End Function <DllImport("User32.DLL", SetLastError:=True)> _ Public Shared Function SetThreadDesktop(ByVal hDesktop As Integer) As Integer End Function <DllImport("User32.DLL", SetLastError:=True)> _ Public Shared Function SwitchDesktop(ByVal hDesktop As Integer) As Integer End Function <DllImport("User32.DLL", SetLastError:=True)> _ Public Shared Function CloseDesktop(ByVal hDesktop As Integer) As Integer End Function Private Const GENERIC_ALL = &H10000000 Private Const DESKTOP_SWITCHDESKTOP = &H100& Private Const STILL_ACTIVE = &H103 Private Const INFINITE As Long = &HFFFFFFFF ' Infinite timeout Private m_sDesktop As String Private m_hDesktopThreadOld As Integer Private m_hDesktopInputOld As Long Private m_hDesktop As Long Public Sub Create(ByVal sDesktopName As String) Dim lR As Long 'MsgBox(GetCurrentThreadId()) m_hDesktopThreadOld = GetThreadDesktop(GetCurrentThreadId()) m_hDesktopInputOld = OpenInputDesktop(0, False, DESKTOP_SWITCHDESKTOP) m_hDesktop = CreateDesktop(sDesktopName, 0, 0, 0, GENERIC_ALL, 0) If Not (m_hDesktop = 0) Then lR = SetThreadDesktop(m_hDesktop) lR = SwitchDesktop(m_hDesktop) m_sDesktop = sDesktopName End If End Sub Public Sub StartProcess(ByVal sPath As String) Dim tSi As New STARTUPINFO Dim tPi As New PROCESS_INFORMATION Dim lR As Long tSi.cb = Marshal.SizeOf(tSi) tSi.lpTitle = m_sDesktop tSi.lpDesktop = m_sDesktop lR = CreateProcess(sPath, vbNullString, IntPtr.Zero, IntPtr.Zero, True, 0, IntPtr.Zero, vbNullString, tSi, tPi) If (lR = 0) Then ClearUp() Else Dim ret As Long ret = WaitForSingleObject(tPi.hProcess, -1) CloseHandle(tPi.hProcess) CloseHandle(tPi.hThread) End If End Sub Public Sub ClearUp() If Not (m_hDesktopInputOld = 0) Then SwitchDesktop(m_hDesktopInputOld) m_hDesktopInputOld = 0 End If If Not (m_hDesktopThreadOld = 0) Then SetThreadDesktop(m_hDesktopThreadOld) m_hDesktopThreadOld = 0 End If If Not (m_hDesktop = 0) Then CloseDesktop(m_hDesktop) m_hDesktop = 0 End If End Sub Protected Overrides Sub Finalize() MyBase.Finalize() ClearUp() End Sub End Class '********************************** 'En un Formulario Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim cNewDesktop As New Class1 Dim sPath As String = "C:\Windows\System32\notepad.exe" cNewDesktop.Create("Boluart") cNewDesktop.StartProcess(sPath) Close() End Sub Bien aunque al pregunta inicial fue de como hacerlo en VB.NET 2005 Aun no lo probé con VB.NET 2005 lo que pasa es que al volver encontre la PC llena de virus asi que reisntale todo y aun me falta el VS2005, dentro de los proximos dias adaptaré el codigo a VB.NET2005. Bien para los que quieran bajarse el proyecto completo: (VB6.0) www.es.geocities.com/boluart/VB6_New_Desktop_Sample.zip (VB.NET2003 )http://www.es.geocities.com/boluart/...top_Sample.zip Última edición por boluart; 27/03/2007 a las 17:03 |