text:
Detect MS Windows
Challenge
Create a program that returns a truthy value when run on Microsoft Windows (for simplicity we'll stick with Windows 7, 8.1 and 10) and a falsey value when run on any other operating system (OSX, FreeBSD, Linux).
Rules

Code that fails to run/compile on a platform doesn't count as a falsey value.

Winning criteria
I'm labelling this as code-golf, so lowest score wins, but I'm also very interested in seeing creative solutions to this problem.

Can the programs output by exit code? (normally allowed)

I'm gonna say yes @FlipTack

Can you give a definite list of which operating systems this needs to work on?

is True␤ and False␤ valid outputs?

What should the result be under Windows RT?

Possible duplicate

You may want to specify a few specific non-Windows systems that must be supported. There's some debates in comments about things like DOS and OS2.

We probably need a consensus about what counts as truthy and falsey for exit codes; the normal convention is 0 for true and anything else for false, but many answers are treating it as the opposite, and the "if statement" definition doesn't obviously apply.

Such discrimination... Windows? Shudder :)

English: 1 thought: Are you looking at a Blue Screen Of Death?

WIN32 macros. Its magic!

I wonder if ReactOS gives false positives from some of these answers

This isn't nearly short enough to be competitive, but it certainly uses a unique and imo baffling approach: NodeJS, 43 bytes _=>new Promise(r=>require("fs").fstat(0,r)).

Vim, 2 bytes
<C-a>1

On Windows, <C-a> (ctrl+a) is mapped by default to Select All.  If you type a 1 in select mode in Windows, it replaces the selection with what you typed (1) leaving a 1 in the buffer.
On other operating systems, <C-a> by default is mapped to Increment number.  Because there's no number to increment, it's a no-op, and then the 1 increases the count but in terms of the buffer is a no-op.
1 is truthy in Vim, and an empty string is falsy

Looks like 3 keystrokes. Ctrl+a+1

I think per this meta post http://meta.codegolf.stackexchange.com/questions/8995/how-should-vim-answers-be-scored Vim answers are generally scored without the modifiers (especially given that the first answer on the post uses <ctrl+a> as an example for 1 byte)

@Pavel it's Ctrl + a, 1. If it were Ctrl + a + 1 it'd be counted as 1 keystroke.

Beautiful, I love this answer!

That's rather elegant, I like it.

MATLAB, 4 bytes
ispc

From the documentation:

tf = ispc returns logical 1 (true) if the version of MATLAB® software is for the Microsoft® Windows® platform. Otherwise, it returns logical 0 (false).

There are also the functions ismac and isunix. I'll leave it to the reader to figure out what those functions do. Mego kindly asked for diagrams explaining ismac and isunix so I've tried to illustrate it here:

It was not asked for a diagram of ispc but I can reveal that the behaviour is pretty similar, except substitute OSX and Unix with Windows.

Second approach:
Here's a second approach with getenv using 23 bytes that should be bullet proof, unless there's another operating system starting with W:
x=getenv('OS');x(1)==87

getenv 'name' searches the underlying operating system environment
  list for text of the form name=value, where name is the input
  character vector. If found, MATLAB® returns the character vector
  value. If the specified name cannot be found, an empty matrix is
  returned.

Comments are not for extended discussion; this conversation has been moved to chat.

Python 2.7.10, 24 bytes
import os
0/('['>os.sep)

Thanks to FlipTack for 3 bytes
This program takes advantage of the fact that Windows is the only OS to use \ as a path separator. Normally this is frustrating and bad, but for once it is actually an advantage. On Windows, '['>os.sep is false, and thus 0/0 is computed, causing a ZeroDivisionError and exiting with a non-zero exit code. On non-Windows platforms, '['>os.sep is true, making the expression 0/1, which does nothing, and the program exits with exit code 0.

DOS also uses a backslash as the path separator and it has at least one Python 2 implementation.

@isanae I've edited the title to specify Python 2.7 - the only Python 2 implementation on DOS is an archaic, buggy 2.4.2

OS/2 also uses a backslash and has a Python 2.7 implementation ;)

@isanae The only Python 2 port I see for OS/2 is 2.4.4: https://www.python.org/download/other/

This port is 2.7.5.

@isanae There, I specified 2.7.10. Good luck finding a port of that.

apparently it only needs to give correct results on 3 recent windows versions and presumably similarly recent versios of the three other systems listed, OS2 and DOS don't matter,

I love that 'non-zero exit code' --> truthy value

@Luigi Whoops, I said it backwards. It is a bit odd, honestly, that 0 is truthy in shell contexts, but falsey basically everywhere else. The > could be swapped for a <, and then it will exit with 0 on Windows and non-zero elsewhere.

Would  doing os.sep=="\\" be ok ?  With import, that line adds up to 19 bytes. What do you guys think ?

@Serg That's a snippet, not a function or full program.

@Mego   I'm not saying to use that line alone, of course it needs import.

@Serg That's not the problem. It doesn't utilize one of the acceptable I/O methods. The program I have, for example, outputs via exit code. Previously, I used STDOUT for output.

@Mego ah, I see what you mean

Interesting solution. So all we need is a language which is only implemented for Windows, and then return true.

