Stories
Slash Boxes
Comments

SoylentNews is people

posted by Fnord666 on Friday March 24 2017, @06:49PM   Printer-friendly [Skip to comment(s)]
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.
(1)
  • (Score: 1, Informative) by ikanreed on Friday March 24 2017, @06:56PM (9 children)

    by ikanreed (3164) on Friday March 24 2017, @06:56PM (#483799) Journal

    That the application's user interface has an explicit export and import for both workspaces and projects, why would you ever trust your OS to do it right?

    And if all you want to do is troll, eclipse will let you install arbitrary python scripts into the engine Window->Preferences->Scripting->Script Locations. If you've got any creativity at all, congratulations, fucking with your coworkers is easy.

    • (Score: 4, Insightful) by jdavidb on Friday March 24 2017, @07:16PM (4 children)

      by jdavidb (5690) on Friday March 24 2017, @07:16PM (#483805) Homepage Journal

      I think to really get the implication of this story, you have to make it about Windows rather than about Eclipse. Windows has a built-in file compression menu option that is broken because it silently excludes files that are important to some applications, Eclipse being one example. I wonder what else it excludes.

      I'm glad I make most of my compressed files on Windows with gzip under Cygwin, or else 7-zip.

      --
      ⓋⒶ☮✝🕊 Secession is the right of all sentient beings
      • (Score: 2) by ikanreed on Friday March 24 2017, @07:19PM

        by ikanreed (3164) on Friday March 24 2017, @07:19PM (#483808) Journal

        horribledisgustinginhumanporn.jpg->7-zip->compress and send to->Boss's wife

        Thanks 7-zip!

      • (Score: 4, Insightful) by driverless on Saturday March 25 2017, @12:40AM (2 children)

        by driverless (4770) on Saturday March 25 2017, @12:40AM (#483958)

        I realise it's fun to bash Microsoft over this, but the complaint is really about Windows not handling very Unix-specific filename conventions properly. The reason why Windows is extra careful, possibly excessively so, about how it deals with dot+suffix is because that's the way it does file typing, and has done for about quarter of a century. This happens to interact badly with Unix' "filenames beginning with a dot are hidden". You could just as easily take it in the other direction, if you zip a hidden (attribute +H under Windows) file and unzip it under Unix, it's no longer hidden. Oh noes! Unix is b0rked!

        The issue of it only storing the first dot+filename directory may well be something to do with how Explorer handles these things. I don't know, but the answer is "don't rely on platform-specific semantics of file naming", not "complain when a platform totally unlike your one does things differently".

        (Just for references, I'm a FreeBSD user, so I have no skin in this game, just trying to inject some balance into the debate).

        • (Score: 2) by jdavidb on Saturday March 25 2017, @01:07AM

          by jdavidb (5690) on Saturday March 25 2017, @01:07AM (#483976) Homepage Journal
          My first computer was an Apple II, and we used the period in filenames just like any other character.
          --
          ⓋⒶ☮✝🕊 Secession is the right of all sentient beings
        • (Score: 0) by Anonymous Coward on Saturday March 25 2017, @09:41AM

          by Anonymous Coward on Saturday March 25 2017, @09:41AM (#484064)
          <quote>This happens to interact badly with Unix' "filenames beginning with a dot are hidden".</quote>
          Not compressing hidden folders by default seems to be in-line with Window's philosophy. So the bug should be that it's compressing the first one ;).
    • (Score: 3, Insightful) by edIII on Friday March 24 2017, @07:16PM (1 child)

      by edIII (791) on Friday March 24 2017, @07:16PM (#483806)

      That, and how is the above a prank? That just sounds like being a dick. Usually a prank on a computer has an "uninstall" feature, while years later, the above has no recourse. What if that was the only copy?

      I came here thinking that somebody had some scripts for Eclipse to mess with a coder in subtle ways like you suggested.

      Did Biff Tannen start coding or something?

      --
      Technically, lunchtime is at any moment. It's just a wave function.
      • (Score: 2) by Jiro on Saturday March 25 2017, @06:36AM

        by Jiro (3176) on Saturday March 25 2017, @06:36AM (#484045)

        He's actually complaining about how Windows mishandles file names. Phrasing it as a fun way of committing a prank is sarcasm; he isn't actually suggesting it would be a good prank.

        In other words, whoosh.

    • (Score: 2) by DannyB on Friday March 24 2017, @07:45PM (1 child)

      by DannyB (5839) Subscriber Badge on Friday March 24 2017, @07:45PM (#483825) Journal

      why would you ever trust your OS to do it right?

      Spoken like a Windows user. :-)

      f***ing with your coworkers is easy.

      #define while if // make code run faster
      #define struct union // use less memory

      --
      You can not have fun on the weak days but you can on the weakened.
      • (Score: 5, Funny) by ikanreed on Friday March 24 2017, @07:48PM

        by ikanreed (3164) on Friday March 24 2017, @07:48PM (#483826) Journal

        Hey, look, the software is going to get the wrong answer either way, so my goal is now to get the wrong answer in the least amount of time.

  • (Score: 3, Touché) by Anonymous Coward on Friday March 24 2017, @07:18PM (1 child)

    by Anonymous Coward on Friday March 24 2017, @07:18PM (#483807)

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

            1. Why would I downgrade from FreeBSD?

    • (Score: 3, Funny) by DannyB on Friday March 24 2017, @08:02PM

      by DannyB (5839) Subscriber Badge on Friday March 24 2017, @08:02PM (#483833) Journal

      2. Output of the "ls" command is too different from the output of DIR.
      3. Eclipse doesn't have a plug in to support QuickBasic.

      --
      You can not have fun on the weak days but you can on the weakened.
  • (Score: 4, Informative) by Nerdfest on Friday March 24 2017, @07:21PM (5 children)

    by Nerdfest (80) on Friday March 24 2017, @07:21PM (#483810)

    Windows hasn't been a superior devlopment platform for a very long time. All the can really clain superiority for is the availability of games and malware.

    • (Score: 4, Informative) by DannyB on Friday March 24 2017, @07:57PM (1 child)

      by DannyB (5839) Subscriber Badge on Friday March 24 2017, @07:57PM (#483831) Journal

      As for Windows and superior development platform, you've no doubt seen that VS Code, when idle, uses 13% cpu time to blink the cursor.

      Kill two birds with one stone. That is a statement of efficiency.

      Inspired, Microsoft created Windows 8. Its new interface kills desktop computing, while its requirement of a keyboard kills tablet computing.

      Then Windows 10 began the downfall of civilization. Or maybe it was the US election. Not sure. Or maybe one is the cause of the other.

      --
      You can not have fun on the weak days but you can on the weakened.
      • (Score: 2) by Gaaark on Friday March 24 2017, @11:52PM

        by Gaaark (41) Subscriber Badge on Friday March 24 2017, @11:52PM (#483924) Journal

        Windows fecks its users, Wasserman-Hillary fecked Bernie: result=Trump.

        Really, i saw it all coming in 1999: that's why I switched to Linux!

        NOW, I'm going to Disneyland! :)

        --
        --- Please remind me if I haven't been civil to you: I'm channeling MDC. ---Gaaark 2.0 ---
    • (Score: 0) by Anonymous Coward on Friday March 24 2017, @08:20PM (1 child)

      by Anonymous Coward on Friday March 24 2017, @08:20PM (#483846)

      Sometimes the games are malware. See SecuROM.

      • (Score: 1) by Scrutinizer on Friday March 24 2017, @10:38PM

        by Scrutinizer (6534) on Friday March 24 2017, @10:38PM (#483901)

        Back in the bad ol' days of SecuROM (Starforce, et al), one of the many wonders of the Internet was roaming groups of software pirates who would crack and remove the copy-protection, thus enabling the consumer to obtain a superior product.

        I'm sure I'm not the only one whose bought-and-paid-for copy of Morrowind would crash constantly, yet the cracked executables [gamecopyworld.eu] enabled hours-long crash free gaming sessions. I wasn't even aware of my keystrokes being logged (hopefully because it didn't happen)!

    • (Score: 4, Insightful) by JoeMerchant on Friday March 24 2017, @08:51PM

      by JoeMerchant (3937) Subscriber Badge on Friday March 24 2017, @08:51PM (#483858)

      Visual Studio still has a strong lead in debugging tools, and, of course, delivery of code to the Windows platforms.

      Personally, I think it's a bloated whale carcass that should be dynamited for entertainment, but when you have as many bugs as Windows developers do, you need a good debugging tool.

      --
      Україна досі не є частиною Росії.
  • (Score: 3, Funny) by nobu_the_bard on Friday March 24 2017, @07:23PM (6 children)

    by nobu_the_bard (6373) on Friday March 24 2017, @07:23PM (#483812)

    There's a lot of ways to create folders that start with periods...

    mkdir .test

    I prefer, for pranks, to use black tape to cover up the laser on all of the mice and see who figures it out and who requests replacements.

    • (Score: 5, Funny) by Azuma Hazuki on Friday March 24 2017, @07:25PM (4 children)

      by Azuma Hazuki (5086) Subscriber Badge on Friday March 24 2017, @07:25PM (#483813) Journal

      Pssh, just plug everyone's mouse into someone else's USB port. Hail Eris!

      --
      I am "that girl" your mother warned you about...
      • (Score: 2) by canopic jug on Friday March 24 2017, @07:48PM (2 children)

        by canopic jug (3949) Subscriber Badge on Friday March 24 2017, @07:48PM (#483827) Journal
        Better if you control the mouse while watching them and their screen and can approximate their movements. If you're good enough you can keep them going for a little while.
        --
        Money is not free speech. Elections should not be auctions.
        • (Score: 0) by Anonymous Coward on Friday March 24 2017, @08:40PM (1 child)

          by Anonymous Coward on Friday March 24 2017, @08:40PM (#483855)

          Meh, too much work.

          At one of the first jobs I worked when I was 16, my boss decided to prank the secretary one day. He installed VNC on her computer and would move the mouse (remotely, from his computer running VNC viewer) when she wasn't moving it.

          • (Score: 2) by el_oscuro on Friday March 24 2017, @10:31PM

            by el_oscuro (1711) on Friday March 24 2017, @10:31PM (#483897)

            Back in the PC Anywhere days, one of my co-workers used to do something like that. Whenever the victim would try to login, he would press an extra character to ensure the password was always wrong.

            --
            SoylentNews is Bacon! [nueskes.com]
      • (Score: 3, Funny) by EvilSS on Friday March 24 2017, @10:17PM

        by EvilSS (1456) Subscriber Badge on Friday March 24 2017, @10:17PM (#483894)
        This is super fun when everyone uses the same brand wireless mice. Just swap the receivers!
    • (Score: 2) by number6 on Saturday March 25 2017, @02:19AM

      by number6 (1831) on Saturday March 25 2017, @02:19AM (#484002) Journal

      using the 'CD' command to create an empty zero-byte file at current directory (note there are two dots in the command):

      cd.>.file

  • (Score: 5, Informative) by tangomargarine on Friday March 24 2017, @07:34PM

    by tangomargarine (667) on Friday March 24 2017, @07:34PM (#483818)

    utility has a mandatory optional feature

    Augh!

    --
    "Is that really true?" "I just spent the last hour telling you to think for yourself! Didn't you hear anything I said?"
  • (Score: 4, Interesting) by bob_super on Friday March 24 2017, @07:41PM (3 children)

    by bob_super (1357) on Friday March 24 2017, @07:41PM (#483821)

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

    People coding FPGA tools which organize IP files for you in neat unnecessarily long directory names containing multiple times the name of the IP.
    They test on Linux and see no issue.
    You test the default project on Windows, and the long paths, now exceeding 260 chars, fail.

    You tell them they are idiots for wasting characters by repeating unnecessary redundant unnecessary repetition.
    They "solve" the problem by packing the whole tree in a zip, to be opened by the tools at runtime.

    Of course, it turns out that you need to modify something, so you need to unzip that directory and get back to the old way, once again breaking all the paths...
    2017, right?

    • (Score: 3, Interesting) by edIII on Friday March 24 2017, @09:15PM (2 children)

      by edIII (791) on Friday March 24 2017, @09:15PM (#483872)

      Whatever stuck-on-stupid gone-full-retard stuff Windows does with filenames is annoying as hell. I once sftp'd a directory from a Linux server (full of porn) that had a file so fucked up, that the file once into a Windows workstation was dead on arrival. Absolutely no part of Windows had a program that could deal with it. It was very long, and also had some characters that Windows refused to deal with period. The entirety of the Windows API, at every level, could not do it. It became a piece of information stuck inside it that caused Windows to fail just trying to list the damn directory. It became a mission to delete that fucking file and directory and it simply could not be done. Not even in safe mode, or with special tools claiming to delete anything.

      Only by using a Linux machine to read the hard drive was I able to finally remove that file and the directory I created.

      Those days taught me that Windows can handle only very short file names, no spaces, no weird characters. When I finally started using Linux the big surprise for me initially was how flexible the file system was WRT file names, and how much Windows sucks at it.

       

      --
      Technically, lunchtime is at any moment. It's just a wave function.
      • (Score: 1) by Arik on Friday March 24 2017, @09:33PM

        by Arik (4543) on Friday March 24 2017, @09:33PM (#483879) Journal
        Yeah you realize once you booted to a sane system you didn't have to delete the file, you could have just renamed it to something Windows wouldn't choke on?

        (Yeah I've had to do this a few times.)
        --
        If laughter is the best medicine, who are the best doctors?
      • (Score: 2) by driverless on Saturday March 25 2017, @12:59AM

        by driverless (4770) on Saturday March 25 2017, @12:59AM (#483970)

        It became a mission to delete that fucking file and directory and it simply could not be done. Not even in safe mode, or with special tools claiming to delete anything.

        Deleting preteen_boys_sodomizing_hamster_gerbil_satanic_sex_orgy_lesbian_dildo_inferno.mpg before you boss sees it would be a priority, I can certainly see that.

        Before you get too hung up about how bad Windows is, check what the Unix command dsw (delete from switches) does, and why it was written. That problem predates Windows by many years. It later turned into the -i command, present for the same reason, and also predating Windows by years.

  • (Score: 0) by Anonymous Coward on Friday March 24 2017, @07:45PM (4 children)

    by Anonymous Coward on Friday March 24 2017, @07:45PM (#483823)

    is another ballache with Windoze, and with the Mac too. Things get real interesting when source control don't get told by the OS that the file "Title" is different than the file "title" or the file "TITLE".

    • (Score: 3, Insightful) by tibman on Friday March 24 2017, @08:00PM

      by tibman (134) Subscriber Badge on Friday March 24 2017, @08:00PM (#483832)

      Moving a project from a non case sensitive OS to a case sensitive one is very painful. IIS will gladly serve up pages while ignoring case. Apache? not so much.

      --
      SN won't survive on lurkers alone. Write comments.
    • (Score: 0) by Anonymous Coward on Saturday March 25 2017, @06:20AM (2 children)

      by Anonymous Coward on Saturday March 25 2017, @06:20AM (#484042)

      > "Title" is different than the file "title" or the file "TITLE".

      But unless you have taken the red pill and only see hex codes, these are all the same word. Capitalization hints at emphasis, its use as a name or title, or the beginning of a sentence. It doesn't change the word itself.

      Case sensitivity is obnoxious for real word end user use. A user may see their file named "Title" right in front of them, but when they type "title" to load it, Unix-ish OSes will stick their nerdy dick noses in the air and say "I can't find that file, I have noooo idea what you are talking about".

      And who in the real world would file "iPhone" after "Zenith"? Nobody.

      I'm sure some jackass will come along and talk about how they help jack off a horse. But "Jack" and "jack" are the same word. In this case the word "jack" is being used as a name (oh, and with punctuation). It is easy to think of it as a new word since you are now thinking of a person instead of a jack or jacking. But capitalizing a word does not create a new word. If I create a paper file in my filing cabinet about how these people don't know jack, I'll title it "Jack". Same word, but now part of a title. Actually, my hand writing sucks so I would probably label it JACK, and any human could find that file if I asked for it.

      • (Score: -1, Troll) by Anonymous Coward on Saturday March 25 2017, @08:16AM

        by Anonymous Coward on Saturday March 25 2017, @08:16AM (#484061)

        Normies oppose men taking cute female children as brides too.

      • (Score: 0) by Anonymous Coward on Monday March 27 2017, @08:44AM

        by Anonymous Coward on Monday March 27 2017, @08:44AM (#484553)

        > But "Jack" and "jack" are the same word.

        But JACK (JACK Audio Connection Kit, i.e. an acronym) and Jack/jack are not the same word. Also, WINE (for running Win32 stuff) is not the same as wine (alcohol stuff). This is true for any "wordy" acronyms).

        /home/user/JACK (source code for JACK)
        /home/user/Jack (files relating to relative Jack)
        /home/user/jack (no explanation needed)

  • (Score: 2) by bob_super on Friday March 24 2017, @07:54PM (7 children)

    by bob_super (1357) on Friday March 24 2017, @07:54PM (#483830)

    Symbolic links have long been source of major schadenfreude in Windows. Not sure if that got finally improved.

    • (Score: 4, Informative) by DannyB on Friday March 24 2017, @08:05PM (6 children)

      by DannyB (5839) Subscriber Badge on Friday March 24 2017, @08:05PM (#483837) Journal

      While I would discourage the use of Windows in the strongest terms, there is this [microsoft.com].

      There are three types of file links supported in the NTFS file system: hard links, junctions, and symbolic links. This topic is an overview of hard links and junctions.

      --
      You can not have fun on the weak days but you can on the weakened.
      • (Score: 2) by bob_super on Friday March 24 2017, @08:45PM (4 children)

        by bob_super (1357) on Friday March 24 2017, @08:45PM (#483856)

        I know they exist, but until XP at least, they were implemented in a quite confusing and dangerous way for those who expect Unix-like behavior.
        I'm assuming/hoping that they fixed that to support the new linux subsystem.

        • (Score: 5, Insightful) by JoeMerchant on Friday March 24 2017, @08:55PM (3 children)

          by JoeMerchant (3937) Subscriber Badge on Friday March 24 2017, @08:55PM (#483860)

          >I'm assuming/hoping that they fixed that to support the new linux subsystem.

          Oh, dear child, don't you know how these things are done? The new Linux subsystem was patched to work with Windows 10 style symlinks. It will continue to work with 97.44% compatibility until such time as they decide to not update the patch to keep up with changes in Windows 10 security implementations.

          Change Windows to support Linux? Do you want a chair thrown at you?

          --
          Україна досі не є частиною Росії.
          • (Score: 5, Funny) by bob_super on Friday March 24 2017, @09:04PM (2 children)

            by bob_super (1357) on Friday March 24 2017, @09:04PM (#483866)

            > Do you want a chair thrown at you?

            Impact in 3 seconds ... 7 minutes ... 15 seconds ... 42 hours ... 1 second ...

            • (Score: 2) by JoeMerchant on Friday March 24 2017, @09:08PM

              by JoeMerchant (3937) Subscriber Badge on Friday March 24 2017, @09:08PM (#483869)

              >Impact in 3 seconds ... 7 minutes ... 15 seconds ... 42 hours ... 1 second ...

              Oh how I miss the days of Disk Defrag....

              --
              Україна досі не є частиною Росії.
            • (Score: 2) by edIII on Friday March 24 2017, @09:17PM

              by edIII (791) on Friday March 24 2017, @09:17PM (#483873)

              This is the funniest thing I have read on SN so far.

              Congratulations :)

              --
              Technically, lunchtime is at any moment. It's just a wave function.
      • (Score: 2) by butthurt on Friday March 24 2017, @11:26PM

        by butthurt (6141) on Friday March 24 2017, @11:26PM (#483915) Journal

        I suppose that .lnk files were a way of achieving a similar effect with a FAT file-system, but have been kept for backwards compatibility.

        https://en.wikipedia.org/wiki/File_shortcut#Microsoft_Windows [wikipedia.org]

  • (Score: 3, Informative) by HyperQuantum on Friday March 24 2017, @09:24PM (1 child)

    by HyperQuantum (2673) on Friday March 24 2017, @09:24PM (#483876)

    Microsoft .NET has an API to get all files in a specified directory that match some search pattern (Directory.GetFiles(String,String) [microsoft.com]).

    If you try to use it, though, you might encounter the following nasty surprise:

    Note:
    Because this method checks against file names with both the 8.3 file name format and the long file name format, a search pattern similar to "*1*.txt" may return unexpected file names. For example, using a search pattern of "*1*.txt" returns "longfilename.txt" because the equivalent 8.3 file name format is "LONGFI~1.TXT".

    • (Score: 2) by Azuma Hazuki on Saturday March 25 2017, @04:25AM

      by Azuma Hazuki (5086) Subscriber Badge on Saturday March 25 2017, @04:25AM (#484025) Journal

      ...that made my soul hurt. I am a worse and sadder person for having read that.

      --
      I am "that girl" your mother warned you about...
  • (Score: 3, Funny) by Anonymous Coward on Friday March 24 2017, @09:32PM (3 children)

    by Anonymous Coward on Friday March 24 2017, @09:32PM (#483877)

    On someones Linux PC or someone who hates Win10, load this webpage and fullscreen it then call the owner over. http://fakeupdate.net/win10u/index.html [fakeupdate.net]

    • (Score: 3, Funny) by Nuke on Friday March 24 2017, @11:54PM (1 child)

      by Nuke (3162) on Friday March 24 2017, @11:54PM (#483926)

      I saw a more alarming version that said "Upgrading to Windows Vista" . Can't find the link now though. Thing to do is go into an Apple store and set this up, full screen, on one of their demo laptops.

    • (Score: 2) by driverless on Saturday March 25 2017, @01:03AM

      by driverless (4770) on Saturday March 25 2017, @01:03AM (#483974)

      That's just pure evil.

      OTOH a more scary one would be 97% complete or something. 0% complete implies you can still quickly pull the plug.

  • (Score: 2) by Valkor on Saturday March 25 2017, @12:13AM

    by Valkor (4253) on Saturday March 25 2017, @12:13AM (#483939)

    Simply not allowing : is enough of a headache for me. I want to include full URLs in to the file or folder name, but no.

  • (Score: 4, Insightful) by SDRefugee on Saturday March 25 2017, @01:09AM

    by SDRefugee (4477) on Saturday March 25 2017, @01:09AM (#483978)

    I get a lot of entertainment from articles like this... After 20 years of using/supporting primarily MS Windows, and towards the end of that 20 years, some Linux also, I decided, when I retired in 2010, I was DONE with MS products, and one day, fired up gparted, and deleted my Win7 partition on both of my main systems, reinitialized Grub, and became MS-less, and after nearly 7 years of avoiding the insanity that is the life of anybody who still uses Windows, esp now with "Windows NSA Edition nee Windows 10"... These stories about the stupidity that is the MS ecosystem and the abuse MS heaps on those who still, for WHATever reason, use their products, provides a great amount of entertainment for me, and I'll bet a lot of other people who have dumped Windows for Linux/Mac/BSDs.....

    --
    America should be proud of Edward Snowden, the hero, whether they know it or not..
  • (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);
    }
    }

    • (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);
        }
      }

(1)