viernes, 5 de marzo de 2010

Problemas al depurar en IE8 con VS2005

Hola,
Este dato lo encontre en un Blog, que al parecer es muy importante, algunas veces tenemos problemas al iniciar nuestra proyecto WEB en modo de depuración.

En caso esten usando IE8 lo que tienen que realizar es lo siguiente.
Ingresar al REGEDIT

A la ruta que muestra la imagen y agregar un DWORD con valor "0" y listo. ya lo probe y funciono.


Fuente:
http://blogs.renacimiento.com/aarias/archive/2009/06/18/%5Bie8vs2005%5Dproblemas-al-depurar-en-ie8-con-vs2005.aspx

miércoles, 3 de marzo de 2010

VB.NET RUNAS

Hola,
Seguramente muchos nos hemos visto en la necesidad de crear una aplicación la cual ejecute otras aplicaciones con un usuario diferente. Sin la necesidad de tener privilegios de administración en PC.

Bueno acá esta el código como se realiza en VB.NET.
1.-Un form con los siguiente objetos:
  • Textbox1 = Para el dato del usuario.
  • Textbox2 = Para el dato del dominio.
  • Textbox3 = Para el dato la aplicación que queremos ejecutar.
  • Button = Para el generar el evento
2.- archivo runas.vb

Código del Button :

Imports System.Environment

Imports System.Diagnostics
Imports System.Runtime.InteropServices

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try

Dim proc As System.Diagnostics.Process = VastAbyss.RunAs.StartProcess(TextBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text)

Catch w32e As System.ComponentModel.Win32Exception

End Try

End Sub
Código archivo runas.vb
Imports System

Imports System.Text
Imports System.Runtime.InteropServices
Imports System.Security.Principal
Imports System.Security.Permissions
Imports Consola_parametros.VastAbyss

Namespace VastAbyss
_

Public Class RunAs
_

Private Shared Function CreateProcessWithLogonW(ByVal lpszUsername As [String], ByVal lpszDomain As [String], ByVal lpszPassword As [String], ByVal dwLogonFlags As Integer, ByVal applicationName As String, ByVal commandLine As StringBuilder, _

ByVal creationFlags As UInteger, ByVal environment As IntPtr, ByVal currentDirectory As String, ByRef sui As StartUpInfo, ByRef processInfo As ProcessInformation) As Boolean

End Function

_

Private Shared Function CloseHandle(ByVal handle As IntPtr) As Boolean

End Function

_

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

_

Public Structure ProcessInformation

Public hProcess As IntPtr

Public hThread As IntPtr

Public dwProcessId As Integer

Public dwThreadId As Integer

End Structure

_

Public Enum FillAttributes

BackgroundIntensity = 128

BackgroundRed = 64

BackgroundGreen = 32

BackgroundBlue = 16

ForegroundIntensity = 8

ForegroundRed = 4

ForegroundGreen = 2

ForegroundBlue = 1

End Enum

_

Public Enum LogonFlags

WithProfile = 1

NetworkCredentialsOnly = 2

End Enum

_

Public Enum CreationFlags

Suspended = &H4

NewConsole = &H10

NewProcessGroup = &H200

SeperateWOWVDM = &H800

UnicodeEnvironment = &H400

DefaultErrorMode = &H4000000

End Enum

_

Public Enum PriorityFlags

NormalPriority = &H20

IdlePriority = &H40

HighPriority = &H80

RealTimePriority = &H100

BelowNormalPriority = &H4000

AboveNormalPriority = &H8000

End Enum

_

Public Enum StartUpInfoFlags As UInteger

UseShowWindow = &H1

UseSize = &H2

UsePosition = &H4

UseCountChars = &H8

UseFillAttribute = &H10

RunFullScreen = &H20

ForceOnFeedback = &H40

ForceOffFeedback = &H80

UseStandardHandles = &H100

UseHotKey = &H200

UseMonitor = &H400

UseIcon = &H400

TitleShortcut = &H800

Screensaver = &H8000000

End Enum

'=====>>>>> carlos onocuica

Public Shared Function StartProcess(ByVal userName As String, ByVal domain As String, ByVal password As String, ByVal logonFlags As LogonFlags, ByVal applicationName As String, ByVal commandLine As String, _

ByVal creationFlags As CreationFlags, ByVal environment As IntPtr, ByVal currentDirectory As String, ByRef startupInfo As StartUpInfo, ByRef processInfo As ProcessInformation) As System.Diagnostics.Process

Dim cl As New StringBuilder(commandLine.Length)

