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

Windows Discussion :

variable d'environnement windows non interprétée


Sujet :

Windows

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    131
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 131
    Points : 50
    Points
    50
    Par défaut variable d'environnement windows non interprétée
    voila

    j'ai mon script qui doit écrire un fichier dans %windir%

    target[1] = "%WinDir%\\1147405550.exe";

    l'echo
    cout <<target[1];

    %WinDir%\1147405550.exe

    std::ofstream file(target[0], std::ios_base::binary);
    file << decoded_stub[0];

    n'écrit pas le fichier dans windir (ni ailleurs) alors que si je met

    target[1] = "%WinDir%\1147405550.exe";

    il me l'ecrit dans %cd%\"%WinDir%L7405550.exe

    c'est à dire qu'il ecrit un fichier nommé "%WinDir%L7405550.exe
    dans le repertoire courant

    j'en conclu que %windir% n'est pas interprétée

    quelqu'un aurait il une solution ?

    rogerio

  2. #2
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 518
    Points
    41 518
    Par défaut
    Sous windows 2000 et supérieur, il y a ceci:
    http://msdn.microsoft.com/library/de...sdirectory.asp

    Sinon, il faut que tu le fasses toi-même avec GetEnvironmentVariable(), etc.
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  3. #3
    Membre éclairé
    Avatar de Interruption13h
    Inscrit en
    Août 2005
    Messages
    603
    Détails du profil
    Informations forums :
    Inscription : Août 2005
    Messages : 603
    Points : 786
    Points
    786
    Par défaut
    Salut !

    Bon ben,pourquoi ne pas utiliser l'API GetWindowsDirectory :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    
    The GetWindowsDirectory function retrieves the path of the Windows 
    directory. The Windows directory contains such files as Windows-based 
    applications, initialization files, and Help files. 
    
    
    UINT GetWindowsDirectory(
    
        LPTSTR lpBuffer,	// address of buffer for Windows directory 
        UINT uSize 	// size of directory buffer 
       );	
    
     
    
    Parameters
    
    lpBuffer
    
    Points to the buffer to receive the null-terminated string containing the path. 
    This path does not end with a backslash unless the Windows directory is the 
    root directory. For example, if the Windows directory is named WINDOWS on 
    drive C, the path of the Windows directory retrieved by this function is 
    C:\WINDOWS. If Windows was installed in the root directory of drive C, the 
    path retrieved is C:\. 
    
    
    uSize
    
    Specifies the maximum size, in characters, of the buffer specified by the 
    lpBuffer parameter. This value should be set to at least MAX_PATH to allow 
    sufficient room in the buffer for the path. 
    
    
    
    Return Values
    
    If the function succeeds, the return value is the length, in characters, of the
     string copied to the buffer, not including the terminating null character. 
    If the length is greater than the size of the buffer, the return value is the 
    size of the buffer required to hold the path. 
    If the function fails, the return value is zero. To get extended error 
    information, call GetLastError. 
    
    Remarks
    
    The Windows directory is the directory where an application should store 
    initialization and help files. If the user is running a shared version of Windows,
     the Windows directory is guaranteed to be private for each user. 
    If an application creates other files that it wants to store on a per-user 
    basis, it should place them in the directory specified by the HOMEPATH 
    environment variable. This directory will be different for each user, if so 
    specified by an administrator, via the User Manager administrative tool. 
    HOMEPATH always specifies either the user's home directory, which is 
    guaranteed to be private for each user, or a default directory (for example, 
    C:\USERS\DEFAULT) where the user will have all access.


    A+
    Plus tu prends part aux joies et chagrins des gens, plus ils te sont proches et chers. Mais c'est le chagrin et les problèmes qui vous rapprochent le plus.

    (Mark TWAIN)

  4. #4
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 518
    Points
    41 518
    Par défaut
    Dans ce cas, si l'on veut toucher aux dossiers pointés par les variables d'environnement (ex: windir, homedrive, homepath, appdata), on peut carrément s'attaquer à SHGetSpecialFolderPath()...
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    131
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 131
    Points : 50
    Points
    50
    Par défaut cool
    cool

    c'était exactement ça (bravo et merci)

    le c++ ça doit etre geant quand on touche bien sa bille

    qu'est ce que c'est chiant quand on débute


    char szPath[MAX_PATH];

    SHGetFolderPath(0, CSIDL_WINDOWS , NULL, 0, szPath ) ) ;

    sans oublier

    #include <shlobj.h>

    je compile avec mingw

    merci encore

    rogerio

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

Discussions similaires

  1. récupération de variable d'environnement windows avec javascript
    Par dorian2031 dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 22/11/2006, 11h37
  2. [Système] Variable d'environnement Windows
    Par jdiamsss dans le forum Langage
    Réponses: 2
    Dernier message: 15/11/2006, 17h47
  3. [PHP-JS] Variable d'environnement Windows username
    Par licorne dans le forum Langage
    Réponses: 4
    Dernier message: 28/09/2006, 14h52
  4. Réponses: 9
    Dernier message: 27/09/2006, 15h58

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