Run application automatically when system back from hibernate - java

I want to start my application automatically for all users, whenever system starts from shutdown or hibernate (I don't want user manually click on my exe icon to run application). For example, if same system is used by two users, it should work for both users.
I've tried following, but it is not working for all users, neither for start from hibernate:
I had added my exec shortcut in shell:startup
I m also using batch file code like this REG ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v JApp /t REG_SZ /d /h "%~MoodOMeter.exe"
now a problem which i m getting is that it only works for current user i.e if it registers on startup folder on userid 1 then it will not run for userid 2 and the last thing that not working is that if system start from hibernate then it will not run automatically can anyone help me with this issue

You can use Task Scheduler to trigger an action on resuming system.
But Task Scheduler has its limitation (in context of your question).
You can setup the task in two modes:
For specific account with "Run whether user is logged on or not" option. For that you need to know a password of some local account. And the task will run with privileges of that account, so not with privileges of the logged on account. That would be problem, if you need to write files or registry in user profile. Not to mention that there can be multiple logged on users at the same time (the task would be run for one of them only).
With "Run when user is logged on" option, you won't need the password and the task is run with correct privileges, but only for the account that created the task. So if you create the task in installer, it would be executed only for the account that run the installer. To solve this, you can make the application itself create the task, when it's executed (and the task does not exists yet).
If the above limitation is ok, then it's a solution.
Other way is to keep your application running in the background and monitor the system to trigger your desired action on resuming.

Related

JCMD for different user

I need to grab parameters from jcmd for process, which started by other user on same PC. But I can't do it using admin account. I also tried to use 'runas' function, but have same result.
Is there a way to catch this process, except using the same user?
have the answer. Java locates it perf files in user temp folder, besides, it cleaning stopped process files on each jcmd request. That's why you can't get perf.counter data from other user, also you cant use perf file of other user under your account.
Another trouble is that if you want to use windows task scheduller for that purposes, you MUST run this task ONLY, when user is logged. Other way you will have permission exception.

Java/MySQL scheduler, reminder for web app and standalone app

OK so here is the scenario.
I have a local Java application running on a desktop. Users/clients need to check in to this (by going through required steps) either every day, every other day, weekly, biweekly, monthly, etc (admin-defined for each user).
In my web application, an admin would add the user and the schedule they need to check in to. If the user does not check in by their required time, then the admin would be alerted of this person and he can complete other actions from there.
How should I go about doing this and should it be done through MySQL or Java? I thought about scheduling events in MySQL but that could not be admin-defined on the web app. I'm not sure what else to do for this.
MySQL is good for storing state. Maintaining records of when they checked in is good, and you can write a script that sees who hasn't checked in when they needed to and alerts the admins. The Java application then just has to update the MySQL record with the current time everytime they check in.

User Permission in Jenkins

Inside Jenkins Jobs & Builds folder, I am creating a text file and writing some content through Java program. As I am part of corporate network, I am inside firewall with many security rules where I have been restricted to write/update the program files directory under C: drive. Although I am administrator in my local machine, however the company policies are still applied which is denying me access to write/delete any files from the Jenkins directory. I see Jenkins is nicely reading/modifying/writing any files/folders without any issues which is believed to the typical behavior of Jenkins's USER.
Question 1: Is there any way I can use this Jenkins's user through my code so I can avail access on to these directories?
Question 2: Are there ways to solve this issue through Java code? (Note: I have tried writing a file with Run as Administration java code as well)
Kindly let me know if I am missing any details,.any help is highly appreciated.
It's about the user who launched the jenkins server, who might have the permissions to access the directories.
You can use the same user for your operations if available.
Question 1: Is there any way I can use this Jenkins's user through my code so I can avail access on to these directories?
Jenkins users - Jenkins server can have its own users and privileges can be set for each users differently. You cannot use these users outside of Jenkins server.
You can use the user who launched the Jenkins server, must be a user at OS level.
Question 2: Are there ways to solve this issue through Java code? (Note: I have tried writing a file with Run as Administration java code as well)
Again, only OS level users can be used and not the Jenkins users(users created inside Jenkins server)
If you want your application to run with same credentials as Jenkins user, then hold Shift+Right Click your application, select "Run as different user", provide Jenkins's user credentials and press OK.
If you are launching your Java application from command line, do the Shift+Right Click on the cmd.exe first, and once again select "Run as different user"
If you want to impersonate a Windows user from within code, then you should really reword your question body and title (and remove Jenkins references as it has nothing to do with this). But even in this case, you need to know the credentials of the user you are trying to impersonate

Is it possible, in Java, to authenticate a user over active directory and then perform tasks that user has permissions for?

I have a java app that is running as a service on a server.
The service is running as the local system user. Which does not have access to folder XYZ
However, let's say there is a user, who does have access to folder XYZ. Is it possible for this user to somehow login through the java app, thus giving the app permission to access the folder?
The network revolves around active directory.
not really... the app while its running has only the privilege of the user account that started it..
now if you want to do some activity as a different user (when you have his/her credentials) you can start a new process & do the activity in it.
on windows you can say runas /user:<<username>> <<command to run>>. again this requires sufficient privilege to execute the runas command & the runas service must be running.
you could also try to start another instance of your app (but I wouldn't recommend this)
If you can install the server as a Windows service then you can chose the user that will be used to run the server. If you chose the user to be one that has access to the required folder,
then your app will also have access to the folder.
On the run command or command prompt, run services.msc. Look at the 'Log On As' column of the services. 'Log On As' is set to 'Local system' by default. If you right-click the service and go to its properties, the Log On tab will have an option to start the service under any user that you desire.
As for install a new windows service to automatically start your server with, try http://wsinnovations.com/softeng/support/manualservice.html

java getRuntime().exec an exe that requires UAC

So we have a java process that runs as a windows service. It needs to execute a command with Runtime.getRuntime().exec(command). The command it executes requires UAC. This is on windows server 2008 and sounds like you cannot disable UAC for a single executable so is there any other way to make this work?
If your Java application runs as a windows service, it most likely runs under one of the system accounts: SYSTEM (most probable), LOCAL SERVICE, or NETWORK SERVICE. Thus if the service runs under SYSTEM account, everything you start from the service will inherit the account. Anyway your service must be allowed to interact with Desktop.
To summarize, if your process run as elevated, then processes started from it will also run elevated.
To elevate, you have to use ShellExecute or ShellExecuteEx functions of Windows API. If the .exe you're starting is marked with level=requireAdministrator in its manifest, the shell will display UAC dialog. If it's not marked, you can use runas verb/operation to force UAC confirmation dialog. Note: runas on Windows XP will show "Run as another user" dialog.
If Runtime.getRuntime().exec(command) is implemented via ShellExecute, then marking the .exe with appropriate manifest will work; if exec uses CreateProcess, the process will be started with current user privileges, i.e. not elevated; moreover the process will not be started at all if .exe has requireAdministrator in its manifest.

Categories