title: C# Windows 7 BlockInput
body: <p>I have created a service in Win7 using C#. Within that service I want to use the BlockInput function, which in Win7 it seems requires admin.</p>
  
  <p>I set the serviceprocessorinstaller's, account, username, and password to an admin account, within the code and the BlockInput doesn't work. Note: under the service properties/logon tab it is set properly.</p>
  
  <p>I then added a manifest for my service and set the requestedExecutionLevel to "requireAdministrator". Yet the BlockInput still doesn't want to work. </p>
  
  <p>I tried moving the BlockInput down to the client level and then to a client wrapper but still it doesn't want to work.</p>
  
  <p>Running out of ideas...Any suggestions?</p>
  
  <p>Start Edit Here:</p>
  
  <p>Here is my manifest (or part of it, sorry formatting is terrible)
  <code>&lt;assemblyIdentity version="1.0.0.0" name="BlockInputService.app"/&gt;</code>
  <code>&lt;trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"&gt;</code>
  <code>&lt;security&gt;</code>
  <code>&lt;requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"&gt;</code>
  <code>&lt;requestedExecutionLevel level="requireAdministrator" uiAccess="false" /&gt;</code>
  <code>&lt;/requestedPrivileges&gt;</code>
  <code>&lt;/security&gt;</code>
  <code>&lt;/trustInfo&gt;</code></p>
  
  <pre>
  <code>
  
      namespace BlockInputService
      {
         [ServiceContract(Namespace = "http://BlockInputService")]
         public interface IBlockInputTest
         {
            [OperationContract]
            void BlockInputMethod();
         }
  
         public class BlockInputTest : IBlockInputTest
         {
            private const string SOURCE = "BlockInputService";
            private const string LOGNAME = "Application";
  
            [return: MarshalAs(UnmanagedType.Bool)]
            [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
            public static extern bool BlockInput([In, MarshalAs(UnmanagedType.Bool)] bool fBlockIt);
  
            public void BlockInputMethod()
            {
               if (!EventLog.SourceExists(SOURCE))
               {
                  EventLog.CreateEventSource(SOURCE, LOGNAME);
               }
  
               try
               {
                  bool flag = BlockInput(true);
                  EventLog.WriteEntry(SOURCE, "BlockInput(true) returned: " + flag);
  
                  EventLog.WriteEntry(SOURCE, "Sleep for 5 sec");
                  Thread.Sleep(5000);
               }
               catch (Exception ex)
               {
                  EventLog.WriteEntry(SOURCE, ex.Message);
               }
               finally
               {
                  bool flag = BlockInput(false);
                  EventLog.WriteEntry(SOURCE, "BlockInput(false) returned: " + flag);
               }
            }
         }
      }
  
  </code>
  </pre>