Results 1 to 9 of 9

Thread: How to get Windows directory path?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2003
    Posts
    74

    How to get Windows directory path?

    What is the code to get the Windows directory for the local machine?

    i.e. c:\WINNT or c:\Windows

    Thanks!

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    VB Code:
    1. MessageBox.Show(Environment.GetFolderPath(Environment.SpecialFolder.System))

  3. #3
    Addicted Member
    Join Date
    Sep 2003
    Posts
    227
    try using this property >>
    system.environment.systemdirectory

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Same result .

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2003
    Posts
    74
    This gives me the C:\[Windows Dir]\System32\ directory. Is there a property that will just return me the Windows directory (without the System32)? Of course, I can parse it out, but just wondering if there is a property for it so I don't have to do the work...

    Thanks again!

  6. #6
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    VB Code:
    1. Declare Function GetWindowsDirectory Lib "kernel32.dll" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As System.Text.StringBuilder, ByVal nSize As Integer) As Integer
    2.  
    3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    4.         Dim path As New System.Text.StringBuilder(255)
    5.         GetWindowsDirectory(path, path.Capacity)
    6.  
    7.         MessageBox.Show(path.ToString)
    8.  
    9.     End Sub
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Aug 2003
    Posts
    74
    I'd like to do it without using API calls. If there is a .NET property handy, I'd much rather use that. Are there any .NET properties or functions available?

  8. #8
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    yes...
    VB Code:
    1. Dim path As New IO.DirectoryInfo(Environment.SystemDirectory)
    2.  
    3.         MessageBox.Show(path.FullName.Replace(path.Name, ""))
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Aug 2003
    Posts
    74
    Great! Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width