VB Function to find Windows System Directory 
Author Message
 VB Function to find Windows System Directory

Is there a VB function that gives you the windows directory and the windows
system directory, and if so can you please tell what it is.

Thanks Mark



Mon, 13 Dec 2004 06:42:54 GMT  
 VB Function to find Windows System Directory

Quote:

> Is there a VB function that gives you the windows directory and the windows
> system directory, and if so can you please tell what it is.

> Thanks Mark

See: http://www.vb2themax.com/Item.asp?PageID=TipBank&ID=133
...
George
GridLinx Software       Programming Tools for VB Programmers
http://www.gridlinx.com


Mon, 13 Dec 2004 06:49:36 GMT  
 VB Function to find Windows System Directory


Quote:
> Is there a VB function that gives you the windows directory and the
windows
> system directory, and if so can you please tell what it is.

> Thanks Mark

private declare function GetSystemDirectoryA lib "kernel32" _
    (ByVal lpBuffer As String, _
     ByVal uSize As Long) As Long

private const MAX_PATH As Long = 260

Public Function GetSystemDirectory() As String
    Dim cChars As Long

    GetSystemDirectory = String$(MAX_PATH + 1, vbNullChar)
    cChars = GetSystemDirectoryA(GetSystemDirectory,
Len(GetSystemDirectory))
    GetSystemDirectory = Left$(GetSystemDirectory, cChars)
End Function

HTH,
Tom Shelton



Mon, 13 Dec 2004 06:55:36 GMT  
 VB Function to find Windows System Directory


Quote:


> > Is there a VB function that gives you the windows directory and the
windows
> > system directory, and if so can you please tell what it is.

> > Thanks Mark

> See: http://www.vb2themax.com/Item.asp?PageID=TipBank&ID=133
> ...
> George
> GridLinx Software Programming Tools for VB Programmers
> http://www.gridlinx.com

I always get a little nervous using Environment variables for this kind of
thing.  First you have the fact that sometimes they only exist on a
particular platform, which can lead to problems if you expect your code to
run on other versions of Windows.  Second you have the issue of future
releases - the environment variable may go away or things could change in
some other incompatible way.  I for one will use the 2 or 3 extra lines of
code and call the API function if one exists - besides once you have the
wrapper for it...

Tom Shelton



Mon, 13 Dec 2004 07:02:28 GMT  
 VB Function to find Windows System Directory
Perhaps it's just me, and I am not trying to be critical of Tom's coding
style....

But does anybody else think it's "bad" to use a function's name within the
function as if it were a variable?  I realize VB treats GetSystemDirectory
WITHIN GetSystemDirectory just as if it were a local variable of type
String.  But it *looks* like GetSystemDirectory is getting called
recursively, three different times.

Just interested in others' opinions/thoughts on that particular style of
coding.

Mike


Quote:
> private declare function GetSystemDirectoryA lib "kernel32" _
>     (ByVal lpBuffer As String, _
>      ByVal uSize As Long) As Long

> private const MAX_PATH As Long = 260

> Public Function GetSystemDirectory() As String
>     Dim cChars As Long

>     GetSystemDirectory = String$(MAX_PATH + 1, vbNullChar)
>     cChars = GetSystemDirectoryA(GetSystemDirectory,
> Len(GetSystemDirectory))
>     GetSystemDirectory = Left$(GetSystemDirectory, cChars)
> End Function



Mon, 13 Dec 2004 08:00:57 GMT  
 VB Function to find Windows System Directory


Quote:
> Perhaps it's just me, and I am not trying to be critical of Tom's coding
> style....

> But does anybody else think it's "bad" to use a function's name within the
> function as if it were a variable?  I realize VB treats GetSystemDirectory
> WITHIN GetSystemDirectory just as if it were a local variable of type
> String.  But it *looks* like GetSystemDirectory is getting called
> recursively, three different times.

> Just interested in others' opinions/thoughts on that particular style of
> coding.

Well, I'll tell you my justification for doing this - in case your
interested, or not :)  It seems to me a little wastefull not to use the
function name.  VB declares a variable of the same type and name as your
function - whether it's asked for or not, so I figure why declare a separate
variable when VB has declared one for me.  I realize it is only a 4 byte
pointer that is beign wasted by not doing it - but 4 bytes adds up :)

Tom Shelton



Mon, 13 Dec 2004 10:40:58 GMT  
 VB Function to find Windows System Directory
I don't think it's bad. The variable is there whether you
use it or not. Might as well use it.

-Pete


Quote:
> Perhaps it's just me, and I am not trying to be critical
of Tom's coding
> style....

> But does anybody else think it's "bad" to use a function's
name within the
> function as if it were a variable?  I realize VB treats
GetSystemDirectory
> WITHIN GetSystemDirectory just as if it were a local
variable of type
> String.  But it *looks* like GetSystemDirectory is getting
called
> recursively, three different times.

