FoxPro/Visual FoxPro - usuario windows

 
Vista:

usuario windows

Publicado por extremo (78 intervenciones) el 17/08/2006 23:27:45
Hola amigos foxeros

Tengo un pequeño problemilla, necesito saber como dientres hago para saber quien es el usuario que ingreso en windows. especificamente win XP, me refiero al usuario del windows XP ejemplo minombre, administrador,invitado ,etc.

De antermano
Muchas gracias
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
sin imagen de perfil

RE:usuario windows

Publicado por Ernesto Hernandez (4623 intervenciones) el 18/08/2006 00:51:47
Prueba esto
espero te sirva


*-- Code begins here.
PUBLIC oform1
ON ERROR DO errorhnd
oform1=NEWOBJECT("form1")
oform1.Show
RETURN

PROCEDURE errorhnd

DO CASE
CASE ERROR() = 1426
*-- We have an OLE error code.
*-- Insert code to handle it as needed.
OTHERWISE
*-- We have an error not related to ADSI.
*-- Error handling would normally be placed here.
=MESSAGEBOX(STR(ERROR()) +": " + MESSAGE(), 0, "Error")
ENDCASE

ENDPROC

DEFINE CLASS form1 AS form

Height = 253
Width = 457
DoCreate = .T.
AutoCenter = .T.
Caption = "Form1"
Name = "form1"

ADD OBJECT text1 AS textbox WITH ;
Value = "WinNT://MyServer", ;
Height = 23, ;
Left = 12, ;
Top = 206, ;
Width = 238, ;
Name = "Text1"

ADD OBJECT label1 AS label WITH ;
Caption = "ADS Path to Server:", ;
Height = 25, ;
Left = 12, ;
Top = 181, ;
Width = 202, ;
Name = "Label1"

ADD OBJECT cmdfind AS commandbutton WITH ;
Top = 192, ;
Left = 283, ;
Height = 37, ;
Width = 97, ;
Caption = "\<Find", ;
Name = "cmdFind"

ADD OBJECT list1 AS listbox WITH ;
Height = 152, ;
Left = 24, ;
Top = 12, ;
Width = 156, ;
Name = "List1"

ADD OBJECT lblfullname AS label WITH ;
Caption = "", ;
Height = 17, ;
Left = 204, ;
Top = 27, ;
Width = 248, ;
Name = "lblFullName"

ADD OBJECT label2 AS label WITH ;
Caption = "Last Login:", ;
Height = 17, ;
Left = 203, ;
Top = 60, ;
Width = 72, ;
Name = "Label2"

ADD OBJECT lbllastlogin AS label WITH ;
Caption = "", ;
Height = 17, ;
Left = 314, ;
Top = 60, ;
Width = 132, ;
Name = "lblLastLogin"

ADD OBJECT label3 AS label WITH ;
Caption = "Last Logoff:", ;
Height = 17, ;
Left = 203, ;
Top = 83, ;
Width = 73, ;
Name = "Label3"

ADD OBJECT lbllastlogoff AS label WITH ;
Caption = "", ;
Height = 17, ;
Left = 314, ;
Top = 83, ;
Width = 132, ;
Name = "lblLastLogoff"

ADD OBJECT chkdisabled AS checkbox WITH ;
Top = 140, ;
Left = 202, ;
Height = 17, ;
Width = 123, ;
Caption = "Account Disabled", ;
ReadOnly = .T., ;
Name = "chkDisabled"

ADD OBJECT label4 AS label WITH ;
Caption = "Password Expires:", ;
Height = 17, ;
Left = 203, ;
Top = 107, ;
Width = 106, ;
Name = "Label4"

ADD OBJECT lblexpire AS label WITH ;
Caption = "", ;
Height = 17, ;
Left = 314, ;
Top = 107, ;
Width = 68, ;
Name = "lblExpire"

PROCEDURE cmdfind.Click

*-- This could take a while, so update the status bar.
ThisForm.lblFullName.Caption = "Searching..."
ThisForm.List1.Clear

