Results 1 to 10 of 10

Thread: [RESOLVED] Save file, need to determine XP/7

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    5

    Resolved [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

  2. #2
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    5

    Re: Save file, need to determine XP/7

    Not to sound ungrateful but i work with vb .net

    anyways thx

  4. #4
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    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

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    5

    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.

  6. #6
    Member intellilogic's Avatar
    Join Date
    Oct 2010
    Location
    Tyson's Corner, VA
    Posts
    39

    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.

  7. #7

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    5

    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?

  8. #8
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    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.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  9. #9

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    5

    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

  10. #10
    Member intellilogic's Avatar
    Join Date
    Oct 2010
    Location
    Tyson's Corner, VA
    Posts
    39

    Re: Save file, need to determine XP/7

    Quote Originally Posted by SlimJim View Post
    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
  •  



Click Here to Expand Forum to Full Width