Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Window directory ? How do i locate it


Reply
 
Thread Tools Display Modes
  #1  
Old 10-09-2004, 10:01 PM
Quantumfusion Quantumfusion is offline
Centurion
 
Join Date: Oct 2004
Posts: 176
Default Window directory ? How do i locate it


Hi, i would like to know how can i locate where the window(xp,nt,2000,me) is installed. =/
Thanks in advance
Reply With Quote
  #2  
Old 10-09-2004, 10:04 PM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,685
Default

__________________
Quis custodiet ipsos custodues.
Reply With Quote
  #3  
Old 10-09-2004, 10:06 PM
rajeeshun rajeeshun is offline
Senior Contributor
 
Join Date: Oct 2002
Location: Dubai & Srilanka (Jaffna)
Posts: 1,151
Default

Use the GetWindowsDirectory API (For sample, please visit to AllApi.net)


Edit:
Oh... I am toooooooo Late
Reply With Quote
  #4  
Old 10-09-2004, 10:13 PM
Quantumfusion Quantumfusion is offline
Centurion
 
Join Date: Oct 2004
Posts: 176
Default

o... but how come it return me a number instead of a path ?
Reply With Quote
  #5  
Old 10-09-2004, 10:33 PM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,685
Default

You probably forgot to initialize the string buffer before calling the function.
__________________
Quis custodiet ipsos custodues.
Reply With Quote
  #6  
Old 10-09-2004, 10:35 PM
Quantumfusion Quantumfusion is offline
Centurion
 
Join Date: Oct 2004
Posts: 176
Default

Quote:
Originally Posted by OnErr0r
You probably forgot to initialize the string buffer before calling the function.
could u give me an example on how u do it ?
Reply With Quote
  #7  
Old 10-09-2004, 10:40 PM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,685
Default

Code:
Option Explicit Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long Private Const MAX_PATH = 260 Private Sub Form_Load() Dim s As String Dim lRet As Long s = Space$(MAX_PATH) lRet = GetWindowsDirectory(s, Len(s)) Debug.Print Left$(s, lRet) End Sub
__________________
Quis custodiet ipsos custodues.
Reply With Quote
  #8  
Old 10-09-2004, 10:44 PM
Quantumfusion Quantumfusion is offline
Centurion
 
Join Date: Oct 2004
Posts: 176
Thumbs up

oh cool i manage to get it working =D thanks !
Reply With Quote
  #9  
Old 10-09-2004, 11:22 PM
rajeeshun rajeeshun is offline
Senior Contributor
 
Join Date: Oct 2002
Location: Dubai & Srilanka (Jaffna)
Posts: 1,151
Default

Just I though...

No need to use the API for this, we can simply use the Environment variables to find the windows directory
Code:
'To get the Windows path MsgBox Environ("windir") 'Or you can get this with the following variable MsgBox Environ(41)
Reply With Quote
  #10  
Old 10-10-2004, 12:04 AM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,685
Default

The Environ$ function with "windir" is a good bet. But don't hardcode to 41, that will often fail.
__________________
Quis custodiet ipsos custodues.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->