Visual Basic - algun scrip para deslogear el usuario y muestre el formulario de acceso otra vez

Life is soft - evento anual de software empresarial
 
Vista:

algun scrip para deslogear el usuario y muestre el formulario de acceso otra vez

Publicado por JoseMendozq (1 intervención) el 26/06/2012 06:41:26
Hola..

asi comodice el titulo pues...

les explico tengo un prlograma hecho ya pero quiero agregarle un boton lo log off o cerrar seccion, ya los usuarios pueden entrar y todo... pero no se que usar para que el programa se recicie al apretar ese boton... y vuelva a salir el acceso.. no se si me explique...

en fiin necesito ayuda.. saludos
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Antoni Masana
Val: 1.259
Plata
Ha mantenido su posición en Visual Basic (en relación al último mes)
Gráfica de Visual Basic

algun scrip para deslogear el usuario y muestre el formulario de acceso otra vez

Publicado por Antoni Masana (558 intervenciones) el 26/06/2012 09:35:22
Esto Codigo es para apagar ( EXC_SHUTDOWN ), rebotar ( EXC_REBOOT ) o finalizar el usuario ( LOGOFF) la cuarta es para forzar que se mueran los procesos y se usa conjuntamente con las tres anteriores.

Se llama a reboot({n}) con un parametro del 1 al 3

Se comporta ligeramente diferente si es Win 98 o Win XP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
' </> ----------------------------------------------------------------- </>
' </> ---&--- </>                                           </> ---&--- </>
' </> ---&--- </>   FRONT para Windows - Shutdown           </> ---&--- </>
' </> ---&--- </>                                           </> ---&--- </>
' </> ----------------------------------------------------------------- </>
 
 
Option Explicit
 
' </> ---&--- </>   Shutdown
 
Public Shut_Botar As Byte, _
       Shut_Tipo As Byte, _
       Shut_Hora As String
 
Public Const EXC_SHUTDOWN = 1
Public Const EXC_LOGOFF = 0
Public Const EXC_REBOOT = 2
Public Const EXC_FORCE = 4
 
 
'---------------------------------------------------------------------------
' API declarations to obtain the Windows version and the type of
' keyboard.
'---------------------------------------------------------------------------
 
Private Declare Function apiGetVersion _
        Lib "kernel32" _
        Alias "GetVersionExA" (ByRef lpVersionInformation _
                                       As OSVERSIONINFO) As Long
 
' size of 'Type' = (5 x 4 bytes) =  20 bytes (the 5 Longs)
'                                  128 bytes (fixed-length string)
'                                 ----- +
'                                  148 bytes
 
Private Type OSVERSIONINFO
    dwOSVersionInfoSize As Long      ' Has to be set to size of 'type'= 148
    dwMajorVersion As Long           ' Gives the Major version
    dwMinorVersion As Long           ' Gives the Minor version
    dwBuildNumber As Long            ' Gives the buildnumber (I don't use it)
    dwPlatformId As Long             ' Gives the operating system.
    szCSDVersion As String * 128     ' ?
End Type
 
 
 
'---------------------------------------------------------------------------
' API Declaración para Rebotar Windows 95/98
'---------------------------------------------------------------------------
 
'Declare Function ExitWindowsEx& Lib "user32" (ByVal uFlags&, _
                                              ByVal dwReserved&)
 
'---------------------------------------------------------------------------
' API Declaración para Rebotar Windows NT
'---------------------------------------------------------------------------
 
' Tipos definidos
 
Private Type LUID
    UsedPart As Long
    IgnoredForNowHigh32BitPart As Long
End Type
 
Private Type TOKEN_PRIVILEGES
    PrivilegeCount As Long
    TheLuid As LUID
    Attributes As Long
End Type
 
' Las funciones del API
 
Private Declare Function ExitWindowsEx _
        Lib "user32" (ByVal dwOptions As Long, _
                      ByVal dwReserved As Long) As Long
 
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
 
Private Declare Function OpenProcessToken _
        Lib "advapi32" (ByVal ProcessHandle As Long, _
                        ByVal DesiredAccess As Long, _
                              TokenHandle As Long) As Long
 
Private Declare Function LookupPrivilegeValue _
        Lib "advapi32" _
        Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, _
                                       ByVal lpName As String, _
                                             lpLuid As LUID) As Long
 
Private Declare Function AdjustTokenPrivileges _
        Lib "advapi32" (ByVal TokenHandle As Long, _
                        ByVal DisableAllPrivileges As Long, _
                              NewState As TOKEN_PRIVILEGES, _
                        ByVal BufferLength As Long, _
                              PreviousState As TOKEN_PRIVILEGES, _
                              ReturnLength As Long) As Long
 
