Window directory ? How do i locate it

Quantumfusion
10-09-2004, 10:01 PM
Hi, i would like to know how can i locate where the window(xp,nt,2000,me) is installed. =/
Thanks in advance

OnErr0r
10-09-2004, 10:04 PM
GetWindowsDirectory

rajeeshun
10-09-2004, 10:06 PM
Use the GetWindowsDirectory API (For sample, please visit to AllApi.net)


Edit:
Oh... I am toooooooo Late

Quantumfusion
10-09-2004, 10:13 PM
o... but how come it return me a number instead of a path ?

OnErr0r
10-09-2004, 10:33 PM
You probably forgot to initialize the string buffer before calling the function.

Quantumfusion
10-09-2004, 10:35 PM
You probably forgot to initialize the string buffer before calling the function.

could u give me an example on how u do it ?

OnErr0r
10-09-2004, 10:40 PM
Option Explicit

Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Const MAX_PATH = 260

Private Sub Form_Load()
Dim s As String
Dim lRet As Long

s = Space$(MAX_PATH)
lRet = GetWindowsDirectory(s, Len(s))
Debug.Print Left$(s, lRet)
End Sub

Quantumfusion
10-09-2004, 10:44 PM
oh cool i manage to get it working =D thanks !

rajeeshun
10-09-2004, 11:22 PM
Just I though...

No need to use the API for this, we can simply use the Environment variables to find the windows directory

'To get the Windows path
MsgBox Environ("windir")
'Or you can get this with the following variable
MsgBox Environ(41)

OnErr0r
10-10-2004, 12:04 AM
The Environ$ function with "windir" is a good bet. But don't hardcode to 41, that will often fail.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum