Discussion:
Disable or enable a command button at runtime based on logged on user?
(too old to reply)
Hii Sing Chung
2008-10-14 10:40:17 UTC
Permalink
Hi,

Does anyone know if VFP 9 can do this: Disable or enable a button during
runtime based on the logged on AD user account (best if can based on the
user group). For example I have a program that has a centralized form
containing buttons that call other subprograms, I would to enable the
buttons 'PO entry' when the current user belongs to the AD group of
'procurement' and disable the 'PO confirmation' button, whereas if the
current user belongs to the AD group of 'finance', disable the 'PO entry'
button but enable the 'PO confirmation' button. Can it be done?

Sing Chung
Jan Bucek
2008-10-14 14:20:10 UTC
Permalink
Post by Hii Sing Chung
Hi,
Does anyone know if VFP 9 can do this: Disable or enable a button during
runtime based on the logged on AD user account (best if can based on the
user group). For example I have a program that has a centralized form
containing buttons that call other subprograms, I would to enable the
buttons 'PO entry' when the current user belongs to the AD group of
'procurement' and disable the 'PO confirmation' button, whereas if the
current user belongs to the AD group of 'finance', disable the 'PO
entry' button but enable the 'PO confirmation' button. Can it be done?
Sing Chung
Properties "enabled" or "visible" (both of type "logical") are
available, you have to set them after user is logged in.
Hii Sing Chung
2008-10-17 05:55:39 UTC
Permalink
Jan,

Do you mean I have to set enable or disable for a particular form everytime
after a particular user is logged on? What I need is the program to
automatically disable or enable controls or forms based on the the logging
user groups. This is because I don't want every user has access to every
part of the program, the program itself must identify who the current user
is now and give accesses accordingly.
Post by Hii Sing Chung
Hi,
Does anyone know if VFP 9 can do this: Disable or enable a button during
runtime based on the logged on AD user account (best if can based on the
user group). For example I have a program that has a centralized form
containing buttons that call other subprograms, I would to enable the
buttons 'PO entry' when the current user belongs to the AD group of
'procurement' and disable the 'PO confirmation' button, whereas if the
current user belongs to the AD group of 'finance', disable the 'PO entry'
button but enable the 'PO confirmation' button. Can it be done?
Sing Chung
Properties "enabled" or "visible" (both of type "logical") are available,
you have to set them after user is logged in.
Jan Bucek
2008-10-17 07:42:46 UTC
Permalink
Post by Hii Sing Chung
Jan,
Do you mean I have to set enable or disable for a particular form
everytime after a particular user is logged on?
Yes, I do.




What I need is the
Post by Hii Sing Chung
program to automatically disable or enable controls or forms based on
the the logging user groups. This is because I don't want every user has
access to every part of the program, the program itself must identify
who the current user is now and give accesses accordingly.
Post by Jan Bucek
Post by Hii Sing Chung
Hi,
Does anyone know if VFP 9 can do this: Disable or enable a button
during runtime based on the logged on AD user account (best if can
based on the user group). For example I have a program that has a
centralized form containing buttons that call other subprograms, I
would to enable the buttons 'PO entry' when the current user belongs
to the AD group of 'procurement' and disable the 'PO confirmation'
button, whereas if the current user belongs to the AD group of
'finance', disable the 'PO entry' button but enable the 'PO
confirmation' button. Can it be done?
Sing Chung
Properties "enabled" or "visible" (both of type "logical") are
available, you have to set them after user is logged in.
--
Jan Bucek
17. listopadu 2657
544 01 Dvu*r Králové n. L.
www.bucek.info
Mark
2008-10-17 14:08:00 UTC
Permalink
Hi,
You might want to create a table with UserName, UserPassword and
UserAccessLevel e.g. 0 - 9.
When logging in the UserAccessLevel is saved into a variable accessible
through the application e.g. oApplication.nUserAccessLevel = 4
Depending on the UserAccessLevel you can then enable or disable your control
e.a. in the Control.Refresh()

Control.Refresh()

Local nUserAccessLevel

nUserAccessLevel = oApplication.nUserAccessLevel

If nUserAccessLevel > 4
This.Enabled= .F.
Else
This.Enabled = .T.
EndIf

This is preferably done at class level.

hth

Mark
Post by Hii Sing Chung
Jan,
Do you mean I have to set enable or disable for a particular form everytime
after a particular user is logged on? What I need is the program to
automatically disable or enable controls or forms based on the the logging
user groups. This is because I don't want every user has access to every
part of the program, the program itself must identify who the current user
is now and give accesses accordingly.
Post by Hii Sing Chung
Hi,
Does anyone know if VFP 9 can do this: Disable or enable a button during
runtime based on the logged on AD user account (best if can based on the
user group). For example I have a program that has a centralized form
containing buttons that call other subprograms, I would to enable the
buttons 'PO entry' when the current user belongs to the AD group of
'procurement' and disable the 'PO confirmation' button, whereas if the
current user belongs to the AD group of 'finance', disable the 'PO entry'
button but enable the 'PO confirmation' button. Can it be done?
Sing Chung
Properties "enabled" or "visible" (both of type "logical") are available,
you have to set them after user is logged in.
Hii Sing Chung
2008-10-19 06:29:55 UTC
Permalink
Mark,