x86 Assembly, 7 bytes (Inspired by Runemoro's answer)
31 DB 89 D8 40 CD 80

Or
xor ebx, ebx
mov eax, ebx
inc eax
int 0x80

Description
First of all, we'll set eax to 1 (the system call number for exit(int val) for Linux, FreeBSD and OSX).
Then, we'll call the interrupt gate 0x80 which is the system call gate for Linux, FreeBSD and OSX. That would cause the program to exit with status of ebx which is 0 (false).
On Windows int 0x80 is an invalid gate (It uses 2e as a syscall gate) and would crash the program, causing it to end with a positive exit code (true).
Edit: Would not work on OSX since it has a different argument-passing convention on 32 bit (by the stack).
References and further reading

FreeBSD - System Calls: Information about system calls in FreeBSD.
System calls in the Linux kernel. Part 2.:  A great article about Linux's system calls.
Linux Syscall Reference: a system call numbers reference for Linux.
Windows Syscall Shellcode : An article about directly calling system calls in windows from assembly.
Making system calls from Assembly in Mac OS X: An article about system calls on OSX.

That's brilliant!

Why does the crash cases a truthy value? Is it because EAX (typically the return value) is 1? Also, is EAX guaranteed to be 0 at program start? Or do you need xor eax, eax in there?

@ColeJohnson: OS-detected crashes (on the operating systems typically used with x86) never leave an exit code of 0, because that's reserved for successful termination. (Normally the exit code is some wonky value that the OS reserves specifically for this circumstance.) However, I'm not sure it makes sense to count 0 as falsey and 1 as truthy in program exit codes, given that the normal convention is the exact opposite (with 0 being the only truthy vaue, e.g. the standard UNIX/Linux/POSIX program false exits with code 1 whilst true exits with code 0).

@ais523 The relevant answer on the Interpretation of Truthy/Falsey post on meta also states
that 0 is truthy and nonzero is falsy.

This answer implicitly assumes that registers eax and ebx are cleared to zero on program start (on non-Windows), which is not guaranteed if I remember correctly.  It also explicitly assumes that the syscall argument-passing convention for Linux matches that for FreeBSD and OSX, which would be very surprising indeed.

@zwol You're right about the eax and ebx. I'll update the answer. The argument-passing  convention is the same for Linux and FreeBSD  (with linux emulation). However, I could not verify about OSX.  I will fix these problems, thank you for the corrections.

Why not just mov eax, 1 to get rid of the inc call?

@Sebastian-LaurenţiuPlesciuc Good question. mov eax, 1 would be translated to \xB8\x01\x00\x00\x00, which is a lot longer that just moving register and calling inc.

PHP, 22 bytes
`<?=PATH_SEPARATOR>":";`

prints 1 if the path separator is semicolon (colon or empty for all other OSs except for DOS and OS/2), else nothing.
also 22 bytes, but not that safe:
<?=strpos(__FILE__,92);

prints a positive integer if the file path contains a backslash; else nothing.
A safe alternative with 27 bytes: <?=DIRECTORY_SEPARATOR>"/"; prints 1 or nothing.
A strange find: <?=__FILE__[1]==":"; (20 bytes) should be, not safe either, but ok.
But although __FILE__ pretends to be a string (I tried var_dump and gettype), indexing it throws an error, unless you copy it somewhere else (concatenation also works) or use it as a function parameter.
Edit:
<?=(__FILE__)[1]==":"; (also 22 bytes) works in PHP 7; but that´s because the parentheses copy the constant´s value to a temporary variable.
27 bytes: <?=stripos(PHP_OS,win)===0;
tests if predefined PHP_OS constant starts with win (case insensitive; Windows,WIN32,WINNT, but not CYGWIN or Darwin); prints 1 for Windows, else nothing.
17/18 bytes:
<?=strlen("
")-1;

prints 1 if it was stored with Windows linebreak (also on DOS, OS/2 and Atari TOS - although I doubt that anyone ever compiled PHP for TOS), else 0.
You could also check the constant PHP_EOL.
more options:
PHP_SHLIB_SUFFIX is dll on Windows, but not necessarily only there.
php_uname() returns info on the operating system and more; starts with Windows for Windows.
$_SERVER['HTTP_USER_AGENT'] will contain Windows when called in a browser on Windows.
<?=defined(PHP_WINDOWS_VERSION_BUILD); (38 bytes) works in PHP>=5.3
conclusion
The only failsafe way to tell if it´s really Windows, not anything looking like it, seems to be a check on the OS name. For PHP: php_os() may be disabled for security reasons; but PHP_OS will probably always contain the desired info.

File names on *nix can contain backslashes, so this isn't really foolproof. The rules don't say it has to be foolproof, though, so ¯\(ツ)/¯

@Jordan: You´re right. I added that info to the description. Thanks.

An alternative: <?=class_exists(COM);. The class COM is only available under Windows, as far as I know. That should save you one byte.

@IsmaelMiguel That's enough of a different answer for you to post it as such. (However, it may not be worth it to do so; this answer is very well written.)

@wizzwizz4 It isn't worth it. The answer would be pushed to oblivion. That's why I simply left the comment, instead of writting my own answer.

The strlen one won't tell you the OS you're using, only the OS the file was saved on, and even that isn't certain, because Windows editors can save in LF, and non-Windows editors can save in CRLF.

C, 44 43 38 36 bytes
Thanks to @Downgoat for a byte! crossed out 44 is still regular 44
Thanks to @Neil for two bytes!
f(){return
#ifdef WIN32
!
#endif
0;}

Originally I was going to suggest that you can save a bunch of bytes by moving the 0 out of the ifdef and changing the 1 to !, but I think _WIN32+0 works even better still.

If c99 is OK you can change f to main and stick return 1; inside the ifdef and remove the else, since main without return in c99 must return 0.

That's a compiler directive. If it's compiled on a Windows system and run on a Linux system, for example, it will still return 1.

Do you need _ in WIN32? I never added it on my code

@Neil, "Code that fails to run/compile on a platform doesn't count as a falsey value.", it won't compile on a Linux/macOS/etc system (TIO link, click debug).

@Mego ^ (i can't ping you both in a single comment)

@Downgoat _WIN32 is a always defined by the compiler, while WIN32 is set by some project templates in Visual Studio. _WIN32 is more reliable.

@isanae in PPCG, portability isn't an issue. It count if it works in one implementation.

@betseg Ahh, I didn't think about that.

@betseg Sorry, I thought it would be empty or zero for some reason.

My comment about ! still stands though, and saves 2 bytes.

@Neil oooh i got it now. Didn't understand when I first read it.

@MichealJohnson no. I can compile it on linux (using mingw32gcc msvc) snd get code that returns true when run on windows. I don't know of any windows-hosted linux compiler.  if you want to argue emulation layers like "wine" all the other answers probably suffer the same problem

@Jasen My point is, the return value is still set at compilation time not at execution time, so technically it doesn't answer the question.

all the other answers here are also using values set at compile time.

I'm not sure your count is accurate.  It looks like you've got 32 printable ASCII characters plus four line feeds.  A proper Windows text file would, of course, have CR+LF as line separators, so it would be 4 bytes more.  And a proper POSIX text file uses LF as line terminators not separators, so you'd need one more byte for the last LF. ;-)

Not sure if WIN32 is just defined, but is defined to non-zero. If it's the later case, you can just say #if WIN32. On non-windows, since WIN32 is not defined, the preprocessor is required to treat it as 0.

-3 bytes if you replace the first line with f(x){x=.

Befunge-98, 7 bytes
6y2%!.@

Try it online!
This works by querying the system path separator, which is \ on Windows and / on other operating systems.
6y            System information query: #6 returns the path separator.
  2%          Test the low bit - this will be 1 for '/' and 0 for '\'.
    !         Not the value, so it becomes 0 for '/' and 1 for '\'.
     .@       Output the result and exit.

Mathematica, 28 bytes
$OperatingSystem=="Windows"&

What's the point in making it a function? You could remove the ampersand saving one byte, and the code would just directly evaluate whether it's executed is on a Windows-ish system.

@Ruslan All answers must be either full programs that print the result or callable functions. If this is declared a Mathematica notebook answer, then you might get away with calling it a full program, but if I invoke the thing from the command-line without the &, it won't print anything (and it's then also not a callable function, but merely a snippet/expression).

@MartinEnder Really no output? I get Out[1]= False output from this: ~/opt/Mathematica/11.0/Executables/math <<< '$OperatingSystem=="Windows"'

@Ruslan I believe that also starts a notebook environment (just a command-line based one). What I mean by running a program from the command-line is using script mode.

Java 8, 33 bytes
Special thanks to Olivier Grégoire for suggesting separatorChar, and Kritixi Lithos for -1 byte!
This is a lambda expression which returns a boolean. This can be assigned to Supplier<Boolean> f = ...; and called with f.get().
()->java.io.File.separatorChar>90

Try it online! - the server isn't windows, so this prints false. However, in my windows machine, the same code prints true.
What this code does is get the System's file seperator, and check whether its codepoint is larger than the character [. This true for Windows, as it uses \ as the seperator - but every other OS uses /, which has a lower code in the ASCII table.

Won't this break on other OSes which start with W?

()->java.io.File.separatorChar=='\\' is only 36 bytes.

@OlivierGrégoire nice one - and I can golf it to 34 using ()->java.io.File.separatorChar>'['!

I think you can golf this using >90 instead of >'[' https://tio.run/nexus/java-openjdk#LY0xC8IwEEbn5lfcmA4GVykWiuDm1FEcrjXWkzQJl2tBpL@9Buv68d77eocpwQXJf1SRBIV6IC@WH9hbaCCvAF0IzqIHnrwuK1UsShVx6lxm/8oc6A5jruhWmPxwvSEPqdz0BhCOsOpyV79wRkPBnMlZk2xERgl8eiLXh321Zrh9J7GjCZOYmEvivEbzO96el/UL

@KritixiLithos thanks, don't know why I didn't remember that...

@FlipTack I'm not very familiar with Java's lambdas, but don't you have to include the semicolon at the end?

@KritixiLithos This expression itself is a literal (function literals are allowed), just like 1. When assigning it to a variable, the assignment is a statement and therefore requires the semicolon, like int i = 1; - but the lambda itself doesn't need the semicolon.

@Downgoat: Is there any other OS that starts with W?

@Titus WebOS, Whonix. Probably even more.

@Titus Wait, what about WAITS?

R, 15 bytes
.Platform$O>"v"

Thanks to plannapus for the suggestion to use partial matching for list element extraction.
.Platform is a list with some details of the platform under which R was built. There is an element OS.type (the only element with name starting with "O") which is character string, giving the Operating System (family) of the computer. One of "unix" or "windows".
So "unix" is less then "v", but "windows" is greater then "v". Other valid 15 bytes answers are
.Platform$O>"V"
.Platform$O>"w"
.Platform$O>"W"

R is being developed for the Unix-like, Windows and Mac families of operating systems. Other OS families are not supported.

there are platforms other than unix that aren't windows you know...

@muddyfish: .Platform[[1]] is defined as either "unix" or "windows" in R documentation. https://github.com/wch/r-source/blob/af7f52f70101960861e5d995d3a4bec010bc89e6/src/library/base/man/Platform.Rd#L22

Sorry, that's ok then. The answer should probably be modified to include this fact to stop that being asked again

J, 7 bytes
6=9!:12

This is a verb (similar to a function) that uses the builtin foreign conjunction 9!:12 to acquire the system type where 5 is Unix and 6 is Windows32.

J Official documentation shows it returns this value for older Windows. "6 Windows32 (95/98/2000/NT)"  Does the documentation need to be updated?  What happens when it is 64 bit Windows? http://jsoftware.com/help/dictionary/dx009.htm

Tested on 64 bit Windows 7 and it returns a 6.  Documentation seems to be quite old.

@Keeta Yes I think it is old but it still returned a 6 for me on Windows 10 64 bit.

5 bytes: IFWIN
source

Perl, 11 bytes
print$^O=~MS

^O should be replaced by a literal Control-O.
Outputs 1 on windows, nothing on another OS.
Note that I'm not using say as it adds a trailing newline, which is truthy in Perl.
-2 bytes thanks to primo. (and fixed potential issues)
-1 bytes thanks to ais523.

AFAIR this won't work in Cygwin Perl.

This won't work in mingw Perl either. Perl treats those both as distinct operating systems from Windows, though (as they generally obey UNIX rather than Windows conventions), and it's not clear whether they should count for the purpose of the question. In other news, you can save a byte here by using a literal control-O character rather than ^O.

@ais523 I edited that, thanks. As for Cygwin and Mingw, I'll delete the post if they should be considered as Windows, but as you say, it would make more sense to consider them like separate OS (or at least, like not-Windows OS).

Regex delimiters shouldn't be necessary $^O=~W, although, I would probably match against MS. Alternatively, you could also match $^X=~':'.

@primo right, thanks. I don't know any other OS with a W in it so I assumed checking for a W for fine.. any reasons why you suggest MS instead?

@Dada less likely to hit a false positive: Cygwin and Mingw have both already been mentioned.

x86 machine code, 9 bytes
40 39 04 24 75 02 CD 80 C3

Compiled from:
inc eax        ; set eax to 1
cmp [esp], eax ; check if [esp] == 1 (linux)
jne windows    ; jump over "int 0x80" if on windows
int 0x80       ; exit with exit code 0 (ebx)
windows:
ret            ; exit with exit code 1 (eax)

pure binary (COM) won't run on Windows or Linux so not sure if this is valid

@IgorSkochinsky There must be an interpreter for assembly.

You can make the code even shorter by leaving only inc eax and int 0x80, I think it should fail on windows and terminate the process.

@ShmuelH. We aren't allowed to do that: "Code that fails to run/compile on a platform doesn't count as a falsey value."

@Runemoro You're right. However, this is a true value (on windows, the program would end with positive status code; status code is allowed, see the first comment).

Well, surely you can assemble and  link  it into a valid executable for the platform (ELF or PE) but then you'd have to count either the executable size with all the headers or the source code size.

@IgorSkochinsky, No, just like you can run python (with an interpreter), there are programs that run assembly (see here)

I'm not aware of any such, but even if they exist you still have to count the source code, not raw binary.

The exit code is set to non-zero, but you get a dialog saying "program.exe has stopped working" first, so I'm not sure if that's ok.

@IgorSkochinsky There are programs that run raw binary too. See the link in my previous comment.

Technically, this answer checks for the Linux Kernel (afaics). If I run GNU/Hurd (just like GNU/Linux, but using a different kernel) and compile this program for it, it would say that it was Windows. Equally if I ran this on my x86 smart TV it would say that it was Windows. (Both untested, feel free to prove me wrong!)

Bochs and QEMU simulate bare metal environment and do not run the binary code under the host OS. So they won't work IMO. But this all could be a discussion for the meta.

julia, 10 bytes
is_windows

A function that returns true for windows

This corresponds to Sys.iswindows() in modern Julia

C#, 61 48 bytes
()=>(int)System.Environment.OSVersion.Platform<4

Saved 13 bytes thanks to TheLethalCoder
Or a full program at 83 bytes:
class P{static int Main(){return(int)System.Environment.OSVersion.Platform<4?1:0;}}

Various Windows variants use enum values 0 to 3 in the Microsoft .NET implementation. 4 is Unix, 5 is Xbox [360] (which I won't consider "Windows"), 6 is MacOSX. Mono uses the same values, adding 128 for Unix/Linux in earlier versions.
Therefore, anything < 4 is Windows, and everything else is not Windows.

Not sure if I'm missing something, but why are you casting the value to an int?

@auhmaan CS0019 Operator '<' cannot be applied to operands of type 'PlatformID' and 'int' -- basically, C#'s typing rules says I can't compare a PlatformID and int directly, and there's no implicit cast from PlatformID to int. But there is an explicit cast from all enums to their values, which I take advantage of here...

Depends on which xbox you're running this on. XBox ONE runs on Windows 10 therefore correct answer should be returning true.

@MustafaAKTAŞ According to documentation, Xbox explicitly means "The development platform is Xbox 360.". Also, arguably, by including WinCE I'm already going beyond the scope of the question (which is presumably traditional computers only). IMO, and lacking further clarification from the question author, I will assume "Windows" does not include, say, "Windows Phone".

@MustafaAKTAŞ Also, I have to point out that this is targeting C#/.NET Framework/.NET Core. On Xbox One it's only possible to run UWP apps, which use a different API not including System.Environment.OSVersion at all. If you're going to take issue with that, then you should also delete every other non-UWP answer. It also turns out that you can't (currently) run UWP apps on non-Windows platforms, so you can go delete all those too. Which leaves you with 0 answers, and an unanswerable question.

You can compile to an Action<bool> in the first example for 48 bytes (I haven't tested it but believe it will work) _=>(int)System.Environment.OSVersion.Platform<4; It might need to be ()=>... for 49 bytes though

@TheLethalCoder Hm, is that allowed? Without a (implicit or explicit) cast to Action<bool>, it's not really a delegate yet... not sure how acceptable that is on PCCG.

Compiling to anonymous functions such as Funcs and Actions are used all the time here. I believe it's in the golfing tips page and I use them almost all the time. Also anonymous functions are used in other languages a lot so I think it is safe to use them here

Although if the statement specifies you must write a full-program then obviously Actions and Funcs aren't going to help you. But this challenge just says program and I believe that means you can use an anonymous method (although I may be wrong on that). Though some other answers appear to be using anonymous functions/methods.

@TheLethalCoder Ah, ok. Thanks! I do think it needs to be ()=> because _=> takes a param. Also, Func<bool> in this case, but apparently that's not part of the function, so... still 48 bytes assuming the semicolon isn't required (it's not part of the anon function, technically).

I usually include the semi-colon, same as if it was multiline I'd include the braces {}. And the challenge doesn't state if you aren't allowed to take input so you could compile to a Func<int, bool> and you just don't use the int you pass in. Again still 48 bytes

JavaScript, 42 30 26 25 bytes

console.log((
//Begin
_=>navigator.oscpu[0]>'V'
//End
)())

Tested with Firefox. (Chrome doesn't have the oscpu property.)
Since lowercase letters have a higher character code than uppercase letters, this depends on the first letter of navigator.oscpu being uppercase and not being W, X, Y or Z on any platform that Firefox supports (other than Windows, of course). According to this post, that is the case.
Edits

Saved 12 bytes thanks to Neil.
Saved another four bytes
Saved another byte thanks to Blender.

oscpu is probably the shortest navigator property that you can use. Also, testing a regexp will probably work out shorter, but I haven't measured it.

You can remove !=-1 and add a ~ right after the fat arrow, saving 3 bytes.

Do you have to create a function? Can't you just console.log the regex test? Also would navigator.oscpu[0]=='W' work or is there another OS that also starts with W.

Hmm, for some reason my Chrome doesn't have oscpu.

If it wasn't for WebTV OS, I would suggest navigator.platform[0]=='W' as a more robust alternative.

navigator.oscpu>'V' might work as well

navigator.oscpu>'V' could produce a false positive on some *nix systems, which derive navigator.oscpu from the output of uname. Examples

Batch, 50 bytes
@if %OS%==Windows_NT if not exist Z:\bin\sh echo 1

Edit: Fixed to ignore DOS instead of claiming that it's Windows.
The only other way I know of running Batch outside of Windows is to use WINE which by default will map Z: to /. Therefore if Z:\bin\sh exists, chances are that it's /bin/sh, so not MS Windows.
I don't know what WINE sets %OS% to, but if it's not Windows_NT then I could save 23 bytes.

Another way is DOS, which is not Windows.

Not only does this fail under DOS, but also, on a computer where Z: is mapped, and happens to contain such a path.

This doesn't work if cygwin is install to the root of drive Z:

At least I'm trying to detect WINE. None of the other answers will give the correct result when run under WINE either.

DOS: set OS=Windows_NT & subst Z: C:\ & mkdir Z:\bin & echo X > Z:\bin\sh.

@Adám Sure and if you compile the C answer with -DWIN32=1 then it fails too. Your point?

yes, wine sets OS=Windows_NT

Doesn't work under MS-DOS 6.22 -- it fails with a syntax error.

there can be hybrid scripts like this

@Mark Strange, it worked for me when I tried it.

@Neil, are you trying with actual MS-DOS, or with a Windows command prompt?

@Mark I have an MS-DOS 6.22 VM.

Node.js, 27 16 15 13 bytes
Thanks to @Patrick, who shaved 12 bytes off my solution using Node's REPL:
_=>os.EOL>`
`

Original solution:
_=>require('path').sep!='/'

If you change this to Node.js REPL, you can save 16 bytes by just using _=>path.sep!='/'

I'm new to codegolf. Am I allowed to do that?

Yes, otherwise I wouldn't have suggested it. REPL means read, execute, print loop, the program that runs when you enter node on the console. From there, all the system node modules are available without the need to require() them.

Oh yeah sorry. I meant 11. You can save another byte by changing != to > since the ASCII index for \  is 92 and / is 47.

Excel VBA, 41 40 30 29 26 24 Bytes
Immediate windows function that returns true if the system's OS code starts is longer than length 3, because the info is restricted to output either else mac or pcdos this returns true only on windows pcs
?[Len(Info("SYSTEM"))>3]

Previous Versions
''# Ignore the second `"` that follows every `\` - its only there for highlighting

?Left(Environ("OS"),1)="W"                 # 24 Bytes

?InStr(ThisWorkbook.Path,"\"")             # 29 Bytes

?Mid(ThisWorkbook.Path,3,1)="\""           # 30 Bytes, Restricted to local Files

?Application.PathSeparator="\""            # 30 Bytes

?Left(Application.OperatingSystem,1)="W"   # 40 Bytes

Changes
-1 Thanks to Neil for using Left(...,1) over Mid(...,1,1)
-10 Thanks to ChrisH for pointing out @Mego's Path Separator Trick
-1 For Checking the WorkbookPath for "\"  rather than using Application.Path Separator
-4 For switching to Environ()
-2 For switching to [Len(Info(...
Novel Solution, 51 bytes
Novel subroutine that outputs, to the VBE immediates window, a 1 (truthy) under windows and 0 (falsey) under mac by method of conditional compilation.
Sub a
i=1
#If Mac Then
i=0
#End If
Debug.?i
End Sub

left saves you a byte.

Have you tried it on office365 online? Does that even support VBA? Just curious.

@ChrisH To my knowledge office.com does not support online VBA scripting (though if anyone else knows better please do tell me, that would make my life significantly easier); However, with O365 you have the rights to download a copy of Office 2016 (or whatever is current) to your desktop, and that does support VBA scripting.

I've so far manage to avoid it; given your comment that looks set to continue (the only windows machines I use have a desktop copy of office, personal machines are all linux)

@Mego's path separator trick (?Application.PathSeparator)="\" would be 32 as it's a single char)

QBasic, 31 bytes
?INSTR(ENVIRON$("COMSPEC"),"W")

Prints non-zero under Windows, 0 under everything else.
COMSPEC is an environment variable unique to Microsoft OSs.  It points to the command interpreter, typically command.com or cmd.exe.  Under Windows, the command interpreter sits somewhere in the Windows directory; under MS-DOS, it sits in the DOS directory or on the root of the disk, and under any other OS, it doesn't exist.
By checking to see if the value of COMSPEC contains a "W", we can tell the difference between Windows and not-Windows.

COMSPEC isn't reserved to mean anything in particular under Linux (meaning it's under user control by default), so isn't it possible that the user's set it to a value that they're using for their own purposes (and happens to contain a W)? Admittedly, that's a bit of an edge case.

@ais523: Also, the Windows directory doesn't have to contain a W. It's brittle in either case.

Perl 6,  19  18 bytes
put $*DISTRO.is-win

put ?($*CWD~~/\\/)

Both output True␤ or False␤ depending on the system it is run on.

the second one relies on the non windows values of CWD not containing any \ - there's no guarantee of that,

bash + coreutils, 5 bytes
rm $0

Also works in most other POSIXy shells. (Note that Windows ports of bash and rm exist; even though they're only normally used with more heavily POSIXy operating systems, this isn't an entirely vacuous entry.) Outputs via exit code (0 = false, 1 = true). Can be counted as 4 bytes if you're allowed to assume a filename (e.g. rm a). Note that this can potentially fail in the case of very weird filenames (which rm will interpret as arguments due to the lack of quoting, and possibly delete files you care about, so I'd advise against running this program from a file with a weird name).
Note: deletes the program from disk as a side effect, or at least tries to. In the case where we're running on Windows, the OS will fail to delete the running file (an operation that Windows disallows either by default or full stop), and thus rm will error out. bash catches the error and converts it into an exit code (thus the program as a whole terminates normally). Most of the other entries here are using 0 for falsey and 1 for truthy in exit codes, so this does the same; note that bash's if statement doesn't accept integers at all (rather, it accepts commands and branches based on whether they run successfully, and arithmetic tests are done via the means of programs like test that intentionally report a "crash" on a failed comparison), so this is on shakier ground in terms of legality than programs that output via exit code in languages where 0 is valid in an if statement test and sends the program to the else branch.

APL (Dyalog), 21 bytes
'W'∊∊#⎕WG'APLVersion'

Try it online!
#⎕WG'APLVersion' Root (#) Window Get property APL Version
∊ enlist (flatten)
'W'∊ is W a member? (no non-Windows return values contain a capital W)

TrumpScript, 17 bytes
America is great.

Try it online!

This program, if run on windows, will print:
The big problem this country has is being PC

This is considered a truthy value.

Empty output and the following value are falsy:
Boycott all Apple products  until such time as Apple gives cellphone info to authorities regarding radical Islamic terrorist couple from Cal

The empty output will occur on any linux system (for this program), the long apple response obviously occurs on Mac (for any program). On TIO, the backend (I'm assuming) is a Unix operating system, so you can only get the falsy value; on my computer I get the PC message.

Not 100% sure if this counts as an error message (which would invalidate the answer), but if you didn't know about this it was probably worth a laugh for you.

What has the world come to...

@avaragecoder MAKE PYTHON GREAT AGAIN!

Haskell, 39 31 bytes
import System.Info
f=os!!0=='m'

I check for the first letter output of "m", which should be "mingw" for windows. As far as I could tell, there is no other OS which starts with M. The information comes from https://github.com/ghc/ghc/blob/master/compiler/utils/Platform.hs

On my system (Windows 10 64-bit, GHC 8.0.1 64-bit), os gives "mingw32".

@Mego you are right, corrected for that

tcl, 38 bytes
 expr [lsearch $tcl_platform windows]>0

PHP 17 Bytes
The following will output 1 if windows and nothing if anything else. Ignoring notices of string convertion.
<?=PHP_OS==WINNT;
Try online Online tests for linux because the sandbox is linux for PoC.

Sure that is enough? Asking because Possible Values For: PHP_OS.

'<?=PHP_OS[0]==W;is both 1 byte shorter and catches all the other windows values in the question linked by manatwork.>V` might work too.

manatwork depends on which windows version PHP was compiled on, since Windows Visa\7, Windows version has been represented with WINNT because of the NT Authority Kernel.
before windows XP and below was WIN32 and Windows server 2003 was Windows.

8th, 11 bytes

os 1- not .

Prints true on Windows, false on Linux and macOS. Other platforms supported by 8th are Android, iOS and Raspberry Pi, but I am not able to test on them.
Ungolfed version (with comments)

G:os  \ Return a number n indicating the operating system
      \ 0 for Linux
      \ 1 for Windows
      \ 2 for macOS
      \ 3 for Android
      \ 4 for iOS
      \ 5 for Raspberry Pi
n:1-  \ Subtract 1
G:not \ If Windows --> true, otherwise --> false
.     \ Print result

Java 8, 49 bytes
()->System.getenv().get("OS").contains("Windows")

Longer than the other Java answer, but takes a different approach.
This lambda fits in a Supplier<Boolean> and can be tested with the following program:
public class DetectMSWindows {

  public static void main(String[] args) {
    System.out.println(f(() -> System.getenv().get("OS").contains("Windows")));
  }

  private static boolean f(java.util.function.Supplier<Boolean> s) {
    return s.get();
  }

}

It's very, very similar to the initial answer that you link (before the edits).

Why not just .contains("W")?

@Cyoce actually, the variable OS appears to be Windows-specific.

Python 3 (13 bytes)
import winreg

Returns with exit code zero (generally true in shells) if on windows, and with a non-zero exit code otherwise.
If you prefer it the other way round, there is a 12 bytes solution: import posix.

I think this will not work if there is a file called winreg.py in the same directory.

Also, per the rules: "Code that fails to run/compile on a platform doesn't count as a falsey value."

Powershell 6, 10 bytes
$isWindows

Powershell 6 intoduce 3 predefined variables: $isWindows, $isLinux and $IsMacOs.

FPC, 61 chars
begin{$ifdef win32}write('f');{$else}write('nf');{$endif}end;

you can shave some bytes by using only one write begin write({$ifdef win32}1{$else}0{$endif});end.

Or to work on win64 as well: begin write({$ifdef windows}1{$else}0{$endif})end.

@hdrz, yes, you right, thanks ;)

@hdrz, sure that would be correct? 1 and 0 are not truthy/falsey in Pascal. I would go with begin write(1={$ifdef windows}1{$endif}+0)end.

@manatwork, FPC and Delphi supports various types in writeln.
And boolean is can be only 0 or 1 in pascal

@manatwork - well i'm streching the rules a bit here... anyhow i like your solution much better than mine

@hdrz, yes, but you left ;.

You seem to have created a second account with the same name. If that wasn't on purpose, you can follow the steps in I accidentally created two accounts; how do I merge them?

@Dennis, no, i'm post first and the same answer by unlogged nick.
My first account is monobogdan, but it's blocked by system because haters downvote some posts

IBM/Lotus Notes Formula Language, 22 21 bytes
@Like(@Platform;"W%")

Previous versions:
@Left(@Platform;1)="W"

or
@Begins(@Platform;"W")

Computed field formula on a Notes form. @Platform returns 1 of:
AIX/64
Linux/64
Macintosh
OS/400®
UNIX
Windows/32
Windows/64

So the formula returns 1 (@True) if the platform starts with "W" and 0 (@False) if not.

Lua, 21 Bytes
os.execute"dir c:\\"

It will error if not on windows and list the C:\ directory if on windows.

Welcome to Programming Puzzles and Code Golf!

Debian has a /bin/dir that seems almost identical to /bin/ls.  If I do mkdir C:\\ I can fool this script.

LibreOffice Calc / OpenOffice Calc, 21 bytes
Code:
=INFO("system")="WNT"

Microsoft Excel, 23 bytes
Code:
=INFO("system")="pcdos"

Result:
Returns TRUE if Windows; FALSE otherwise.

C (gcc), x64 only, 37 bytes
asm("m:_m:.int 50066");f(){m(2,1,0);}

Try it online!
Function called f(). Returns 1 for Windows, 0 for non-Windows.
You wanted a "creative solution"? Here you go. Unfortunately, it isn't as short or portable as the other C solution. (TODO: x86, ARM, and ARM64 polyglot /s)
Expanded:
// ASM
// We need both m and _m because macOS uses leading underscores for
// C symbols, while Windows and Linux do not.
m:
_m:
        // We manually encode these in the golfed code to save space.
        // eax = edx
        xchg    eax, edx // 0x92
        ret              // 0xC3
// C
int m(int, int, int);
int f()
{
    // The first parameter can be anything, I use 2 for ease of explanation.
    return m(2, 1, 0);
}

What does it do? It uses the fact that Windows and Linux (and Mac, BSD, etc) use different calling conventions on x64.
So, when GCC tries to call m(2, 1, 0), on Windows it will use the Microsoft x64 calling convention (rcx, rdx, r8, r9):
    mov     ecx, 2
    mov     edx, 1
    mov     r8d, 0
    call    m
However, on Linux, Mac, BSD, etc, it will use the System V calling convention (rdi, rsi, rdx, rcx, r8, r9):
    mov     edi, 2
    mov     esi, 1
    mov     edx, 0
    call    m
As I have bolded, edx is used on both platforms, but since they represent different parameters in the calling conventions, Windows and non-Windows will get different values.
With some inline assembly, we can get GCC to return the value of edx instead of the third parameter.
To test how it would function on Windows, simply uncomment the prototype at the top, which uses an attribute to force GCC to use the Microsoft ABI.

I thought Windows was the one that prefixes C symbol names with underscore, or do I mis-remember?

tcl, 51
puts [string match windows $tcl_platform(platform)]

I don't have a Windows machine online, but on http://rextester.com/live/OVTY1488 replace windows by unix to see it output 1 instead of 0.
2nd attempt:
tcl, 40
puts [string match W* $tcl_platform(os)]

assuming Windows is the only system the name begins on a W.

3rd attempt:
tcl, 26
puts [info exists env(OS)]

assuming Windows is the only system the OS environment variable is defined.

Ruby, 38 bytes
Stealing the code from here:
exit (RUBY_PLATFORM=~/(?<!r)win/)!=nil

Return 0 on OK, to keep with shell conventions. We need the funny (?<!r) negative look-behind to avoid matching darwin, although if Microsoft device to make a vrwin Windows version for virtual reality the code will fail... On JRuby, though, this doesn't work so well, so instead:
Ruby including JRuby, 52 bytes
exit (RbConfig::CONFIG['host_os']=~/(?<!r)win/)!=nil

I don't have raw Windows, just Cygwin, but if the host_os is windows then we need to distinguish nil and 0.
Ruby plus gem install os, 25 (+9?)
This needs an extra gem, so we might have to add an extra 9 bytes for gem i os at the command line:
require 'os'
exit OS.windows?

This also avoids the darwin problem completely!

According to other answer in the question you linked to, your code will reach the conclusion that “darwin” is also “win”. If the question not requires otherwise, by default the answers are expected to be either full programs or functions (or whatever callable entities exist in your language), which should return or output the result explicitly or rely on the interpreter doing it implicitly. As it looks now, your code is a snippet, leaving the generated value in the memory.

Oops! Filtering out darwin makes things lengthier. And let me add an exit...

PHP, 18 bytes
<?=!(PHP_EOL^'=');

Explanation
PHP_EOL, as its name might suggest, returns the line separator on a given system. On Windows, this is CRLF, and on other platforms, this is LF.
^ is binary XOR. '=' XOR "\r" is '0', and PHP's string bitwise operations truncate to the length of the shortest string, so "\r\n" XOR '=' is also '0'.
! is boolean NOT. In PHP, "0" is considered falsy. So, when we're on Windows, PHP will negate this to true. When we're not on Windows, we get a truthy value ('7') which PHP negates to false.
<?= is the short opening tag for echo.

Ruby 2, 17 14 bytes
17 byte solution: Gem.win_platform?
This only works on the newer versions of ruby, as in the older versions you would have to require rubygems.

14 byte solution: system 'del a' This command outputs true if on windows, because there is a command called del in Windows, but outputs nil (falsey) on Linux and Mac because there is no such command as del in Unix. Oh, and if you are on windows it will delete a file called a in your current directory, that's an unintended side effect :P

Python 3, 29 bytes
import os;exit(os.name!='nt')

Probably should have tryed that first....
Previous answer (41 bytes)
Two answers I found that are the same size
import os;exit(-hasattr(os,"P_DETACH")+1)

and
import sys;exit(-hasattr(sys,"winver")+1)

also -+1 is a neat way to negate the output, gonna keep that one noted

-n+1 <-> 1-n?

@JonathanFrech true, although I found even more savings by not being fancy :(

-2 bytes by using os.name>'o' (linux and mac is posix, while windows is nt)

Elixir, 19 bytes
{:win32,_}=:os.type

Exit code 0 for Windows, 1 for others.

Scala, 71 bytes
object W extends App{print(sys.env.get("OS").get.contains("Windows"))}

Dartlang, 43 bytes
import'dart:io';main()=>Platform.isWindows;

First answer one here, so I hope this is okay :)

D, 43 bytes
int f(){version(Windows)return 0;return 1;}

D ... is horrible at golfing. But it does have a version construct, so I thought I'd post an answer in D.
And ... there's really no point in putting a TIO link, since TIO is ran on only one type of OS.

SQL 2017, 61 bytes
SELECT IIF(host_platform='Linux',0,1)FROM sys.dm_os_host_info

SQL 2017 is the first MS SQL version that can run on a platform other than Windows. The  system view sys.dm_os_host_info returns either Linux or Windows, so (at least in this version) anything that isn't on Linux is on Windows.

Nice solution!!

Rust, 14 bytes
||!cfg!(unix);

The target_family attribute is windows on Windows and (most) others have unix.

05AB1E, 26 19 bytes
'ª¬7£’ÿ :ï´.ƒª’.E2å

Try it online!
'ª¬7£’...’.E2å  # trimmed program
             å  # is...
            2   # literal...
             å  # in...
          .E    # result of running...
     ’...’      # "ÿ :os.type"...
                # (implicit) with ÿ replaced by...
    £           # first...
   7            # literal...
    £           # characters of...
'ª¬             # "inspection"...
          .E    # as Elixir code...
             å  # ?
                # implicit output

=================================================

inspect :os.type  # full program
        :os.type  # return tuple of OS family and OS name...
inspect           # as a string

:os.type return values:

Family
Names

unix
A result from running uname -s. No Unix kernels have 2 in their name, so if the machine is running Unix, the program will return 0.

win32
nt or windows

05AB1E (legacy), 21 bytes
’__£Ø__('ï´').ˆ³’.EÇÈ

Try it online!
’...’.EÇÈ  # trimmed program
        È  # push 1 minus...
       Ç   # codepoint of...
     .E    # result of running...
’...’      # "__import__('os').sep"...
     .E    # as python code...
        È  # modulo 2
           # implicit output

=================================================

__import__('os').sep  # full program
__import__(    )      # return...
           'os'       # operating system...
                .sep  # file path separator

Julia 0.6, 8 bytes
!is_unix

Try it online!
Julia 1.0, 11 bytes
!Sys.isunix

Try it online!

This will give the same value for Windows as macOS.

i don't have a mac device to test it should give the same output as linux (macOS is unix-based) see the doc

nvm, you're right

you can save a byte btw by removing the ! and outputting reversed values (false if on windows)

@Makonede the challenge specifications do not allow that.

Factor, 11 bytes
os windows?

Try it online!

Nim, 20 bytes
echo defined windows

Try it online!

Lua (LuaJIT), 17 bytes
print(jit.os>"V")

Try it online!

Thunno 2, 28 bytes
‘\_\_Ʋ¡\_\_('Ỵġ').ẓ÷()‘E`ż³=

Uses platform.system(), as suggested in this SO answer.
Explanation
‘...‘E`ż³=  # Full program
‘...‘       # Push compressed string "__import__('platform').system()"
     E      # Evaluate as Python code (returns "Linux"/"Darwin"/"Windows")
      `ż³   # Push compressed string "Windows"
         =  # Are they equal?
            # Implicit output

Swift, 33 39 bytes
var f={#if os(Windows)
1#else
0#endif
}

Simply performs a compile-time check on the OS family and returns 1 if it's on Windows, or 0 otherwise. (I'm not gonna lie, I'm a little surprised you can put compiler directives on non-new lines like that...)

Does this actually output or just assign to a variable? Just assigning is not a valid output format

@mousetail You’re right, fixed now.

Racket, 26 17 bytes
Shameless plug for the TCL answer I saw that used the OS environment variable.
(and(getenv"OS"))

(Old answer)
Pretty straight forward. system-type with no argument returns a symbol indicating the system operating system type.
(eq?'windows(system-type))

Nim, 37 bytes
quit when defined(windows): 0 else: 1

Returns exit code 0 for Windows, 1 for all other operating systems. Uses conditional compilation with when.

PowerShell, 17
gdr|? P* -like *y

Abusing the fact that there's no Registry PSProvider on non-Windows systems.

Node.js, 23 bytes
_=>os.platform=="win32"

This only appears to be a snippet, as opposed to a full program or a function.

GNU AWK, 45 37 bytes
BEGIN{print PROCINFO["platform"]~/w/}

Try it online!
Evaluates the PROCINFO["platform"] built-in variable, and returns 1 if it matches any w character; returns 0 otherwise. Why, you ask? According to the GNU AWK manual, only mingw option has a letter w:
PROCINFO["platform"]

    This element gives a string indicating the platform for which
    gawk was compiled. The value will be one of the following:

    "mingw"
        Microsoft Windows, using MinGW.

    "os390"
        OS/390.

    "posix"
        GNU/Linux, Cygwin, Mac OS X, and legacy Unix systems.

    "vms"
        OpenVMS or Vax/VMS.

Python 3, 78 bytes
Raises a KeyError exception if it can't determine if running on Windows. On not-Windows it can return either None or 0 (both are falsy), on Windows it returns 1.
def f():
 try:open(':','x')
 except Exception as e:return{17:0,22:1}[e.errno]

: is a forbidden character on Windows (also on DOS, etc.)

The colon is also an invalid character in file names on macOS, so this seems like it would produce a lot of false-positives, if the goal is to detect Windows. In fact, it specifically violates the rules of the challenge, which was to fail to detect OS X. Have you actually verified that this does not result in an error on macOS?

@CodyGray I remember having tested this on my Hackintosh, but I'll check again just in case.

It does actually work on Mac OS Sierra (10.12).

PowerShell, 18 bytes
$env:OS-like"Win*"

Try it online!


text:
Different tasks, same characters
In this challenge, you need to solve 4 different tasks using the same set of characters. You can rearrange the characters, but you can't add or remove characters.
The winner will be the submission that solves all tasks using the smallest number of characters. All tasks must be solved in the same language.
Note that it's the smallest number of characters, not the smallest number of unique characters.
Task 1:
Output the first N numbers of every third composite number. The codeblock below shows the first 19 composite numbers in the first row, and every third composite number on the row below.
4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24, 25, 26, 27, 28, 30
4,       9,         14,         18,         22,         26,         30

If N=5 then the output should be 4, 9, 14, 18, 22. You must support 1<=N<=50.
Composite numbers are positive numbers that aren't prime numbers or 1.
The result for N=50 is:
4, 9, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 57, 62, 65, 69, 74, 77, 81, 85, 88, 92, 95, 99, 104, 108, 112, 116, 119, 122, 125, 129, 133, 136, 141, 144, 147, 152, 155, 159, 162, 166, 170, 174, 177, 182, 185, 188, 192

Task 2:
Output a N-by-N multiplication table. You must support 1<=N<=20
Example:
N = 4
1   2   3   4
2   4   6   8
3   6   9  12
4   8  12  16

The output format is optional, the following is acceptable output [[1,2,3,4],[2,4,6,8],[3,6,9,12],[4,8,12,16]].
Task 3:
Determine if a number is a Fibonacci number. You must support positive N up to the default integer limit of your language. If there are both 32-bit integers and 64-bit integers then you can choose to use the one that requires the shortest code. For instance, use int instead of long int if you have the choice. You can not choose a smaller integers than 32-bit unless that's default (you can't use 8-bit integers if 32-bit is default).
true/false, false/true, 1/0, 1/-1, a/b are all acceptable output as long as it's consistent.
Task 4:
Take N as input and output the result of 1^1+2^2+3^3+...N^N. You must support 1<=N<=10.
The 10 different results are:
1, 5, 32, 288, 3413, 50069, 873612, 17650828, 405071317, 10405071317

This is code-golf, so the shortest submission in each language wins!
This Stack Snippet will help check your solution. It measures the minimum set of characters needed to include all four solutions, and shows the leftover characters.

function update() {
  var m = {};
  var a = [q1.value, q2.value, q3.value, q4.value];
  var o = [{}, {}, {}, {}]
  for (var i = 0; i < 4; i++) {
    for (var j = 0; j < a[i].length; j++) o[i][a[i][j]] = -~o[i][a[i][j]];
    for (var c in o[i]) if (!(o[i][c] < m[c])) m[c] = o[i][c];
  }
  var t = 0;
  for (var c in m) t += m[c];
  for (var i = 0; i < 4; i++) {
    t += "\n";
    for (var c in m) t += c.repeat(m[c] - ~~o[i][c]);
  }
  p.textContent = t;
}

  <textarea id="q1"></textarea>
  <textarea id="q2"></textarea>
  <textarea id="q3"></textarea>
  <textarea id="q4"></textarea>

Binary: two characters

@coredump Yes, two unique characters...

Python, 88 87 bytes
lambda n:[a for a in range(11*n)if any(a%b<1for b in range(2,a))][:3*n:3]#1,,,=====bd++
lambda n:[[a*b for b in range(1,n+1)]for a in range(1,n+1)]#,,::ybaaa(*i%n< =====2)d33f
f=lambda n,a=1,b=1:a<n and f(n,b,a+b)or n==a#2eerrrfo::((**iii11[[aannn+     ]]y))%33gg
f=lambda n,a=1:a<=n and a**a+f(n,a+1)#::ooeeiii]]      y))bbbgg,,rrrra((11[[nnnnf==2%33

Didn't put too much effort into sharing characters or the golfs themselves, this will almost surely be beat.

Will range(11*n) always contain enough composites?

@FlipTack Yes, 5*n is sufficient.

Jelly, 19 18 17 characters
Task 1
Ḟþe*S
×5µḊḟÆRm3ḣ³

Try it online!
Task 2
5µḊḟÆRm3ḣ³Ḟe*S
×þ

Try it online!
Task 3
5µḊḟmḣþ*S
×3RÆḞ³e

Try it online!
Task 4
×5ḊḟÆm3ḣ³þe
Rµ*ḞS

Try it online!
How it works
Every line in a Jelly program defines a separate link (function). The last one is the main link and is called automatically when the program is executed. Unless that main link references the others somehow, they have no effect. Note that even uncalled links may not contain parser errors.
Task 1
×5µḊḟÆRm3ḣ³  Main link. Argument: n

×5           Yield 5n.
  µ          Begin a new chain, with argument 5n.
   Ḋ         Dequeue; yield [2, ..., 5n].
     ÆR      Prime range; yield all primes in [1, ..., 5n].
    ḟ        Filter; remove the elements to the right from the ones to the left.
       m3    Pick every third element.
         ḣ³  Keep the first n results.

Task 2
This one's trivial: × is the multiplication atom, and the quick þ (table) applies × to each combination of elements in the left and in the right argument. If the arguments are integers (which they are here), it also casts them to range first.
Task 3
×3RÆḞ³e  Main link. Argument: n

×3       Yield 3n.
  R      Range; yield [1, ..., 3n].
   ÆḞ    Fibonacci; yield [F(1), ... F(3n)].
     ³e  Test if n exists in the result.

Task 4
Rµ*ḞS  Main link. Argument: n

R      Range; yield [1, ..., n].
 µ     Begin a new chain with argument [1, ..., n].
   Ḟ   Floor; yield [1, ..., n].
  *    Yield [1**1, ..., n**n].
    S  Take the sum.

Glad to see ÆḞ is already proving to be useful!

Mathematica, 60 characters
Task 1: Composites
#/AFF^abcinoruy{};Select[Range[2,9#],!PrimeQ@#&][[;;3#;;3]]&

Task 2: Multiplication Table
!29;F@FPQRS[];a^b;c[c[e]];eeegiilmnnotu;Array[3##&,{#,#}]/3&

Task 3: Fibonacci
##&;239;A/PS[]^e[];lmrtuy;{,};!FreeQ[Fibonacci@Range[3#],#]&

Task 4: Sum of powers
!###&;23/39;A@F;F[P[Q[]]];Raabccegiilnnorrty;Sum[e^e,{e,#}]&

Each submission is a set of expressions that are ignored, followed by an unnamed function which implements the given task.
I wrote a simple CJam script which "optimally" combines raw solutions by prepending a comment. I then ended up saving three bytes on top of that by manually getting rid of each comment (which required some rearranging to get valid syntax in each case). The script made it a lot easier to try out simple variations of the solutions to see if they would bring down the overall score. Feel free to use the script yourself.

I have a comment, but it's not about your code itself :P. (Nice answer, btw). Your CJam script overlooks a simple flaw: If I enter ab and ba as the scripts, it will give me (**)ab and (**)ba, instead of ab and ba.

@AlexL. Yes, it also doesn't consider the fact that (**) itself could be used to cover some characters if they were used in any of the other programs.

MATL, 29 28 26 characters
Task 1 (every third composite number)
6*:tZp~)G:3*q)%G"$]vwm^sl+

Try it online!
Task 2 (multiplication table)
:l$*%6*tZp~)G:3q)G"]vwm^s+

Try it online!
Task 3 (Fibonacci detector)
l6Zp~G:"3q$t+]vGwm%):*)^s*

This displays 1 / 0 for Fibonacci / non-Fibonacci respectively.
Try it online!
Task 4 (sum of powers)
:t^s%6*Zp~)G:3*q)G"$]vwml+

Try it online!
Check
This program inputs the four strings and displays them sorted, to visually check that they use the same characters.
Explanations
% is the comment symbol. Everything to its right is ignored.
Task 1 (every third composite number)
6*    % Input N. Multiply by 6
:     % Range [1 2 ... 6*N]. This is enough because every even number is composite,
      % so this contains at least 3*N composite numbers
t     % Duplicate
Zp    % Isprime
~     % Negate
)     % Use as index to select composite numbers, including 1, from [1 2 ... 6*N]
G:    % Push [1 2 ... N]
3*q   % Multiply by 3 and subtract 1: gives [2 5 ... 3*N-1]
)     % Pick those composite numbers. Implicitly display

Task 2 (multiplication table)
:     % Input N. Range [1 2 ... N]
l     % Push 1
$     % Specify that next function will take 1 input
*     % Product of array. With 1 input it produces all pair-wise products
      % Implicitly display

Task 3 (Fibonacci detector)
l     % Push 1
6     % Push 6
Zp    % Isprime. Gives false
~     % Negate. Gives true, or 1
G:    % Push [1 2 ... N], where N is the input
"     % For each
  3q  %   3, subtract 1
  $   %   Specify that next function will take 2 inputs
  t   %   Duplicate the top two elements of the stack
  +   %   Add
]     % End
v     % Vertically concatenate the entire stack. This produces a column vector
      % with a sufficient amount of Fibonacci numbers
G     % Push input N
w     % Swap
m     % Ismember. Gives true if input is in the vector of Fibonacci numbers
      % Implicitly display

Task 4  (sum of powers)
:     % Implicitly input N. Push [1 2 ... N]
t     % Duplicate
^     % Power, element-wise
s     % Sum of array. Implicitly display

When I first looked at the challenge, I thought Hey MATL would be perfect for this! You beat me to it. +1

@DJMcMayhem Sorry, I tend to answer a lot. Next time ping me and I'll refrain if you are working on it :-) Anyway, why not go ahead? Maybe you can outgolf this

@DJMcMayhem, please post an answer too, even if you don't manage to outgolf Luis. I wish more people would post answers in languages that are already used, even if they don't manage to outgolf the first one.

@stewiegriffin Haha, okay sure. I don't have a valid answer yet, but if I get one (and it's sufficiently different) I'll post it.

Perl 6, 61 bytes
{(4..*).grep(!*.is-prime)[0,3...^*>=$_*3]}#$$&+1==>X[]__oot{}

{[X*](1..$_,!0..$_).rotor($_)}#&***+-..334===>>[]^eegiimpps{}

{(1,&[+]...*>=$_)[*-!0]==$_}#$()**....334>X^_eegiimoopprrst{}

{[+]((1..$_)>>.&{$_**$_})}#!**,-....0334===X[]^eegiimoopprrst

The second one returns ((1,2,3,4),(2,4,6,8),(3,6,9,12),(4,8,12,16)) when given 4
Perl 6 doesn't really have a maximum integer, but the third one  works instantly with an input of 15156039800290547036315704478931467953361427680642. The only limiting factors would be memory and time.
Otherwise they will all run "instantly" for inputs well beyond what is necessary.
Try it online

JavaScript (ES6), 101 100 95 93 91 bytes
(n,r=[],a=(y,m)=>n?y%m?a(y,++m):a(y+1,2,y==m||n--%3||r.push(y)):r)=>a(4,2,n*=3)//>....p*A&&
n=>[...Array(n)].map((r,y,m)=>m.map((s,n)=>y*++n,y+=1))//22334(,,,,===ayy)??%%::||||--uh*&&
r=(n,y=1,a=2)=>n==y||n>y&&r(n,a,y+a)//2334((((,,,,r=[]ayymmmm))))>??%%++::||--.....ppush**A
r=y=>y&&y**y+r(y-1)//22334(((((nnnn,,,,,,,,r=====[]aaaaymmmm)))))>>??%%++::||||-.....ppushA

Edit: Saved 1 byte by not supporting 0 as a Fibonacci number. Saved 5 bytes plus a further 2 bytes (1 thanks to @Arnauld) by renaming variables. Saved 2 bytes by switching between +1, ++ and +=1.

Replacing all occurrences of the c variable with A should save one byte.

(I was about to suggest that you can also replace d with y, but d is undefined in the current version, so you probably want to fix that first)

@Arnauld Thanks for pointing that out, but I managed to fix things up and save a further byte by renaming a to m.

MATL, 30 characters
The character set I went with is:
!%))*+001233::<=GGQZ\]^`pstvyy~

I couldn't outgolf the other MATL answer, but I had fun coming up with this solution.
Task 1:
Third composite numbers.
4t^:QtZp~)G3*:3\1=)%!`yy+<]vGs

Try it online!
Task 2:
Multiplication table. Definitely the easiest task, due to the way MATL works
:t!*%4QZp~)G3:3\1=)`yy+<]vGs^t

Try it online!
Task 3:
Fibonacci tester. Prints a positive integer (1 or 2) for truthy inputs, and 0 for falsy inputs.
1t`yy+tG<]vG=s%4:QZp~)3*:3\)!^

Try it online!
Task 4:
Sum of powers
:t^s%1`yy+tG<]vG=4QZp~)3*:3\)!

Try it online!
I'll post a more thorough explanation later, but for now, you should note that % is the comment character, so the programs are really:
4t^:QtZp~)G3*:3\1=)
:t!*
1t`yy+tG<]vG=s
:t^s

PowerShell, 95 94 bytes
(TimmyD savin' my bacon yet again)
Task 1:
(""..999|?{'1'*$_-match'^(?=(..+)\1+$)..'})[(0..("$args"-1)|%{$_*3})]#|$$$$===ss%``iiex!!nnnq;

Try it online!

Task 2:
($s=1.."$args")|%{"`$s|%{$_*`$_}"|iex}#0113999((((......??''''*$$$--match^===++))))\[]i!!nnnq;

Try it online!

Task 3:
!!(($i="$args")..($s=1)|?{($n=($s+=$n)-$n)-eq$i})#0113999......||?{''''**__match^+\}[""%%]``x;

Try it online!

Task 4:
"$args"..1|%{$s+="$_*"*$_+1|iex};$s#013999(((((......|??{''''$$$--match^===)))))\}[%]``i!!nnnq

Try it online!

Oh, that stringification "$args" instead of $args[0] is brilliant. I'm going to use that from here on.

@TimmyD Yeah I've been using that for the single byte savings on anything with a single parameter.

@TimmyD good point! I'd have to re-write all of them to be sure though, I might revisit it and apply that. Once I finished all 4 I kind of petered out in terms of optimizing.

Well I meant re-doing the TIO links and such but FINE @TimmyD I'll stop being lazy and use your generous suggestion that's not at all as much work as I'm making it out to be! (edited) :-p

You can eliminate the ; from Task 4 by manipulating the calculation with ("$args"..1|%{$s+="$_*"*$_+1|iex})-(-$s) to save another overall byte.

05AB1E, 21 bytes
Task 1
3ÅFOL¦DâPÙï{3ôø¬¹£qåm

Try it online!
Task 2
LDâP¹ôq3m¦Ùï{3ø¬£ÅFåO

Try it online!
Task 3
3mÅF¹åqL¦DâPÙï{3ôø¬£O

Try it online!
Task 4
LDmOq3¦âPÙï{3ôø¬¹£ÅFå

Try it online!
Explanations
For all tasks, the q ends the program so the code that follows never gets executed.
Task 1
This is the biggest byte-hog. An small improvement here could go a long way.
3ÅFO                 # sum the first 4 fibonacci numbers
    L¦               # range [2 ... above]
      Dâ             # cartesian product with itself
        P            # product
         Ù           # remove duplicates
          ï{         # sort
            3ô       # split in pieces of size 3
              ø      # transpose
               ¬     # get the first lits
                ¹£   # get the first input-nr elements of the list

Task 2
L       # range [1 ... input]
 D      # duplicate
  â     # cartesian product
   P    # product
    ¹ô  # split in pieces of input size

Task 3
3m      # input**3
  ÅF    # get a list of that many (+1) fibonacci numbers
    ¹å  # check if input is in that list

Task 4
L     # range [1 ... input]
 D    # duplicate
  m   # elementwise power of ranges
   O  # sum

Haskell, 77 76 characters
m n=[[x|x<-[1..],2/=sum[1|0<-mod x<$>[1..x]]]!!y|y<-[1,4..3*n]]--2 n===y();^
s n=[(*y)<$>[1..n]|y<-[1..n]]--0112234mmm  ====[[[xxxx||<<--..]]],,/uod!!y;^
n x|x<2=1|1<3=sum(n<$>[x-1,x-2]);d y=[0|m<-[1..y],y==n m]--4[[[....]]]/o!!*^
o n=sum[x^x|x<-[1..n]]--01112234mm  n====[[[[x||<<<--....]]]],,/d$>!!yyy*();

Try it online!
-- starts a line comment, so all four programs are of the form <program>--<unused chars>.
Task 1:
m n=[[x|x<-[1..],2/=sum[1|0<-mod x<$>[1..x]]]!!y|y<-[1,4..3*n]]

The longest program. [x|x<-[1..],2/=sum[1|0<-mod x<$>[1..x]]] yields a infinite list of composite numbers plus a starting 1 which corrects the 0-indexing. Usage:
Prelude> m 5
[4,9,14,18,22]

Task 2:
s n=[(*y)<$>[1..n]|y<-[1..n]]

Usage:
Prelude> s 5
[[1,2,3,4,5],[2,4,6,8,10],[3,6,9,12,15],[4,8,12,16,20],[5,10,15,20,25]]

Task 3:
n x|x<2=1|1<3=sum(n<$>[x-1,x-2]);d y=[0|m<-[1..y],y==n m]

Returns [0] for truthy and [] for falsy. Usage:
Prelude> d 5
[0]
Prelude> d 6
[]

Task 4:
o n=sum[x^x|x<-[1..n]]

Usage:
Prelude> o 5
3413

Ruby, 83 82 80 78 characters
->m{'*+-=';[*0..m-1].map{|b|(4..516).select{|p|(2...p).any?{|n|p%n==0}}[3*b]}}
->n{'()%**+--......00123456==?[[]]clmnsty{||}';(b=1..n).map{|e|b.map{|p|e*p}}}
->m{'%+-......001236bclnnpt[[]]{{||||}}';(1..e=m*m).any?{|p|(p*p-5*e).abs==4}}
->n{'%*.......023456=?[]abbceelnsty{{||||}}';((m=0)..n).map{|p|m+=p**p}[-1]-1}

Note: Fibonacci numbers detector using the perfect square method described on Wikipedia:
https://en.wikipedia.org/wiki/Fibonacci_number#Recognizing_Fibonacci_numbers

if you have characters to burn, why not use a comment at the end instead of a string? It saves you 2 characters per line ''; vs #

Thanks, but to me it feels like cheating.

05AB1E, 17 bytes
Bytes used:
δн3FILOPQm£¦ÅÐãêô

Task 1 - every 3rd composite number:
QÅmFÐOL¦ãPê3ôI£δн

Try it online or verify all \$[1,50]\$ inputs.
Task 2 - multiplication table:
ÅFOQmê3ôãн¦£ILÐδP

Try it online or verify all \$[1,20]\$ inputs.
Task 3 - Fibonacci check:
£3ôδнã¦LPmIÐÅFQêO

Try it online or verify the first \$[0,1000]\$ inputs.
Task 4 - exponentiation sum:
ÅFPQê3ôãδн¦£ILÐmO

Try it online or verify all \$[1,10]\$ inputs.
Try all four at once.
Explanation:
Task 1 - every 3rd composite number:
This one takes up most bytes. Not only in general, but also to get a list large enough for input \$n=1\$.
              # No-ops:
Q             #  Check if the (implicit) input is equal to the (implicit) input: 1
 Åm           #  Get the mean of that (remains 1)
   F          #  Loop that many times:

              # Main part of the program:
Ð             #   Triplicate the (implicit) input
 O            #   Sum all values on the stack
  L           #   Take a list in the range [1,3*input]
   ¦          #   Remove the first to make the range [2,3*input]
    ã         #   Cartesian product with itself, to create all possible pairs
     P        #   Take the product of each pair
      ê       #   Sort & uniquify all values
       3ô     #   Split it into parts of size 3
         I£   #   Leave the first input amount of parts
           δн #   And then leave the first item of each part
              #  (after the no-op loop, the result is output implicitly)

Task 2 - multiplication table:
              # No-ops:
ÅF            #  Get all Fibonacci numbers below or equal to the (implicit) input
  O           #  Take the sum of those
   Q          #  Check if it's equal to the (implicit) input (which will always be 0)
    m         #  Push the input to the power that 0 (which will always be 1)
     ê        #  Sort and uniquify those digits (remains 1)
      3ô      #  Split it into parts of size 3 (which wraps the 1 into a list: [1])
        ã     #  Take the cartesian product of that list with itself (which becomes [[1,1]])
         н    #  Leave the first item of that (which becomes [1,1])
          ¦   #  Remove the first value (which becomes [1])
           £  #  Keep that many digits of the input
              #  (which becomes the first digit of the input, wrapped in a list)

              # Main part of the program:
IL            #  Push a list in the range [1,input]
  Ð           #  Triplicate this list
   δ          #  Using the top two lists, apply double vectorized:
    P         #   Take the product of the two values
              #  (after which the resulting multiplication table is output implicitly)

Task 3 - Fibonacci check:
              # No-ops:
£             #  Keep the first (implicit) input amount of digits of the (implicit) input
 3ô           #  Split this input into parts of size 3
   δн         #  Take the first digit of each part (let's call this digit d)
     ã        #  Take the cartesian product with itself (which becomes [[d,d]])
      ¦       #  Remove the first item (which becomes [])
       L      #  Push a list in the range [1,[]] (which remains [])
        P     #  Take the product of that list (which becomes 1)
         m    #  Push the (implicit) input to the power this 1 (which becomes the input)

              # Main part of the program:
I             #  Push the input
 Ð            #  Triplicate it
  ÅF          #  Get a list of Fibonacci numbers equal to or below this input
    Q         #  Check for each whether it's equal to the input
     ê        #  Sort and uniquify these checks
      O       #  Sum the remaining checks (which will either be [0] or [0,1])
              #  (after which this 0/1 is output implicitly as result)

Task 4 - exponentiation sum:
              # No-ops:
ÅF            #  Get all Fibonacci numbers below or equal to the (implicit) input
  P           #  Take the product of those (which will always be 0)
   Q          #  Check if it's equal to the (implicit) input (remains 0)
    ê         #  Sort and uniquify those digits (remains 0)
     3ô       #  Split it into parts of size 3 (which wraps the 0 into a list: [0])
       ã      #  Take the cartesian product of that list with itself (which becomes [[0,0]])
        δн    #  Leave the first item for each of those (which becomes [0])
          ¦   #  Remove the first value (which becomes [])
           £  #  Keep that many digits of the input (remains [])

              # Main part of the program:
IL            #  Push a list in the range [1,input]
  Ð           #  Triplicate this list
   m          #  Take the power of the values at the same indices of the top two lists
    O         #  And sum those
              #  (after which this sum of exponents is output implicitly as result)

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes