Stories
Slash Boxes
Comments

SoylentNews is people

posted by Fnord666 on Friday March 24 2017, @06:49PM   Printer-friendly
from the didn't-need-those-folders-anyway dept.

in with a story on Robert Elder Software blog entitled Silently Corrupting an Eclipse Workspace: The Ultimate Prank:

Next time your co-worker asks:

"What's the best way to back up my Eclipse workspace on Windows?"

you can tell them "Just right-click on it and select 'Send to Compressed (zipped) folder' and save the zip file". Unbeknownst to them, you just pulled the ultimate prank by telling them to make a corrupted backup!

          What your friend probably doesn't realize is that the Windows 'Send to Compressed (zipped) folder' utility has a mandatory optional feature to automatically not include certain folders in the archive without telling you. This is a great feature because it demonstrates the excellent sense of humour that the authors of Microsoft Windows have. This feature was no doubt included to allow you to play a variety of hilarious pranks on others by causing them lose data, only to find out about it years later when they want to open the archive and recover it.

The blog post goes on to identify other idiosyncrasies with how Windows mishandles directories whose names start with a period and/or contain Unicode characters.

Reasons you haven't switched to Linux (cont.):

  • 3. Windows has superior development tools.

What other issues have you found with how Windows handles filenames?


Original Submission

 
This discussion has been archived. No new comments can be posted.
Display Options Threshold/Breakthrough Mark All as Read Mark All as Unread
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
  • (Score: 3, Interesting) by number6 on Saturday March 25 2017, @03:57AM (2 children)

    by number6 (1831) on Saturday March 25 2017, @03:57AM (#484023) Journal

    Code:

    /****************************************************************************
      * 'keepopen.c' by Cliff
      *
      * Given the way the Microsoft file systems work I bet you could write a trivial
      * prog to keep a file open with deny-write access. I have had to do this in the
      * past for various reasons.
      *
      * This is a simple command-line program written in C.
      * It has only one argument; a file.
      * After you run it, the file will have "deny-write access"
      * and other processes will not be able to modify it.
      * In other words, we are doing this:
      *    > Just open the file and do nothing with it;
      *    > file can be read but not written to until
      *    > this keepopen.exe process is closed.
      *
      * USAGE:
      *    Simply compile keepopen.c to an executable (keepopen.exe).
      *
      *    AN EXAMPLE:  the command "keepopen.exe C:\Windows\system32\drivers\etc\hosts"
      *    will open your system HOSTS file with deny-write access; you can still
      *    read from it but you won't be able to delete/modify/create a file by the
      *    same name until the handle is closed (i.e. terminate the keepopen.exe process).
      *
      *    NOTE:  Windows file permissions (read-only, system) can always be ignored/overridden
      *    by an admin-level or system-level app, so they are practically useless.
      *    However with 'keepopen.c' you can prevent any admin or system process from doing this.
      ***************************************************************************/

    #include <windows.h>
    main(int, argc, char *argv[])
    {
    HANDLE h;
    if (argc == 2)
    {
    h = CreateFile(
    argv[1],
    (GENERIC_READ | GENERIC_WRITE),
    FILE_SHARE_READ
    NULL,
    OPEN_EXISTING,
    FILE_ATTRIBUTE_NORMAL,
    NULL
    );
    Sleep(INFINITE); // never returns
    Close(h);
    }
    }

    Starting Score:    1  point
    Moderation   +1  
       Interesting=1, Total=1
    Extra 'Interesting' Modifier   0  
    Karma-Bonus Modifier   +1  

    Total Score:   3  
  • (Score: 2) by number6 on Monday March 27 2017, @05:55PM

    by number6 (1831) on Monday March 27 2017, @05:55PM (#484743) Journal
    The code above at Post #484023 does not compile; it has bad errors. I showed it to a friend who knows C Programming and he fixed it for me.

    Below are three variations of this program; all have been tested and compile to an executable..............:

    Fixed version of the code at Post #484023 :

    /*
     * 'keepopen' - original version - displays a blank console window; to kill the program handle
     * you either close the console window or terminate the program.
     */

    #include <windows.h>

    int main(int argc, char *argv[]){
      HANDLE h;
      if (argc == 2){
        h = CreateFile(argv[1],(GENERIC_READ | GENERIC_WRITE),FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
        Sleep(INFINITE); // never returns
        CloseHandle(h);
      }
    }

    'No Console' version :

    /*
     * 'keepopen' - no console version - program persists in background until you manually terminate it.
     */

    #include <windows.h>

    int main(int argc, char *argv[]){
      FreeConsole(); // see https://msdn.microsoft.com/en-us/library/ms683150%28v=vs.85%29.aspx
      HANDLE h;
      if (argc == 2){
        h = CreateFile(argv[1],(GENERIC_READ | GENERIC_WRITE),FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
        Sleep(INFINITE); // never returns
        CloseHandle(h);
      }
    }

    'Console Paused Dialog' version :

    /*
     * 'keepopen' - console paused dialog version - console waits and asks you for input to terminate the process and close.
     */

    #include <windows.h>

    int main(int argc, char *argv[]){
      HANDLE h;
      if (argc == 2){
        h = CreateFile(argv[1],(GENERIC_READ | GENERIC_WRITE),FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
        system("echo Press any key to release the file handle and close this console && pause > nul");
        CloseHandle(h);
      }
    }

  • (Score: 2) by number6 on Wednesday March 29 2017, @05:12AM

    by number6 (1831) on Wednesday March 29 2017, @05:12AM (#485686) Journal
    Here is one more version of 'keepopen.c' , the comments in the code explain everything:

    /*
     * 'keepopen.c' -> version -> No console window; Close the process by pressing a hotkey.
     *
     * In the code below I am using the 'F7' key (VK_F7), but you can change it to something else
     * (see https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731%28v=vs.85%29.aspx).
     * Basically it will keep looping every 100 ms (0% CPU, dont worry, without that limit
     * it would go nuts with CPU). It checks for the 'F7' key press.
     *
     * Compiling this version is a bit trickier... you need to link the 'GetAsyncKeyState' function
     * with the system file 'user32.dll'. This is done in most IDEs (Visual Studio, etc) by calling
     * the file typically located here: /Lib/user32.lib
     * (more info https://msdn.microsoft.com/en-us/library/ms646293%28VS.85%29.aspx).
     *
     * However, I managed to compile this code to an executable by using 'Tiny C Compiler' by Fabrice
     * Bellard (http://www.bellard.org/tcc/) . I placed the file 'keepopen.c' at same location as the
     * compiler 'tcc.exe' , and then ran this command:
     *        tcc -luser32 -o keepopen.exe keepopen.c
     * and the executable was created ...and it worked; pressing F7 did close the process.
     *
     * Note: if you decide to use 'Tiny C Compiler' to make this, then you must also change this line:
     *        #include <windows.h>
     * to this:
     *        #include <winapi/windows.h>
     */

    #include <windows.h>

    int main(int argc, char *argv[]){
      FreeConsole(); // see https://msdn.microsoft.com/en-us/library/ms683150%28v=vs.85%29.aspx
      HANDLE h;
      if (argc == 2){
        h = CreateFile(argv[1],(GENERIC_READ | GENERIC_WRITE),FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
            while (1){
                if (GetAsyncKeyState(VK_F7)){
                    return 0;
                }
                Sleep(100);
            }
        CloseHandle(h);
      }
    }