*-- Find the server object.
oADSobj = GETOBJECT(ALLTRIM(ThisForm.Text1.Text))

*-- Populate the list with the users on the server.
*-- We need to filter to get just the users, otherwise
*-- the list will include every object from that server,
*-- such as printers and groups.
FOR EACH Child IN oADSobj
IF Child.Class = "User"
thisform.list1.additem(Child.Name)
ENDIF
ENDFOR
ThisForm.lblFullName.Caption = ""
ENDPROC

PROCEDURE list1.Click
*-- Clear the labels in case we can't get
*-- the values.
ThisForm.lblFullName.Caption = ""
ThisForm.lblLastLogin.Caption = ""
ThisForm.lblLastLogoff.Caption = ""
ThisForm.chkDisabled.Value = 0
ThisForm.lblExpire.Caption = ""

*-- Find the selected item in the list.
FOR nCnt = 1 TO ThisForm.List1.ListCount
IF ThisForm.List1.Selected(nCnt)

*-- Get the user object by building an ADS path
*-- from the server path entered in the text box
*-- and the user name selected from the list.
oUser = GETOBJECT(ALLTRIM(ThisForm.Text1.Text) + ;
"/" + ALLTRIM(ThisForm.List1.Value))

*-- Get the user information and populate the
*-- label controls.
ThisForm.lblFullName.Caption = oUser.FullName
ThisForm.lblLastLogin.Caption = DTOC(oUser.LastLogin)
ThisForm.lblLastLogoff.Caption = DTOC(oUser.LastLogoff)
ThisForm.chkDisabled.Value = oUser.AccountDisabled
ThisForm.lblExpire.Caption = ;
DTOC(oUser.PasswordExpirationDate)
ENDIF
ENDFOR
ENDPROC

PROCEDURE Destroy
ON ERROR
ENDPROC

ENDDEFINE

Suerte
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

RE:usuario windows

Publicado por Plinio (7841 intervenciones) el 18/08/2006 01:11:36
? SUBSTR(ID(),AT("#",ID())+1,30)
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

RE:usuario windows

Publicado por Luisjavier Osorio (12 intervenciones) el 18/08/2006 15:09:08
Hay una forma mucho mas sencilla... prueba lo siguiente.

STORE GETENV("username") TO user

eso es todo.... con eso tienes para obtener el nombre de usuario en cualquier plataforma basada en NT (WinXP, W2k o NT4), en win9x no lo recuerdo, pero creo que tambien funciona..

La funcion GETENV obtiene las llamadas "variables de entorno" del sistema operativo y las retorna al usuario. Esto es muy util si por ejemplo quieres restringir ciertas opciones de un programa a determinados usuarios de tu red local.
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

RE:usuario windows

Publicado por Plinio (7841 intervenciones) el 18/08/2006 15:16:48
Uff, habia usado esta funcion y no sabia este caso. Gracias Luis Javier
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
sin imagen de perfil

RE:usuario windows

Publicado por Ernesto Hernandez (4623 intervenciones) el 18/08/2006 17:12:07
interesante

Pregunta

Regresa el contenido de la variable de entorno especificada de MS-DOS o de todas las variables del sistema operativo ?
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

RE:usuario windows

Publicado por Luisjavier Osorio (12 intervenciones) el 18/08/2006 17:50:49
Las variables de entorno del Sistema Operativo en plataformas NT... En Windows 9x te devuelve las de DOS.

Si mal recuerdo, asi funciona. En un dado caso puedes consultar la ayuda de VFP.
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

RE:usuario windows

Publicado por Luisjavier Osorio (12 intervenciones) el 18/08/2006 17:52:39
Y Se me olvidaba... solo devuelve el valor de la variable de entorno que le especifiques.
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
sin imagen de perfil

RE:usuario windows

Publicado por Ernesto Hernandez (4623 intervenciones) el 18/08/2006 18:02:58
tienes toda la razon compañero ademas de que te permite crear tus propias variables con el command shell SET command
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