Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 31,884 times

Contents

Related Categories

Getting System Folders Easily via API - Finally...

Finally...

And finally, here's a easy to insert list of functions you can insert to a module:

Option Explicit
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Declare Function GetWindowsDirectoryB Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Declare Function GetSystemDirectoryB Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal Path As String, ByVal cbBytes As Long) As Long
Private Const MAX_LENGTH = 512

Public Function GetWindowsSystemDirectory() As String
   Dim s As String
   Dim c As Long
   s = String$(MAX_LENGTH, 0)
   c = GetSystemDirectoryB(s, MAX_LENGTH)
   If c > 0 Then
       If c > Len(s) Then
           s = Space$(c + 1)
           c = GetSystemDirectoryB(s, MAX_LENGTH)
       End If
   End If
   GetWindowsSystemDirectory = IIf(c > 0, Left$(s, c), "")
End Function
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
Public Function GetTempDirectory() As String
   Dim s As String
   Dim c As Long
   s = Space$(MAX_LENGTH)
   c = GetTempPath(MAX_LENGTH, s)
   If c > 0 Then
       If c > Len(s) Then
           s = Space$(c + 1)
           c = GetTempPath(MAX_LENGTH, s)
       End If
   End If
   GetTempDirectory = IIf(c > 0, Left$(s, c), "")
End Function


Well hopefully you found my tutorial helpful. If my english doesn't make sense blame it on the booze!

As always if your stuck or want some help just post your messages on the forums or email me directly thushan.developerfusion@wsoftware.net and don't forget to include where you came from(as in the article page or subject or else i'll be lost).

Work Work Work
Currently I'm working at Vividas Pty Ltd and studying at Swinburne University. My time on DeveloperFusion is limited due to workloads on both parts, I do however keep a Blog that gets updated fairly regularly with lots of Techno-babble...

I also have a software business called WebSoftware Systems in Australia, the primary product we have at the moment is HotHTML which started life as a simple VB6 based HTML editor and is now a full blown text/web development IDE. I'm currently also working on the v4.0 release in .NET 2.0.

Comments

  • Temp path... the easy way

    Posted by svdoever on 23 Jul 2005

    When you need the Temp folder, the easy (and clean .Net way) is to use: Path.GetTempPath()

  • Posted by Thushan Fernando on 30 Aug 2003

    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 ...

  • Posted by boygenius on 30 Aug 2003

    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?

  • Posted by Thushan Fernando on 04 Jul 2002

    hey,

    sorry i couldnt reply earlier, I only saw my post now!

    thank-you for your kind words!

  • VERY USEFUL!

    Posted by MichaelMyAss on 21 Jun 2002

    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!