Start Service with jna

608 views
Skip to first unread message

Sabine Griesser

unread,
Feb 5, 2013, 3:27:40 AM2/5/13
to jna-...@googlegroups.com
For starting and stopping my Service i would like to use jna, but i always get an exception i try to open the ServiceManager
It looks like, that the handle is alsways null

W32ServiceManager serviceManager = new W32ServiceManager();
serviceManager.open( Winsvc.SERVICE_ALL_ACCESS); 

Exception in thread "main" com.sun.jna.platform.win32.Win32Exception: Zugriff verweigert
at com.sun.jna.platform.win32.W32ServiceManager.open(W32ServiceManager.java:47)
at acftui.AcfMessageImpl.closeAcfService(AcfMessageImpl.java:502)
at acftui.AcfMessageImpl.main(AcfMessageImpl.java:64)
ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
JDWP exit error AGENT_ERROR_NO_JNI_ENV(183):  [../../../src/share/back/util.c:838]

I hope you can help me.
Greetings form Austria
SAbine


Daniel Doubrovkine

unread,
Feb 5, 2013, 7:46:23 AM2/5/13
to jna-...@googlegroups.com
Are you running as Administrator?

SAbine


--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--

dB. | Moscow - Geneva - Seattle - New York
dblock.org - @dblockdotorg

Sabine Griesser

unread,
Feb 5, 2013, 8:29:28 AM2/5/13
to jna-...@googlegroups.com
i have administrator rights..

Daniel Doubrovkine

unread,
Feb 5, 2013, 9:38:53 AM2/5/13
to jna-...@googlegroups.com
Does JNA work for any other platform call? Try something that gets the username for example via Win32 API (Advapi32Util.getUserName or something like that).

Sabine Griesser

unread,
Feb 6, 2013, 1:57:29 AM2/6/13
to jna-...@googlegroups.com
Yes.. this works correct. I get the Username

Daniel Doubrovkine

unread,
Feb 6, 2013, 8:05:56 AM2/6/13
to jna-...@googlegroups.com
The error message is pretty clear, it says "Access Denied", but this error:

ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
JDWP exit error AGENT_ERROR_NO_JNI_ENV(183):  [../../../src/share/back/util.c:838]

is completely puzzling. I suspect it happens later in the process and might be unrelated (there're obscure explanations in http://stackoverflow.com/questions/2225737/error-jdwp-unable-to-get-jni-1-2-environment).

I would try opening the service manager with lesser access and go from there. Look at how that is implemented, too, it calls a bunch of Win32 functions, you might want to step through that. But ultimately it still looks like a permissions problem to me.

Mainudin Sazal

unread,
Jun 18, 2017, 5:52:20 AM6/18/17
to Java Native Access
I am also trying a lot to start a windows service but continuously getting this error -
com.sun.jna.platform.win32.Win32Exception: Access is denied.
at com.sun.jna.platform.win32.W32ServiceManager.open(W32ServiceManager.java:47)

My system environment is Windows 10, JDK 1.8, Netbeans - 8.2. My code portion is given below - 

try {

   W32ServiceManager serviceManager
= new W32ServiceManager();


   
//i also tried "Winsvc.SERVICE_ALL_ACCESS" instead of "Winsvc.SC_MANAGER_ALL_ACCESS" but not worked for me.

   serviceManager
.open(Winsvc.SC_MANAGER_ALL_ACCESS);

   W32Service service
= serviceManager.openService("TeamViewer", Winsvc.SC_MANAGER_ALL_ACCESS); // windows service name of team viewer
   service
.startService();
   service
.close();
 
}catch(Exception ex){
   ex
.printStackTrace();
 
}

Matthias Bläsing

unread,
Jun 18, 2017, 6:48:23 AM6/18/17
to jna-...@googlegroups.com
Hey Mainudin,

Am Sonntag, den 18.06.2017, 02:52 -0700 schrieb Mainudin Sazal:
> I am also trying a lot to start a windows service but continuously
> getting this error -
> com.sun.jna.platform.win32.Win32Exception: Access is denied.
> at
> com.sun.jna.platform.win32.W32ServiceManager.open(W32ServiceManager.j
> ava:47)

did you check, that:

a) the current user has the necessary rights to access the service
manager with full privileges and
b) that UAC is not interfering? (deactivate it or run the programm
manually with Administrator privileges).

I worked with the service manager, so in principle it works.

HTH

Matthias


Reply all
Reply to author
Forward
0 new messages