'---------------------------------------------------------------------------
' SUB: WinVer
'
' This sub returns information about the operating system, and about
' the Windows Version.
'
' e.g. Windows 3.11
'      The sub will return:
'         - intMajor    = 3
'         - intMinor    = 11
'         - strPlatform = Windows 3.11
'
' OUT:  intMajor        - Integer containing the major version of Windows.
'       intMinor        - Integer containing the minor version of windows.
'
' strPlatfrom returns one of the following :
'   Windows 95
'   Windows NT
'   Windows + Version
'
' If the call fails intMajor = 0, intMinor = 0, and strPlatform = ""
'---------------------------------------------------------------------------
 
Public Sub WinVer(ByRef intMajor As Integer, _
                  ByRef intMinor As Integer, _
                  ByRef strPlatform As String)
 
    Dim OSystem As OSVERSIONINFO
 
    OSystem.dwOSVersionInfoSize = 148
 
    ' The size of the structure must be set before the call.
 
    If apiGetVersion(OSystem) Then
 
       ' Call the API. It fills the OSystem type.
 
       intMajor = OSystem.dwMajorVersion   ' Store the Major version
       intMinor = OSystem.dwMinorVersion   ' Store the Minor version
 
       Select Case OSystem.dwPlatformId    ' Set strPlatform
          Case 0: strPlatform = "W" + CStr(intMajor)
          Case 1: strPlatform = "W95"
          Case 2: strPlatform = "WNT"
       End Select
    Else
       ' The call failed, set the values to zero
       intMajor = 0
       intMinor = 0
       strPlatform = ""
   End If
End Sub
 
' Código para poner en el formulario
 
Private Sub AdjustToken()
    Const TOKEN_ADJUST_PRIVILEGES = &H20
    Const TOKEN_QUERY = &H8
    Const SE_PRIVILEGE_ENABLED = &H2
 
    Dim hdlProcessHandle As Long
    Dim hdlTokenHandle As Long
    Dim tmpLuid As LUID
    Dim tkp As TOKEN_PRIVILEGES
    Dim tkpNewButIgnored As TOKEN_PRIVILEGES
    Dim lBufferNeeded As Long
 
    hdlProcessHandle = GetCurrentProcess()
 
    OpenProcessToken hdlProcessHandle, _
                     (TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY), _
                     hdlTokenHandle
 
    ' Get the LUID for shutdown privilege.
    LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid
 
    tkp.PrivilegeCount = 1    ' One privilege to set
    tkp.TheLuid = tmpLuid
    tkp.Attributes = SE_PRIVILEGE_ENABLED
 
    ' Enable the shutdown privilege in the access token of this
    ' process.
 
    AdjustTokenPrivileges hdlTokenHandle, False, tkp, _
            Len(tkpNewButIgnored), tkpNewButIgnored, lBufferNeeded
 
End Sub
 
Public Sub Reboot(Shut_Tipo)
    Dim Opc As Long, _
        Mayor As Integer, _
        Menor As Integer, _
        Version As String
 
    WinVer Mayor, Menor, Version
 
    If Version = "WNT" Then AdjustToken
 
    Select Case Shut_Tipo
       Case 1:  Opc = ExitWindowsEx(EXC_REBOOT   Or EXC_FORCE, &HFFFF)
       Case 2:  Opc = ExitWindowsEx(EXC_SHUTDOWN Or EXC_FORCE, &HFFFF)
       Case 3:  Opc = ExitWindowsEx(EXC_LOGOFF   Or EXC_FORCE, &HFFFF)
    End Select
End Sub


Recuerda cerrar ficheros y guardar todo lo que sea necesario antes de ejecuar esta opción
Para más informacion busca en Google sobre: ExitWindowsEx
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

algun scrip para deslogear el usuario y muestre el formulario de acceso otra vez

Publicado por Lago GZ (12 intervenciones) el 29/06/2012 15:08:49
Igual lo he entendido mal, pero por ejemplo si tu aplicación es MDI, en un menú llamado Archivo (o lo q tu quieras) creas un item llamado Cerrar Sesión, y en su evento click colocas lo siguiente:

frmLogin.Show 'O como se llame tu formulario de login.
Unload Me

Y ya estaría. Eso sí, como te dijeron en la respuesta anterior, cierra todo lo q tengas abierto.

Esto para VB6.

Un saludo.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar