Need some more help with defining "relative paths"

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • mystica
    No longer a forum member
    • May 2007
    • 1548

    Need some more help with defining "relative paths"

    Hi everyone,

    Last week I sought assistance for defining a "relative path" to the Windows "Cookie" folder, and received excellent help from both "arb" and "mwreyf1" (thanks guys) ... whose solutions worked a treat.

    I am now however, seeking further assistance on this issue because although the solutions posed, work well on Windows-XP, they unfortunatley do not work on Windows Vista & older versions of Windows such as Windows'95/'98. This is because the location of the "Cookies" folder is different on those operating sysytems.

    Here's my problem:

    I need to define a 'relative pathway' to the "Cookies" folder, so I can delete a file there (ie. "abc.txt") regardless of the drive on which Windows is installed. On Windows-XP, the "Cookies" folder is located at: Local Drive\Documents and Settings\User\Cookies.

    "Arb" came up with the following solution:
    File.Delete(String.SplitPath(_DesktopFolder).Drive ..String.SplitPath(_DesktopFolder).Folder.."Cookie s\\abc.txt", false, false, false, nil);
    "mwreyf1" came up with an alternate solution:

    File.Delete(os.getenv("USERPROFILE").."\\Cookies\\ abc.txt", false, false, false, nil);
    Now, as I said, both these solutions work a treat on Windows-XP ... but not on Windows Vista, nor on Windows'95/98/ME/NT ... because of the different location of the "Cookies" folder.

    So ideally, what I would like to do, is to use either "arb's" or "mwreyf1's" solution together with a solution that works on Vista & the older versions of Windows. So essentially, what I need is, 'relative pathways' for the following:

    Windows Vista:
    C:\Users\<username>\AppData\Roaming\Microsoft\Wind ows\Cookies\abc.txt
    C:\Users\<username>\AppData\Roaming\Microsoft\Wind ows\Cookies\Low\abc.txt
    AND

    Windows 95/98/ME/NT

    C:\Windows\Cookies\abc.txt
    C:\Windows\Profiles\<username>\Cookies\abc.txt
    Can anyone help me figure this out because it's got me stumped?
  • holtgrewe
    Indigo Rose Customer
    • Jul 2002
    • 779

    #2
    The first thing that comes to mind would be to use System.GetOSName() to determine the proper OS - then use the appropriate path...
    hth

    Comment

    • mystica
      No longer a forum member
      • May 2007
      • 1548

      #3
      Yep thanks, I understand this ... but it's defining the relative paths for the alternate operating systems that I'm having trouble with. That's why I made reference in my last post to the absolute pathways I'm trying to define.
      ie.

      Windows Vista:

      C:\Users\<username>\AppData\Roaming\Microsoft\Wind ows\Cookies\abc.txt
      C:\Users\<username>\AppData\Roaming\Microsoft\Wind ows\Cookies\Low\abc.txt
      AND

      Windows 95/98/ME/NT


      C:\Windows\Cookies\abc.txt
      C:\Windows\Profiles\<username>\Cookies\abc.txt
      The goal is to get my app to work for the user, regardless of BOTH the drive-letter on which they have Windows installed AND the version of Windows they are using. Not such an easy feat as it turns out.
      Last edited by mystica; 07-20-2008, 08:58 PM.

      Comment

      • Ulrich
        Indigo Rose Staff Member
        • Apr 2005
        • 5130

        #4
        Originally posted by mystica View Post
        The goal is to get my app to work for the user, regardless of BOTH the drive-letter on which they have Windows installed AND the version of Windows they are using. Not such an easy feat as it turns out.
        I think that might be complicating things too much here. The information you are looking for is stored in the registry, it is best to read and use what is stored there. You shouldn't code any folder names directly in your application, because Windows installations in other languages than English might have very different folder names than you might expect, or the user might have changed the configuration manually. Although my Windows resides on C:, my temporary files and cookies are in D:\TEMP, for example. So you can't assume anything, but in the registry you can always find the current configuration.

        I just tested this code on Windows 98, Me, 2000, 2003 Server, XP and Vista, and it returns the cookie folder correctly for the current user:
        Code:
        cookiefolder = Registry.GetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "Cookies", true);
        Dialog.Message("Registry", "Your cookies are stored in:\n" .. cookiefolder, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
        Ulrich
        Last edited by Ulrich; 07-20-2008, 10:20 PM.

        Comment

        • mystica
          No longer a forum member
          • May 2007
          • 1548

          #5
          Thanks upeters,

          That was great, you're a genius. I would have never thought of that in a million years. Makes the coding process a whole lot easier too. I'm guessing I can close the chapter on this problem now ... thanks so much!

          Comment

          • RizlaUK
            Indigo Rose Customer
            • May 2006
            • 5552

            #6
            i made a dll a while ago to get the path to all system folders

            Embrace change in your life, you never know, it could all work out for the best

            Comment

            • mystica
              No longer a forum member
              • May 2007
              • 1548

              #7
              Thanks for that, RizlaUK

              Comment

              • mystica
                No longer a forum member
                • May 2007
                • 1548

                #8
                upeters,

                Just getting back to you on the solution you generously provided me with, last week

                ie.
                Code:
                cookiefolder = Registry.GetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "Cookies", true);
                Dialog.Message("Registry", "Your cookies are stored in:\n" .. cookiefolder, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
                For the last week, I've been trying to figure out how to get this to work with the "File.Delete" command, but just can't figure out how to do it. I understand that the "Registry.GetValue" is stored in a variable, but how do I pass this variable into the "File.Delete" command?

                Eg. Again, assuming the cookie-file I want to delete is "abc.txt", how do I code my "File.Delete" line, so it automatically grabs the pathway found by the "Registry.GetValue" command?

                I'm sure this is something very basic that I'm just not getting ... but could you please help me out with this? I've been banging my head against the wall, trying to figure this out on my own.

                Comment

                • Ulrich
                  Indigo Rose Staff Member
                  • Apr 2005
                  • 5130

                  #9
                  You would have to retrieve the name of the cookie folder like I showed you, and then concatenate the folder name with name of the file you want to delete in that folder.

                  In your example, it would be like that:

                  Code:
                  cookiefolder = Registry.GetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "Cookies", true);
                  File.Delete(cookiefolder .. "\\abc.txt", false, true, true);
                  Or doing everything in one pass:

                  Code:
                  File.Delete(Registry.GetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "Cookies", true) .. "\\abc.txt", false, true, true);
                  Ulrich
                  Last edited by Ulrich; 07-31-2008, 08:01 AM.

                  Comment

                  • mwreyf1
                    Indigo Rose Customer
                    • Aug 2004
                    • 417

                    #10
                    This should do it.

                    File.Delete(cookiefolder .. "\\abc.txt", false, false, false, nil);

                    Nevermind ...

                    Comment

                    • mystica
                      No longer a forum member
                      • May 2007
                      • 1548

                      #11
                      upeters & mwreyf1,

                      Ah, I see! Thanks so much, you guys. Legends as usual ... we'd be lost without you!

                      Comment

                      • qwerty
                        Forum Member
                        • Oct 2006
                        • 345

                        #12
                        sorry to dig this one up from the grave...

                        Ulrich's solution, whilst working on my XP 32bit system while testing, just failed miserably on Win7 64bit

                        i'm using HTTP.SubmitSecure with SUBMITWEB_POST to log into somewhere, for the site involved this will either, replace any existing cookie with a new one, create one, or remove all if the wrong details are submitted.

                        I've just watched a video of my app in use, with a cookie already in place, and the folder open, and the cookie remains, but the app fails saying can't find cookie :(

                        I'm using:
                        Code:
                        cookie_error = HTTP.SubmitSecure("https://mywebsiteURL", Login_Details, SUBMITWEB_POST, 20, 443, nil, nil);
                        local http_error = HTTP.GetHTTPErrorInfo();
                        -- Check for Error --
                        if (http_error.Status < 200 or http_error.Status > 299) or cookie_error == "" then
                        
                        blah blah
                        right after the HTTP.SubmitSecure call, but find it is somewhat flakey at returning errors (like if i sumbit the wrong details, the error check totally misses the fact no cookie was created) so i also use..

                        Code:
                        File.Find(Registry.GetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "Cookies", true), "*mywebsite[?].txt", false, true, nil, nil) == nil then
                        this works fine on my system, but blows out completely on Win7 64bit

                        i have asked for a second test with no cookie already in place to see if there is a problem with the HTTP call that is being missed in the error check stages, i might add a 3rd error check using Application.GetLastError.

                        Haven't tested Rislauk's DLL yet... that is my next step, but i dont know if it was ever tested on a 64 bit OS, let alone Win7

                        Anyone got any ideas ?

                        Comment

                        • qwerty
                          Forum Member
                          • Oct 2006
                          • 345

                          #13
                          ok, i switched my code to use RizlaUK's DLL and calling for "33" the cookies folder, and had it tested on a Win7 Ultimate Edition 64 bit system, and it worked a treat.

                          I changed nothing else in my code, just the section that defined the path

                          Nice Work Rizla :yes
                          Last edited by qwerty; 10-07-2009, 07:41 AM.

                          Comment

                          • mystica
                            No longer a forum member
                            • May 2007
                            • 1548

                            #14
                            Hmmm ... interesting stuff, qwerty. Believe it or not, I'm still working on the project for which this query was originally targeted (don't even ask why it's taking so-ooo long!). But anyway, guess I'll be going back over that one with a fine tooth comb. Good 'ol Rizla to the rescue, eh?

                            Comment

                            • qwerty
                              Forum Member
                              • Oct 2006
                              • 345

                              #15
                              yeah, it floored me when the guy testing reported the error and i watched the video of my app in progress.

                              RizlaUK sure helped out here, without that DLL i'd have been taking some weird steps to find the cookies folder probably !

                              Comment

                              Working...
                              X