Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting the client name
Message
De
19/04/2015 05:06:12
 
 
À
19/04/2015 04:56:08
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01618480
Message ID:
01618691
Vues:
43
>>>>Just as an FYI for anyone interested The solution is incredibly simply and does not require accessing any API. You can retrieve the users computer name under a terminal services session simply using Windows Scripting Host in 2 lines ("doh!"):
>>>>
>>>>
>>>>objShell = CreateObject("WScript.Shell")
>>>>strClient = objShell.ExpandEnvironmentStrings("%clientname%")
>>>>? strClient
>>>>
>>>>
>....
>>OK, thanks. We are using this on our own terminal services servers
>>
>>.
>We also run TS sessions, often under an account name used by a small group. Identyfying the machine at the other end of TS is a step nearer to fix some issues brought on by not setting up group policies ;-)
>Have you found an easy way to get the loginname of the person manning the machine running the TS session?
>
>tia
>

Thomas

Yes, we do this but note my NB at bottom:
*    GET THE USER LOGIN NAME

TUSER_LOGIN_NAME = ALLTRIM( SUBSTR( SYS(0), AT( "#", SYS(0) ) + 1 )  )
   
*    CREATE AN OBJECT REFERENCE TO THE USER LOGIN ACCOUNT

TRY

    TOBJ_Windows_User = getobject( "WinNT://" + Getenv("USERDOMAIN") + "/" + m.TUSER_LOGIN_NAME + ",User" )

CATCH

    TOBJ_Windows_User = .F.

ENDTRY
 
*    GET THE USERS FULL NAME AND DESCRIPTION

IF VARTYPE( TOBJ_Windows_User ) = "O"

     TUSER_FULL_NAME    = TOBJ_Windows_User.FullName    
     TUSER_DESCRIPTION = TOBJ_Windows_User.Description

ELSE

     TUSER_FULL_NAME    = "?"    
     TUSER_DESCRIPTION = "?"

ENDIF
NB: The above is relatively slow (a couple of seconds) and so our code tests to see whether the login full name is empty in our file and only attempts the above if empty. In other words, we run this code only once for a user and then not again.

.
In the End, we will remember not the words of our enemies, but the silence of our friends - Martin Luther King, Jr.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform