Accessing windows userid

luciliacoelho
luciliacoelho used Ask the Experts™
on
I would like to improve my applications security binding the windows user name (windows server or windows workstation) to a user name registered within a table in my applications.
Is there any function that allows me to access the user name of the windows workstation or the user name of a windows domain?
I would like to prevent that a user logged on on a windows system could log on to my application if he's not logged on with his own user name.
If you see any other way to validate this, suggestion are welcome.
Kind regards
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Kalpesh ChhatralaSoftware Consultant

Commented:
cUserName = GETENV("USERNAME") // Get Windows User Name
Kalpesh ChhatralaSoftware Consultant

Commented:
If you are using Terminal Service then you can also use

GETENV("CLIENTNAME") // Client Computer Name
Commented:
I use the following:

* --- Get Windows Username + Workstation Name ---
cUserName = SYS(0)
* --- Parse down to just Windows Username ---
cUserName = ALLTRIM(SUBSTR(cUserName, AT("#",cUserName) + 1))

Good Luck

Olaf DoschkeSoftware Developer

Commented:
just by the way: ID() is the same as SYS(0) and shorter :)

GetEnv("CLIENTNAME") isn't set fo me, kalpesh, but GetEnv("Computername") is.

Actually GetEnv() is returning the DOS environment variables and depends on what is set, intellisense shows all environment variables, which are set, but that can vary from computer to computer. ID() (or SYS(0)) will always work, though

WMI offers much more options to get system and user profile infos:

oWMI = Getobject("winmgmts:\root\cimv2")
oQuery = oWMI.ExecQuery("select * from Win32_ComputerSystem")
For Each loProp In  oQuery.ItemIndex(0).Properties_
   Try
      ? loProp.Name, Evaluate("oQuery.ItemIndex(0)."+loProp.Name)
   Catch
      *
   Endtry
Endfor

oQuery = oWMI.ExecQuery("select * from Win32_UserAccount")
For nCount = 0 To oQuery.Count-1
   For Each loProp In  oQuery.ItemIndex(nCount).Properties_
      Try
         ? loProp.Name, Evaluate("oQuery.ItemIndex(nCount)."+loProp.Name)
      Catch
         *
      Endtry
   Endfor
Endfor nCount

Open in new window


Especially interesting are Win32_Computersystem.Name and .Username.
A reference on all the win32 classes is here: http://msdn.microsoft.com/en-us/library/aa394084(v=VS.85).aspx

Bye, Olaf.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial