title: JNA:com.sun.jna.platform.win32.Win32Exception- access denied
body: <p>I  use following code to control a windows  service from java program</p>
  
  <pre><code>public class PostgresService2
  {
      public static void main(String[] args)
      {
          try
              {
                  W32ServiceManager serviceManager = new W32ServiceManager();
                  serviceManager.open(Winsvc.SERVICE_STOP);
                  W32Service service = serviceManager.openService("DBService",
                          Winsvc.SERVICE_ACCEPT_STOP);
                  service.stopService();
                  service.close();
               }
               catch (Exception ex)
               {
                   ex.printStackTrace();
               }
      }
  }
  </code></pre>
  
  <p>This gives error on windows7 (64bit) machine</p>
  
  <pre><code>com.sun.jna.platform.win32.Win32Exception: Access is denied.
          at com.sun.jna.platform.win32.W32Service.queryStatus(W32Service.java
          at com.sun.jna.platform.win32.W32Service.waitForNonPendingState(W32S
          at com.sun.jna.platform.win32.W32Service.stopService(W32Service.java
          at chs.capitalmigrate.ui.PostgresService2.main(PostgresService2.java
  </code></pre>
  
  <p>The shell from where the command is run has administrative privileges.  How I can provide full access?</p>