-
Oct 29th, 2010, 01:03 PM
#1
Thread Starter
New Member
[RESOLVED] Save file, need to determine XP/7
Hi. I have a problem, I need my app to determine between Win XP, Vista and Win 7 so It can deside which path to save txt file. I know this can be solved by running program as administrator and be able to save in whatever path you like but it would be good if the user didnt have to. Vista and win 7 suxx in this regard although win7 is great otherwise, use it myself.
Anyways would be nice if it was as simple as:
OS = humhum
and the if else
but probably not TT
Thx in advance
-
Oct 29th, 2010, 01:24 PM
#2
Re: Save file, need to determine XP/7
this info should help you.. i just googled "c# get operating system" (for you):
Code:
Console.WriteLine("Operating System Detaiils");
OperatingSystem os = Environment.OSVersion;
Console.WriteLine("OS Version: " + os.Version.ToString());
Console.WriteLine("OS Platoform: " + os.Platform.ToString());
Console.WriteLine("OS SP: " + os.ServicePack.ToString());
Console.WriteLine("OS Version String: " + os.VersionString.ToString());
Console.WriteLine();
// Get Version details
Version ver = os.Version;
Console.WriteLine("Major version: " + ver.Major);
Console.WriteLine("Major Revision: " + ver.MajorRevision);
Console.WriteLine("Minor version: " + ver.Minor);
Console.WriteLine("Minor Revision: " + ver.MinorRevision);
Console.WriteLine("Build: " + ver.Build);
* Rate It If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID
-
Oct 29th, 2010, 01:39 PM
#3
Thread Starter
New Member
Re: Save file, need to determine XP/7
Not to sound ungrateful but i work with vb .net
anyways thx
-
Oct 29th, 2010, 03:27 PM
#4
Re: Save file, need to determine XP/7
The 'My' namespace may have the directory you're looking for
Code:
Debug.WriteLine(My.Computer.FileSystem.SpecialDirectories.MyDocuments)
Debug.WriteLine(My.Computer.FileSystem.SpecialDirectories.Desktop)
That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma
Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney
-
Oct 29th, 2010, 04:08 PM
#5
Thread Starter
New Member
Re: Save file, need to determine XP/7
Ty Bill but I think i will solve this the easy way.
Since the problem for me is that win7 and vista wont let the app save files werever it want I thought i simply make the app save in user folder on win XP as well. Create the path if it doesnt exist.
------------------------
If Not System.IO.Directory.Exists("C:\Users\" & System.Environment.UserName & "\Documents") Then
System.IO.Directory.CreateDirectory("C:\Users\" & System.Environment.UserName & "\Documents\")
End If
------------------------
Does this path exist on Vista? I know it does on win7 regardless of language of the OS.
Also, anyone know if theres a sign I can use instead of C: ? even though its the most common letter for the os hdd it may differ.
-
Oct 29th, 2010, 04:15 PM
#6
Member
Re: Save file, need to determine XP/7
Their is always the non-programmatic OS shortcuts way: http://vlaurie.com/computers2/Articles/environment.htm / http://www.gdgsoft.com/pb/pbhelp/varlist.html
%USERPROFILE%\Desktop
I feel these variables will have more longevity, as they are binded to OS and have been the same for over 10 years and are likely to work 10 years from now. I am fairly certain that the other variables are simply linking to these anyhow =-0
Last edited by intellilogic; Oct 29th, 2010 at 04:22 PM.
-
Oct 29th, 2010, 04:33 PM
#7
Thread Starter
New Member
Re: Save file, need to determine XP/7
I just tried this:
If Not System.IO.Directory.Exists("%USERPROFILE%\test") Then
System.IO.Directory.CreateDirectory("%USERPROFILE%\test")
End If
But nothing. no error and no created folder. Any ideas?
-
Oct 29th, 2010, 04:41 PM
#8
Re: Save file, need to determine XP/7
... Or you guys could just use the Framework to provide the correct path to the user's Documents folder like it's there for you to make things easier.
VS2002/2003:
Environment.GetFolderPath(Environment.SpecialFolders.WhateverFolderYouSeek)
VS2005+:
My.Computer.FileSystem.SpecialDirectories.WhateverFolderYouSeek
Just like Wild Bill has already suggested.
-
Oct 29th, 2010, 04:50 PM
#9
Thread Starter
New Member
Re: Save file, need to determine XP/7
thx solved it:
Private Property userprofile As String
userprofile = Environ("userprofile")
Now I dont need to create a folder just use "userprofile" as the path
-
Oct 29th, 2010, 05:47 PM
#10
Member
Re: Save file, need to determine XP/7
Originally Posted by SlimJim
I just tried this:
If Not System.IO.Directory.Exists("%USERPROFILE%\test") Then
System.IO.Directory.CreateDirectory("%USERPROFILE%\test")
End If
But nothing. no error and no created folder. Any ideas?
Ok, well I guess it's not the best method. Try hitting this folder from the run command: WinKey + R - Paste: %USERPROFILE%\test
%USERPROFILE% is C:\Users\USERNAME\ in Win7, not desktop or Documents and Settings.
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
|