Page 1 sur 1

Connaître le login réseau de l'utilisateur

MessagePublié: 02 Nov 2005 à 11:50
par oguruma
En passant par les API's de l'OS

Code : Tout sélectionner
Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" ( Byval lpName As String, Byval lpUserName As String, lpnLength As Long ) As Long

Function GetNetLoginUserName (login As String) As Integer
   Const lpnLength  = 255   
   Dim status As Integer    
   Dim lpName As String, lpUserName As String    
   lpUserName = Space$ (lpnLength + 1 )    
   status = WNetGetUser(lpName, lpUserName, lpnLength)    
   If status = 0 Then       
      lpUserName = Left$ (lpUserName, Instr (lpUserName, Chr (0)) - 1 )       
   Else       
      GetNetLoginUserName=False
      Exit Function
      End       
   End If    
   login = lpUserName    
   GetNetLoginUserName=True
End Function

Sub Initialize
   Dim login As String
'// retour de true ou false
   Msgbox GetNetLoginUserName (login)
'// retour du login réseau
   Msgbox login
End Sub

MessagePublié: 02 Nov 2005 à 14:07
par JYR
Le code est très bon mais encore plus rapide


Dim X
Dim U
Set X = createobject("WSCRIPT.Network")

U=x.UserName
Print U

Si le WSH (Windows scriptong host) est installé.
le WSH peut se trouver ici

http://www.microsoft.com/downloads/deta ... laylang=en

Ceci est normalement activé par défaut sur les postes windowzzzz. POur valider il faut un DLL . Il se trouve habituellement dans WinNt\system32\.

wshom - wshom.ocx - DLL Information
DLL File: wshom or wshom.ocx
DLL Name: Windows Script Host Runtime Library
 
Description:
ActiveX control used to create shortcuts, enumerate network drives, and so forth, by the Windows Scripting Host Object Model.

Ou bedon

Print Environ("UserName")

Il s'Agit d'une variable d'environnment Windows accessible via Environ()

JYR

MessagePublié: 25 Nov 2005 à 18:06
par Cyril Niang
Salut,
JYR peux-tu me dire comment utiliser correctement la DLL wshom.ocx? je n'ai pas trop compris ton explication là dessus.

Merci

MessagePublié: 25 Nov 2005 à 18:53
par JYR
1 - Il faut vérifier que le fichier ocx existe bien dans le répertoire spécifié sinon la commande : Set X = createobject("WSCRIPT.Network")
va échouer.

2- si le fichier n'existe pas, il faut allé chercher le package (WSH (Windows scriptong host)) sur le site de Microsoft qui lui installera le dit fichier ocx.


JYR

EDIT de l'ADMIN Téléchargement Microsoft => http://www.microsoft.com/downloads/resu ... layLang=fr