cs_casy
Messages postés7741Date d'inscriptionmercredi 1 septembre 2004StatutMembreDernière intervention24 septembre 201440 15 févr. 2009 à 09:09
Exemple avec l'api windows :
'### Declaration #####################################
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
'### Utilisation #####################################
'Create a buffer
strUserName = String(100, Chr$(0))
'Get the username
GetUserName strUserName, 100
'strip the rest of the buffer
strUserName = Left$(strUserName, InStr(strUserName, Chr$(0)) - 1)
'Show the temppath and the username
MsgBox "Hello " + strUserName
nonoss56
Messages postés14Date d'inscriptionsamedi 1 mars 2008StatutMembreDernière intervention 1 avril 2012 15 févr. 2009 à 09:34
Merci Casy
Je viens de mettre ces 2 éléments dans un VB excel pour tester. Par contre, il ne me renvoie rien, simplement Hello... J'ai fait un copier coller de ton code pour être sûr d'éviter les fautes d'orthographe...
cs_casy
Messages postés7741Date d'inscriptionmercredi 1 septembre 2004StatutMembreDernière intervention24 septembre 201440 15 févr. 2009 à 10:31
Effectivement ça ne marche pas chez moi non plus.
D'après l'aide, il y aurait la commande Application.UserName, mais chez elle me renvoie le nom de la machine au lieu du nom utilisateur.
Sinon tu peut essayer ce code :
'### Déclarations ###########################
Private Enum EXTENDED_NAME_FORMAT
NameUnknown = 0
NameFullyQualifiedDN = 1
NameSamCompatible = 2
NameDisplay = 3
NameUniqueId = 6
NameCanonical = 7
NameUserPrincipal = 8
NameCanonicalEx = 9
NameServicePrincipal = 10
End Enum
Private Declare Function GetUserNameEx Lib "secur32.dll" Alias "GetUserNameExA" (ByVal NameFormat As EXTENDED_NAME_FORMAT, ByVal lpNameBuffer As String, ByRef nSize As Long) As Long
'### Utilisation ############################
Dim sBuffer As String, Ret As Long
sBuffer = String(256, 0)
Ret = Len(sBuffer)
If GetUserNameEx(NameSamCompatible , sBuffer, Ret) <> 0 Then
MsgBox "Username: " + Left$(sBuffer, Ret)
Else
MsgBox "Error while retrieving the username"
End If
pile_poil
Messages postés682Date d'inscriptionvendredi 6 avril 2007StatutMembreDernière intervention 4 août 20126 15 févr. 2009 à 10:34
bonjour
sous XP il y a une solution ultra simple !!!!!
cells(1,1) = Environ("Username")
maintenant la fonction Environ peut te donner bien plus d'infos pour cela tu peux faire
dim i as integer
for i = 1 to 30
cells( 1, i) = environ( i)
next i
et en ligne 27 tu retrouveras le USERNAME =
[reglement.aspx ]si c'est la solution, penser : REPONSE ACCEPTEE