Library articles and tutorials
Getting System Folders Easily via API
- Introduction
- Windoze Directory
- System Directory
- Temporary Directory
- Finally...
Windoze Directory
An alternative to:
open "C:\Windows\System.ini" for input as #1
Input #1, strSomeString
Close #1
You can do this:
Open GetWindowsDirectory & "system.ini" for input as #1
Input #1, strSomeString
Close #1
So now when the users use it in say Windows NT 4 or Windows 2000(NT 5) you
wont get any errors to this critical windows required file.
The code to achieve this is quite easy. Insert the below code into a module(or
wait till the last section for all the code in one easy to use module).
Option Explicit
Private Declare Function GetWindowsDirectoryB Lib "kernel32" Alias "GetWindowsDirectoryA"
(ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Const MAX_LENGTH = 512
Public Function GetWindowsDirectory() As String
Dim s As String
Dim c As Long
s = String$(MAX_LENGTH, 0)
c = GetWindowsDirectoryB(s, MAX_LENGTH)
If c > 0 Then
If c > Len(s) Then
s = Space$(c + 1)
c = GetWindowsDirectoryB(s, MAX_LENGTH)
End If
End If
GetWindowsDirectory = IIf(c > 0, Left$(s, c), "")
End Function
This will get the windows Directory via the 'GetWindowsDirectoryA'
function in the Kernel32 API.
Press on...
Related articles
Related discussion
-
ditto
by zapthedingbat (2 replies)
-
Mousewheel
by jonh (3 replies)
-
True multithread VB source code controls
by James Crowley (3 replies)
-
Rely
by Yujvendra Verma (4 replies)
-
True multithread VB source code controls
by James Crowley (3 replies)
When you need the Temp folder, the easy (and clean .Net way) is to use: Path.GetTempPath()
it will still work for change dpaths... i used TweakXP to try it out on a few VMs and it worked fine... as far as other languaegs go... i only get English versions of OS's from MS so i dont know what the effects are, i suppose its teh same but i aint sure... amybe someone else maybe able to tell you.
so if the user changes their dir from say C:\WinNT\System32\ to C:\WindowsNT\System Files\ would i still be able to get the Windows DIR and System DIR?
also what about foreign languages?
hey,
sorry i couldnt reply earlier, I only saw my post now!
thank-you for your kind words!
Hey,
I must say this is EXTREEMLY useful for a nutcase like myself!
I infact had the exact problem you said most people have.
Thanks alot! It really helps!