cl.Append(commandLine)

Dim retval As Boolean = CreateProcessWithLogonW(userName, domain, password, CInt(logonFlags), applicationName, cl, _

CUInt(creationFlags), environment, currentDirectory, startupInfo, processInfo)

If Not retval Then

Throw New System.ComponentModel.Win32Exception()

Else

CloseHandle(processInfo.hProcess)

CloseHandle(processInfo.hThread)

Return System.Diagnostics.Process.GetProcessById(processInfo.dwProcessId)

End If

End Function

Public Shared Function StartProcess(ByVal userName As String, ByVal domain As String, ByVal password As String, ByVal commandLine As String) As System.Diagnostics.Process

Dim processInfo As ProcessInformation

Dim startupInfo As New StartUpInfo()

startupInfo.cb = Marshal.SizeOf(startupInfo)

startupInfo.lpTitle = Nothing

startupInfo.dwFlags = CInt(StartUpInfoFlags.UseCountChars)

startupInfo.dwYCountChars = 50

Return StartProcess(userName, domain, password, LogonFlags.WithProfile, Nothing, commandLine, _

CreationFlags.NewConsole, IntPtr.Zero, Nothing, startupInfo, processInfo)

End Function

Private _userName As String

Public Property UserName() As String

Get

Return _userName

End Get

Set(ByVal value As String)

_userName = value

End Set

End Property

Private _domain As String

Public Property Domain() As String

Get

Return _domain

End Get

Set(ByVal value As String)

_domain = value

End Set

End Property

Private _password As String

Public Property Password() As String

Get

Return _password

End Get

Set(ByVal value As String)

_password = value

End Set

End Property

Private _logonFlags As LogonFlags

Public Property LogonFlagsInstance() As LogonFlags

Get

Return _logonFlags

End Get

Set(ByVal value As LogonFlags)

_logonFlags = value

End Set

End Property

Private _applicationName As String

Public Property ApplicationName() As String

Get

Return _applicationName

End Get

Set(ByVal value As String)

_applicationName = value

End Set

End Property

Private _commandLine As String

Public Property CommandLine() As String

Get

Return _commandLine

End Get

Set(ByVal value As String)

_commandLine = value

End Set

End Property

Private _creationFlags As CreationFlags

Public Property CreationFlagsInstance() As CreationFlags

Get

Return _creationFlags

End Get

Set(ByVal value As CreationFlags)

_creationFlags = value

End Set

End Property

Private _currentDirectory As String

Public Property CurrentDirectory() As String

Get

Return _currentDirectory

End Get

Set(ByVal value As String)

_currentDirectory = value

End Set

End Property

Private _startupInfo As StartUpInfo

Private _processInfo As ProcessInformation

Public Property ProcessInfo() As ProcessInformation

Get

Return _processInfo

End Get

Set(ByVal value As ProcessInformation)

_processInfo = value

End Set

End Property

Private _environment As IntPtr

Public Property Environment() As IntPtr

Get

Return _environment

End Get

Set(ByVal value As IntPtr)

_environment = value

End Set

End Property

Public Sub New()

_userName = System.Environment.UserName

_domain = System.Environment.UserDomainName

_password = ""

_logonFlags = LogonFlags.WithProfile

_commandLine = System.Environment.CommandLine

_creationFlags = CreationFlags.NewConsole

_currentDirectory = System.Environment.CurrentDirectory

_startupInfo = New StartUpInfo()

_startupInfo.cb = Marshal.SizeOf(_startupInfo)

_startupInfo.dwFlags = CInt(StartUpInfoFlags.UseCountChars)

_startupInfo.dwYCountChars = 50

Using cp As System.Diagnostics.Process = System.Diagnostics.Process.GetCurrentProcess()

_applicationName = cp.StartInfo.FileName

_startupInfo.lpTitle = cp.MainWindowTitle

End Using

_processInfo = New ProcessInformation()

_environment = IntPtr.Zero

End Sub

Public Function StartProcess() As System.Diagnostics.Process

Return StartProcess(UserName, Domain, Password, LogonFlagsInstance, ApplicationName, CommandLine, _

CreationFlagsInstance, Environment, CurrentDirectory, _startupInfo, _processInfo)

End Function

End Class

End Namespace
  
En caso necesiten capturar su dominio por defaul ya saben:

TextBox1.Text = UserName


TextBox2.Text = UserDomainName

Saludos,
Carlos Onocuica

domingo, 3 de enero de 2010

Creación de Controles Dinamicos masivos con eventos propios


