OVH Cloud OVH Cloud

WinPath

1 réponse
Avatar
Ciginfo
Bonjour

Lorsque je crée un fichier du style :
'Cree un fichier dans C:\Windows
Open (WinPath) & "\Fichier.txt" For Output As #1: Write #1,
etc....

le fichier se crée dans C:\ et non pas dans C:\WINDOWS

Je pensais qu'à WinPath correspondait C:\WINDOWS et qu'à WinSysPath
correspondait C:\WINDOWS\SYSTEME. Qu'en est il exactement et comment créer
mon fichier dans C:\WINDOWS ?

Merci


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.691 / Virus Database: 452 - Release Date: 26/05/2004

1 réponse

Avatar
François Picalausa
Hello,

Eventuellement avec Environ tu peux utiliser de tels noms.
Par exemple:
Msgbox environ("SystemRoot")

Mais une autre technique par APIs existe:
http://faq.vb.free.fr/index.php?question`

(WinPath) et (WinSysPath) sont utilisés dans le P&D Wizard mais quand on
regarde au code du projet de l'installateur, on se rend compte que ces noms
sont convertis:
Public Const gstrWINDEST$ = "$(WinPath)"

Public Function ResolveDestDir(ByVal strDestDir As String, ...) As String
...

Select Case UCase$(Left$(strDestDir, intPos))
...
Case UCase$(gstrWINDEST)
strResolved = gstrWinDir
fRecognizedBySetupExe = True

Avec
gstrWinDir = GetWindowsDir()

Qui est retrouvé comme ceci:
'-----------------------------------------------------------
' FUNCTION: GetWindowsDir
'
' Calls the windows API to get the windows directory and
' ensures that a trailing dir separator is present
'
' Returns: The windows directory
'-----------------------------------------------------------
'
Public Function GetWindowsDir() As String
Dim strBuf As String

strBuf = Space$(gintMAX_SIZE)
'
'Get the windows directory and then trim the buffer to the exact length
'returned and add a dir sep (backslash) if the API didn't return one
'
If GetWindowsDirectory(strBuf, gintMAX_SIZE) Then
GetWindowsDir = StringFromBuffer(strBuf)
AddDirSep GetWindowsDir
End If
End Function

--
François Picalausa (MVP VB)
http://faq.vb.free.fr --- http://msdn.microsoft.com
http://apisvb.europe.webmatrixhosting.net

"Ciginfo" a écrit dans le message de
news:c9cenc$le5$
Open (WinPath) & "Fichier.txt" For Output As #1
le fichier se crée dans C: et non pas dans C:WINDOWS

Je pensais qu'à WinPath correspondait C:WINDOWS et qu'à WinSysPath
correspondait C:WINDOWSSYSTEME. Qu'en est il exactement et comment
créer mon fichier dans C:WINDOWS ?