Thanks for the suggestions. When you said create a table with UserName,
UserPassword and UserAccessLevel, does this username refers to the username
of the user in Active Directory. Specifically I want know if Visual FoxPro
is able to come out with something that can detect logged on Active
Directory user or group and gives access accordingly during runtime, without
the need to keep another user table. Can this be done?
Post by Mark
Hi,
You might want to create a table with UserName, UserPassword and
UserAccessLevel e.g. 0 - 9.
When logging in the UserAccessLevel is saved into a variable accessible
through the application e.g. oApplication.nUserAccessLevel = 4
Depending on the UserAccessLevel you can then enable or disable your control
e.a. in the Control.Refresh()
Control.Refresh()
Local nUserAccessLevel
nUserAccessLevel = oApplication.nUserAccessLevel
If nUserAccessLevel > 4
This.Enabled= .F.
Else
This.Enabled = .T.
EndIf
This is preferably done at class level.
hth
Mark
Post by Hii Sing Chung
Jan,
Do you mean I have to set enable or disable for a particular form everytime
after a particular user is logged on? What I need is the program to
automatically disable or enable controls or forms based on the the logging
user groups. This is because I don't want every user has access to every
part of the program, the program itself must identify who the current user
is now and give accesses accordingly.
Post by Hii Sing Chung
Hi,
Does anyone know if VFP 9 can do this: Disable or enable a button during
runtime based on the logged on AD user account (best if can based on the
user group). For example I have a program that has a centralized form
containing buttons that call other subprograms, I would to enable the
buttons 'PO entry' when the current user belongs to the AD group of
'procurement' and disable the 'PO confirmation' button, whereas if the
current user belongs to the AD group of 'finance', disable the 'PO entry'
button but enable the 'PO confirmation' button. Can it be done?
Sing Chung
Properties "enabled" or "visible" (both of type "logical") are available,
you have to set them after user is logged in.
Olaf Doschke
2008-10-22 21:16:39 UTC
Permalink
Hi,

Sys(0)
Getenv('Username')
Getenv('Userdomain')

If you want to check, if a user belongs
to a certain usergroup, the simplest may
be to try to fopen() a file that only users
of that usergoup can access. If that fails,
eg you don't get a valid file handle, the
user lacks that access right.

This in the init of a control class will check that
and Enable/Disable the control correspondingly:

Local lnHandle
lnHandle = FOpen(This.cTestfile)
If lnHandle>0
FClose(lnHandle)
This.Enabled = .T.
Else
This.Enabled = .F.
EndIf

Add a cTestfile property to the control class class.
Change the property value to some path/filename
of a file, only users, which should have access
to that control, can access.

Once you've done that for a commandbutton,
you can create several other buttons based on
this and simply change the cTestfile property.

To really query AD this might help:
http://www.foxite.com/archives/vfp-authentication-on-active-directory-0000137240.htm

Bye, Olaf.

swdev2
2008-10-21 06:07:41 UTC
Permalink
VFP can do things with AD.
You'll have to write code to do it.

Nothing is 'automatic' - you have to write code.
Good Luck !

--
===================
William Sanders / EFG VFP / mySql / MS-SQL
www.efgroup.net/vfpwebhosting
www.terrafox.net www.viasqlserver.net
Post by Hii Sing Chung
Hi,
Does anyone know if VFP 9 can do this: Disable or enable a button during
runtime based on the logged on AD user account (best if can based on the
user group). For example I have a program that has a centralized form
containing buttons that call other subprograms, I would to enable the
buttons 'PO entry' when the current user belongs to the AD group of
'procurement' and disable the 'PO confirmation' button, whereas if the
current user belongs to the AD group of 'finance', disable the 'PO entry'
button but enable the 'PO confirmation' button. Can it be done?
Sing Chung
Hii Sing Chung
2008-10-22 13:14:20 UTC
Permalink
Sorrry, Foxpro is a stranger to me. Is there anywhere I can see a sample of
codes about how it query AD and set properties according?
Thight English will be like this:
Case user is member of AD group Finance
disable poentry.scx
disable poquery.scx
case user is member of AD group admin
disable poquery.scx
enable poentry.scx
end case
Post by swdev2
VFP can do things with AD.
You'll have to write code to do it.
Nothing is 'automatic' - you have to write code.
Good Luck !
--
===================
William Sanders / EFG VFP / mySql / MS-SQL
www.efgroup.net/vfpwebhosting
www.terrafox.net www.viasqlserver.net
Post by Hii Sing Chung
Hi,
Does anyone know if VFP 9 can do this: Disable or enable a button during
runtime based on the logged on AD user account (best if can based on the
user group). For example I have a program that has a centralized form
containing buttons that call other subprograms, I would to enable the
buttons 'PO entry' when the current user belongs to the AD group of
'procurement' and disable the 'PO confirmation' button, whereas if the
current user belongs to the AD group of 'finance', disable the 'PO entry'
button but enable the 'PO confirmation' button. Can it be done?
Sing Chung
Continue reading on narkive:
Loading...