Hola creo que mucha gente ha tenido este tipo de problemas al momento de generar objetos dinámicos deacuerdo a la cantidad de ítem de una consulta efectuada, en este ejemplo solo se hace una consulta a la cantidad de archivos en un directorio, también se puede usar una consulta a una BD espero les sirva.

Imports System.IO
Imports System.Collections
Class Form1
Public
Dim ruta As String = "C:\donde_buscar\"
Dim cuen As Integer
Dim x As Integer = 90
Dim y As Integer = 120
Dim arreglo_top As New ArrayList
Dim arreglo_top_tex As New ArrayList
Dim l As New ArrayList
Dim obj_check() As CheckBox, i As Int16
Dim obj_picture() As PictureBox, j As Int16
Dim obj_combox() As ComboBox, k As Int16
Dim obj_textbox() As TextBox, m As Int16
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ob()
End Sub
Public Function cuenta() As Integer ' cuenta las imagenes en un directorio
ProgressBar1.Minimum = 0
ProgressBar1.Maximum = Directory.GetFiles(ruta, "*.tif", SearchOption.TopDirectoryOnly).Length
ProgressBar1.Value = 0
For Each num As String In Directory.GetFiles(ruta, "*.tif", SearchOption.TopDirectoryOnly)
l.Add(num) 'carga los nombres de los archivos al array
cuen += 1
arreglo_top.Add(x)
x = x + 110 'posicion de altura de combox
arreglo_top_tex.Add(y)
y = y + 110 'posicion de altura de textbox
Next
End Function
Private Function ob() As Object 'funcion para crear los objetos
cuenta() ' inicia la funcion de conteo de archivos
For i = 0 To cuen 'cuen es la cantidad de archivos este dato nos sirve para generar la misma cantidad de objetos.
If i <>Then
'crea el checkbox
ReDim Preserve obj_check(i) ' este procedimiento hace que mantenga el numero de objeto
obj_check(i) = New CheckBox
obj_check(i).Left = 20
obj_check(i).Top = arreglo_top.Item(i) 'jala la posicion de altura para el objeto = alineacion
obj_check(i).Size = New Size(20, 20)
obj_check(i).Text = l.Item(i)
AddHandler obj_check(i).Click, AddressOf lclick
Me.Controls.Add(obj_check(i))
'crea el picturebox
ReDim Preserve obj_picture(i) ' este procedimiento hace que mantenga el numero de objeto
obj_picture(i) = New PictureBox
obj_picture(i).Left = 50
obj_picture(i).Top = arreglo_top.Item(i) 'jala la posicion de altura para el objeto = alineacion
obj_picture(i).ImageLocation = l.Item(i) 'asigna la imagen al picture
obj_picture(i).Size = New Size(100, 100)
obj_picture(i).SizeMode = PictureBoxSizeMode.StretchImage
AddHandler obj_picture(i).Click, AddressOf jclick
Me.Controls.Add(obj_picture(i))
'crea el combox tambien se le puede agregar una consulta a una bd
ReDim Preserve obj_combox(i) ' este procedimiento hace que mantenga el numero de objeto
obj_combox(i) = New ComboBox
obj_combox(i).Left = 170
obj_combox(i).Top = arreglo_top.Item(i) 'jala la posicion de altura para el objeto = alineacion
obj_combox(i).Size = New Size(100, 100)
Me.Controls.Add(obj_combox(i))
'crea el textbox
ReDim Preserve obj_textbox(i) ' este procedimiento hace que mantenga el numero de objeto
obj_textbox(i) = New TextBox
obj_textbox(i).Left = 170
obj_textbox(i).Top = arreglo_top_tex(i) 'jala la posicion de altura
obj_textbox(i).Size = New Size(100, 20)
Me.Controls.Add(obj_textbox(i))
Else
Exit For
End If
ProgressBar1.Value = ProgressBar1.Value + 1 'mueve la barra de progreso
Next
End Function
Private Sub lclick(ByVal sender As Object, ByVal e As EventArgs) '' [b]handles Button1.click, button2.click[/b]
Dim l As CheckBox = CType(sender, CheckBox)
MessageBox.Show(l.Text) 'muestra el nombre de la imagen para prueba
End Sub
Private Sub jclick(ByVal sender As Object, ByVal e As EventArgs) '' [b]handles Button1.click, button2.click[/b]
Dim l As PictureBox = CType(sender, PictureBox)
Process.Start(l.ImageLocation) 'abre la imagen con el visor de windows
End Sub Class
End