-
Does anyone know how to get the system directory
f.e. "C:\Windows\System", or "C:\WINNT\System32"?
I know how to get the temp directory:
Code:
Declare Function GetTempPath Lib "kernel32" Alias _
"GetTempPathA" (ByVal nBufferLength As Long, ByVal _
lpBuffer As String) As Long
Public Const MAX_PATH = 260
Function GetTempDir()
On Error Resume Next
Dim TempDir As String
TempDir = String(MAX_PATH, 0)
If GetTempPath(MAX_PATH, TempDir) <> 0 Then
GetTempDir = Left(TempDir, InStr(TempDir, _
Chr(0)) - 1)
Else
GetTempDir = ""
End If
End Function
Any suggestions?
thx, vbzero
-
<?>
find the windows directory and system has to be under windows
Code:
'find the windows directory path
'usefull in shell commands if you know something
'is in the windows directory
'example..instead of shell c:\windows\notepad.ext
'you could use shell windir$ & /notepad.exe
'if windows was stored in E:/Windows then you wouldn't get an error
'if you used shell c:/windosw\notepad.exe, it couldn't be found '(error)
'
Option Explicit
Private Declare Function GetWindowsDirectory _
Lib "kernel32" Alias "GetWindowsDirectoryA" _
(ByVal lpBuffer As String, ByVal nSize As Long) As Long
'
Private Sub Form_Load()
'
Dim strFindWinDir$, WinDir$
'
WinDir$ = Space(144)
strFindWinDir$ = GetWindowsDirectory(WinDir$, 144)
WinDir$ = Trim(WinDir$)
'
MsgBox "The Windows Directory Path is: " & WinDir$
'
End Sub
-
This won't work in Windows 2000/NT because the system
directory wouldn't be ..\System.
It would be ..\System32.
Primary in Windows 9x/Me the directories are C:\Windows\System and in 2000/NT C:\WINNT\System32.
The code which was posted only gets the windows directory
but not the system directory.
My program will work in Windows 9x and 2000/NT and so I need to find out the system directory in each system.
thx, vbzero
-
Code:
Declare Function SHGetSpecialFolderPath Lib "shell32.dll" Alias "SHGetSpecialFolderPathA" (ByVal hwndOwner As Long, ByVal lpszPath As String, ByVal nFolder As Long, ByVal fCreate As Long) As Long
Const CSIDL_SYSTEM = &H25
Function GetSystemDir() As String
' Display the path of the directory used as the System
' special folder.
Dim pathname As String ' receives the path of System DDim retval As Long ' return value
' Make enough room in the buffer to receive the string.
pathname = Space(260)
' Get the path name of the My Documents special folder
retval = SHGetSpecialFolderPath(Form1.hWnd, pathname, CSIDL_SYSTEM, 0)
' Remove the empty space from the string.
pathname = Left(pathname, InStr(pathname, vbNullChar) - 1)
' Display the result.
GetSystemDir = pathname
This should do it
-
It works! Thanks!
thx, vbzero