IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

Récupérer l'utilisateur courant


Sujet :

C++

  1. #1
    Futur Membre du Club
    Inscrit en
    Septembre 2006
    Messages
    6
    Détails du profil
    Informations forums :
    Inscription : Septembre 2006
    Messages : 6
    Points : 8
    Points
    8
    Par défaut Récupérer l'utilisateur courant
    Slt tt l monde,
    Voilà, j'ai tant cherché dans les FAQ et tutos C++, et je ne suis pas arrivé à trouver une fonction qui me renvoie l'utilisateur courant ainsi que le nom de la machine;
    Est ce que qq'1 sait comment faire??
    Merci

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    464
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 464
    Points : 542
    Points
    542
    Par défaut
    Ce genre de chose est spécifique à chaque OS.
    "La forme même des Pyramides prouve que de tous temps, les ouvriers n'ont jamais pensé qu'à en faire de moins en moins."

    G. CLEMENCEAU

  3. #3
    Futur Membre du Club
    Inscrit en
    Septembre 2006
    Messages
    6
    Détails du profil
    Informations forums :
    Inscription : Septembre 2006
    Messages : 6
    Points : 8
    Points
    8
    Par défaut
    C vrai en fait il s'agit de windows XP

  4. #4
    Membre émérite
    Avatar de Ti-R
    Homme Profil pro
    Ingénieur R&D
    Inscrit en
    Avril 2003
    Messages
    1 683
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Ingénieur R&D
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2003
    Messages : 1 683
    Points : 2 568
    Points
    2 568
    Par défaut
    "gethostname" fonction qui fait partie des sockets.
    Retourne le nom de la machine. Compatible Windows/Linux.

  5. #5
    Expert confirmé
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Décembre 2003
    Messages
    3 549
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Décembre 2003
    Messages : 3 549
    Points : 4 625
    Points
    4 625
    Par défaut
    Regarde dans les variables d'environnement
    Boost ftw

  6. #6
    Expert éminent sénior
    Avatar de Luc Hermitte
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2003
    Messages
    5 275
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Août 2003
    Messages : 5 275
    Points : 10 985
    Points
    10 985
    Par défaut
    Citation Envoyé par Ti-R
    "gethostname" fonction qui fait partie des sockets.
    POSIX tu veux dire ?
    Et je doute que cela réponde à sa question : IIRC, cela retourne des noms de machines.
    Blog|FAQ C++|FAQ fclc++|FAQ Comeau|FAQ C++lite|FAQ BS|Bons livres sur le C++
    Les MP ne sont pas une hotline. Je ne réponds à aucune question technique par le biais de ce média. Et de toutes façons, ma BAL sur dvpz est pleine...

  7. #7
    fd
    fd est déconnecté
    Membre habitué
    Profil pro
    Inscrit en
    Mai 2002
    Messages
    131
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2002
    Messages : 131
    Points : 162
    Points
    162
    Par défaut utilisateur
    The GetUserName function retrieves the user name of the current thread. This is the name of the user currently logged onto the system.

    Windows 2000: Use the GetUserNameEx function to retrieve the user name in a specified format.

    BOOL GetUserName(
    LPTSTR lpBuffer, // name buffer
    LPDWORD nSize // size of name buffer
    );
    Parameters
    lpBuffer
    [out] Pointer to the buffer to receive the null-terminated string containing the user's logon name. If this buffer is not large enough to contain the entire user name, the function fails. A buffer size of (UNLEN + 1) characters will hold the maximum length user name including the terminating null character. UNLEN is defined in Lmcons.h.
    nSize
    [in/out] Pointer to a DWORD variable that, on input, specifies the maximum size, in TCHARs, of the buffer specified by the lpBuffer parameter. If the function succeeds, the variable receives the number of characters copied to the buffer. If the buffer is not large enough, the function fails and the variable receives the required buffer size, in TCHARs, including the terminating null character.
    Return Values
    If the function succeeds, the return value is a nonzero value, and the variable pointed to by nSize contains the number of characters copied to the buffer specified by lpBuffer, including the terminating null character.

    If the function fails, the return value is zero. To get extended error information, call GetLastError.

  8. #8
    fd
    fd est déconnecté
    Membre habitué
    Profil pro
    Inscrit en
    Mai 2002
    Messages
    131
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2002
    Messages : 131
    Points : 162
    Points
    162
    Par défaut machine
    GetComputerName
    The GetComputerName function retrieves the NetBIOS name of the local computer. This name is established at system startup, when the system reads it from the registry.

    If the local computer is a node in a cluster, GetComputerName returns the name of the node.

    Windows 2000: GetComputerName retrieves only the NetBIOS name of the local computer. To retrieve the DNS host name, DNS domain name, or the fully qualified DNS name, call the GetComputerNameEx function.

    BOOL GetComputerName(
    LPTSTR lpBuffer, // computer name
    LPDWORD lpnSize // size of name buffer
    );
    Parameters
    lpBuffer
    [out] Pointer to a buffer that receives a null-terminated string containing the computer name. The buffer size should be large enough to contain MAX_COMPUTERNAME_LENGTH + 1 characters.
    lpnSize
    [in/out] Pointer to a DWORD variable. On input, the variable specifies the size, in TCHARs, of the buffer. On output, the variable receives the number of TCHARs copied to the destination buffer, not including the terminating null character.
    If the buffer is too small, the function fails, GetLastError returns ERROR_BUFFER_OVERFLOW, and the variable returns the required buffer size including the terminating null character.

    Windows 95/98: GetComputerName fails if the input size is less than MAX_COMPUTERNAME_LENGTH + 1.

    Return Values
    If the function succeeds, the return value is a nonzero value.

    If the function fails, the return value is zero. To get extended error information, call GetLastError.

  9. #9
    Membre émérite
    Avatar de Ti-R
    Homme Profil pro
    Ingénieur R&D
    Inscrit en
    Avril 2003
    Messages
    1 683
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Ingénieur R&D
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2003
    Messages : 1 683
    Points : 2 568
    Points
    2 568
    Par défaut
    Citation Envoyé par Luc Hermitte
    POSIX tu veux dire ?
    Et je doute que cela réponde à sa question : IIRC, cela retourne des noms de machines.
    Je ne sais pas si la fonction est POSIX

    Citation Envoyé par nbeligh
    ...et je ne suis pas arrivé à trouver une fonction qui me renvoie l'utilisateur courant ainsi que le nom de la machine;
    Cela ne répond pas à toute sa question mais en partie !

    Sous Windows elle renvoie bien le nom de l'ordinateur (je l'utilise)

    Et en tapant "man gethostname" sous google il y a ce résultat

    man gethostname

    extrait
    CONFORMITÉ
    SVr4, 4.4BSD (Cette fonction est apparue en premier dans
    4.2BSD). POSIX.1 ne définit pas ces fonctions, mais
    ISO/IEC 9945-1:1990 les mentionne au paragraphe B.4.4.1.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 3
    Dernier message: 29/05/2010, 11h28
  2. Comment récupérer l'utilisateur courant ?
    Par colorid dans le forum SQL
    Réponses: 4
    Dernier message: 23/10/2007, 16h37
  3. Réponses: 10
    Dernier message: 17/05/2006, 11h22
  4. Réponses: 5
    Dernier message: 11/10/2005, 11h40
  5. Réponses: 3
    Dernier message: 07/05/2004, 10h01

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo