|
-
Jun 19th, 2006, 07:02 AM
#1
Thread Starter
Hyperactive Member
How to get the windows folder [Resolved]
Hi, simple question, I just want to open a file stored in the windows folder, my problem is getting the windows folder location.
I just need something like
Dim path As String = Application.StartupPath
but rather than pointing to the the application startup path I want the windows directory. which I belive can either be c:\windows (on XP) or c:\winnt
Cheers.
Last edited by Oliver1; Jun 19th, 2006 at 10:49 AM.
Reason: Resolved
-
Jun 19th, 2006, 07:43 AM
#2
Fanatic Member
Re: How to get the windows folder
You need to add a reference to 'Scripting' to use a FileSystemObject to find the Windows Folder. It's done like this:
1. From the Project menu, select Add Reference....
2. In the COM-tab select Microsoft Scripting Runtime, click Select and click OK
Now you can use the FileSystemObject like this:
VB Code:
Dim fso As New Scripting.FileSystemObject
Dim sWinDir As String = fso.GetSpecialFolder(Scripting.SpecialFolderConst.WindowsFolder).Path
There you go. It's harder than it should be. But this works.
You can actually use this to delete the Windows folder, but I wouldn't recommend that.
No matter how fool-proof your program is, there will always be a better fool.
Was a post helpful to you? Rate it!
-
Jun 19th, 2006, 07:45 AM
#3
Re: How to get the windows folder
Will this work?
VB Code:
MessageBox.Show(System.Environment.SystemDirectory)
You can also use:
VB Code:
system.Environment.GetFolderPath
To get pretty much any "common" directory that you might be after.
-
Jun 19th, 2006, 07:47 AM
#4
Fanatic Member
Re: How to get the windows folder
 Originally Posted by sevenhalo
Will this work?
VB Code:
MessageBox.Show(System.Environment.SystemDirectory)
That shows the System32 folder's location.
No matter how fool-proof your program is, there will always be a better fool.
Was a post helpful to you? Rate it!
-
Jun 19th, 2006, 07:49 AM
#5
Re: How to get the windows folder
 Originally Posted by arsmakman
That shows the System32 folder's location.
With basic logic, you can determine the parent directory.
-
Jun 19th, 2006, 07:56 AM
#6
Fanatic Member
Re: How to get the windows folder
Okay, you win. But I still like mine better. 
Anyway, for the people of little IO-experience:
VB Code:
IO.Directory.GetParent(System.Environment.SystemDirectory).ToString()
No matter how fool-proof your program is, there will always be a better fool.
Was a post helpful to you? Rate it!
-
Jun 19th, 2006, 08:43 AM
#7
Re: How to get the windows folder
I'd say stick to .NET types and members if they're available before referencing COM libraries.
-
Jun 19th, 2006, 10:45 AM
#8
Thread Starter
Hyperactive Member
Re: How to get the windows folder
Thanks, have gone for
VB Code:
Dim winfolder As String = System.Environment.SystemDirectory
Dim endpoint As Integer
endpoint = InStr(winfolder, "System", CompareMethod.Text) - 1
winfolder = Mid(winfolder, 1, endpoint)
MsgBox(winfolder)
Just waiting for someone to Incredible Hulk on me now for using old VB functions. I can never remember the correct .net functions.
-
Jun 19th, 2006, 10:50 AM
#9
Fanatic Member
Re: How to get the windows folder
I don't want to Incredible Hulk you, but I feel I have to, because I even gave the correct .net function away (see my post above)!
And I didn't remember it, I found it. Because it's in a very logical place. It's really not that hard.
No matter how fool-proof your program is, there will always be a better fool.
Was a post helpful to you? Rate it!
-
Jun 19th, 2006, 11:04 AM
#10
Thread Starter
Hyperactive Member
Re: How to get the windows folder [Resolved]
Ah, but jmcilhinney who is never wrong (well I think I read one post where he was, but maybe I just dreamt it) said not to use a com libary if I could avoid it.
-
Jun 19th, 2006, 11:06 AM
#11
Fanatic Member
Re: How to get the windows folder
 Originally Posted by arsmakman
Okay, you win. But I still like mine better.
Anyway, for the people of little IO-experience:
VB Code:
IO.Directory.GetParent(System.Environment.SystemDirectory).ToString()
I ment this ^ post.
No matter how fool-proof your program is, there will always be a better fool.
Was a post helpful to you? Rate it!
-
Jun 19th, 2006, 11:07 AM
#12
Thread Starter
Hyperactive Member
Re: How to get the windows folder [Resolved]
Argh, didn't realise your latest post didn't involve the com libary.
Sorry have changed my code now, and please don't get all gamma radition like on me.
-
Jun 19th, 2006, 11:10 AM
#13
Fanatic Member
Re: How to get the windows folder [Resolved]
 Originally Posted by Oliver1
please don't get all gamma radition like on me.
I'll try...
No matter how fool-proof your program is, there will always be a better fool.
Was a post helpful to you? Rate it!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|