> Just interested in others' opinions/thoughts on that
particular style of
> coding.

> Mike



> > private declare function GetSystemDirectoryA lib
"kernel32" _
> >     (ByVal lpBuffer As String, _
> >      ByVal uSize As Long) As Long

> > private const MAX_PATH As Long = 260

> > Public Function GetSystemDirectory() As String
> >     Dim cChars As Long

> >     GetSystemDirectory = String$(MAX_PATH + 1,
vbNullChar)
> >     cChars = GetSystemDirectoryA(GetSystemDirectory,
> > Len(GetSystemDirectory))
> >     GetSystemDirectory = Left$(GetSystemDirectory,
cChars)
> > End Function



Wed, 15 Dec 2004 00:22:58 GMT  
 VB Function to find Windows System Directory
Hello,

Set a reference to the scripting runtime...

then,

========================================
    Dim oFSO As New Scripting.FileSystemObject
    Dim WinDir As String
    Dim SysDir As String

    WinDir = oFSO.GetSpecialFolder(WindowsFolder)
    SysDir = oFSO.GetSpecialFolder(SystemFolder)

    Debug.Print WinDir
    Debug.Print SysDir

    Set oFSO = Nothing
========================================

-cliff knight-


Quote:
> Is there a VB function that gives you the windows directory and the
windows
> system directory, and if so can you please tell what it is.

> Thanks Mark



Wed, 15 Dec 2004 03:21:34 GMT  
 VB Function to find Windows System Directory

Quote:
> Hello,

> Set a reference to the scripting runtime...

aaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrgggggggggggggggghhhhhhhhhhhhhhhhhhhhh


Wed, 15 Dec 2004 06:20:38 GMT  
 VB Function to find Windows System Directory
Well, that's one way...probably not what any "serious" programmer would
recommend, though.  If you're already using the FSO for other things (which
is unnecessary in and of itself)...sure....you might as well use it for this
too.  But for crying out loud, don't ADD the FSO just for this.

Mike


Quote:
> Hello,

> Set a reference to the scripting runtime...

> then,

> ========================================
>     Dim oFSO As New Scripting.FileSystemObject
>     Dim WinDir As String
>     Dim SysDir As String

>     WinDir = oFSO.GetSpecialFolder(WindowsFolder)
>     SysDir = oFSO.GetSpecialFolder(SystemFolder)

>     Debug.Print WinDir
>     Debug.Print SysDir

>     Set oFSO = Nothing
> ========================================



Wed, 15 Dec 2004 07:35:49 GMT  
 VB Function to find Windows System Directory

Quote:
> > Set a reference to the scripting runtime...

> aaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrgggggggggggggggghhhhhhhhhhhhhhhhhhhhh

I once taught someone how to use a hammer and now everything looks like
a nail to him. <g>

Rick



Fri, 24 Dec 2004 23:04:03 GMT  
 VB Function to find Windows System Directory

Quote:
>>> Set a reference to the scripting runtime...

>> aaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrgggggggggggggggghhhhhhhhhhhhhhhhhhhhh

> I once taught someone how to use a hammer and now everything looks
> like a nail to him. <g>

Give a man some fire and he's warm for the night.
Set a man on fire and he's warm for the rest of his life.
<g>

I think there's an eight ring of hell reserved for people who use FSO
indiscriminately.



Fri, 24 Dec 2004 23:14:16 GMT  
 VB Function to find Windows System Directory

Quote:



> >>> Set a reference to the scripting runtime...

> >> aaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrgggggggggggggggghhhhhhhhhhhhhhhhhhhhh

> > I once taught someone how to use a hammer and now everything looks
> > like a nail to him. <g>

> Give a man some fire and he's warm for the night.
> Set a man on fire and he's warm for the rest of his life.
> <g>

> I think there's an eight ring of hell reserved for people who use FSO
> indiscriminately.

And a ninth for those who refuse even when it's actually appropriate.

        Bob
--
VB expert looking for work  <http://resumes.dice.com/bobobob>



Sat, 25 Dec 2004 00:55:48 GMT  
 VB Function to find Windows System Directory


Or generically:

Quote:
> > I think there's an eight ring of hell reserved for people who use
> > <%Some often-misused piece of the language%> indiscriminately.
> And a ninth for those who refuse even when it's actually appropriate.



Sat, 25 Dec 2004 05:02:56 GMT  
 
 [ 14 post ] 

 Relevant Pages 

1. Find Windows System Directory via VBA?

2. How to find the location of windows and windows\system folders

3. Finding Hidden & System Directories

4. Help! Program Can't Find system directory

5. Windows System Directory from Access97

6. Windows System Directory

7. Locating Windows System directory

8. windows system directory

9. Do vbx's/dll's have to go in c:\windows\system directory

10. Need Windows\system directory name

11. WINDOWS SYSTEM DIRECTORY

12. Need to know Windows\System directory name

 

 
Powered by phpBB® Forum Software