running a java application as superuser - java

I have a build java application for mac I want to run the application as root/superuser all the time when the application opened up. how would i go about to achieve this, I don't want to make a script that runs the jar or open terminal and type sudo to run the jar. I want it where if they double click on the runnable jar it will prompt the user requesting for root right.

Related

How can I host my Springboot application in my own computer like a background service?

I want to host my springboot application on my on PC, I want it to start with the computer, just like databases do. But I can't find anything related (probably because I am asking the 'wrong' way). There is any way to start the springboot application with my pc in the background, with no CMD showing or having to keep intelijj open?
I tried to search how to host the application, but didn't found any thing 'locally' based, everything was how to host in X cloud or Y domain/host. What I want is to my application run on the background of my PC so I can use it as a personal system, but don't want to keep a cmd open or intelijj
Also I can't really use docker.. that was the way I was trying before, but I can't let Hyper-v active..
There are 2 steps:
Get command line of execution of your application runned by IntelliJ. To do so:
You have to create a file with extension ".bat" (batch file) with the contents of the command copied above, than follow the steps bellow to define it to run in the startup configuration of the windows 10:
Run a batch file at loading of Windows 8 and 10 Once the shortcut is created, right-click the shortcut file and select Cut. Press Start, type Run, and press Enter . In the Run window, type shell:startup to open the Startup folder.

how to trigger jar on windows machine at a specific time [duplicate]

This question already has answers here:
How to schedule a java program to run daily in Windows?
(3 answers)
Closed 6 years ago.
I am designing a java application which needs to run at a specific time. My application is packaged in jar file and this jar should be activated every day at 3 AM in morning. My end Machine is windows machine not a server. Please help me out with this. Myapp.jar is the jar file and its located in D:/Collector/MyApplication/target/MyApp.jar is the location in my system.
Right now
java -jar MyApp.jar
is executing fine. But when my system goes off then again I have to initiate the same through command prompt. So I would also require a solution in which when system reboots the jar should be initiated.
How to schedule a java program to run daily in Windows?
This answer already is there but I don't want to do it with Task scheduler as it reduces my machine efficiency.
Windows has a "Task Scheduler", which is what you need to use to run a program on a recurring schedule and/or on machine startup.
You can program a task, or make an executable with your jar and place it on startup folder if windows 7 or lower
PROGRAM A TASK (SOURCE)
To Run Task Scheduler using the Windows interface
Click the Start button.
Click Control Panel .
Click System and Maintenance .
Click Administrative Tools .
Double-click Task Scheduler .
To Run Task Scheduler from the Command Line
Open a command prompt. (cmd or click Start, All Programs, Accessories, Command Prompt)
At the command prompt, type Taskschd.msc.
STARTUP FOLDER (SOURCE:)
On Windows 7 and earlier versions of Windows, the Start menu contained a “Startup” folder to make this easy. On these versions of Windows, you can simply open your Start menu, locate a shortcut to an application you want to start automatically, right-click it, and select Copy. Next, locate the Startup folder under All Apps in the Start menu, right-click it, and select Paste to paste a copy of that shortcut.
Create a bat file for that you want to achieve and schedule the windows Task Scheduler as listed below.
Click Start
Type Task and then click Task Scheduler
Once the Task Scheduler is open, you can create your own custom task by clicking Create Basic Task. This action starts a wizard that walks you through the process, prompting you with what program you want to execute, as well as how often and what time it should be run.

Running exe files with Hudson on Windows 8

I am attempting to have a Hudson job run a windows executable on a Windows 8 VM. When I attempt to run the exe file I get the error:
java.io.IOException: Cannot run program "C:\hudson\workspace\workspaceName\installer\bin\fileToExecute.exe": CreateProcess error=740, The requested operation requires elevation
Has anyone run into this and had it run automatically? I can't just have the exe file on the VM and set its permissions because a new copy gets downloaded at the start of each build.
Thanks in advance.
Disclaimer: I have not tried this with Windows 8.
First things first, even if you succeed to launch an .exe application from Hudson/Jenkins, it will be running under a different session, probably invisible to you. I've managed to achieve the workarounds for this with PsExec as detailed here:
Open Excel on Jenkins CI
With the above method, you will be able to launch an application and actually see it in the logged in session.
If your application does require elevated permissions for whatever reason, you've got to add -h switch to PsExec

Installation failed due to low priviledge on Win8

I am using Java code to install an EXE program on Win8, by executing this command "java -jar installapp.jar" in CML. The command line window is NOT opened by "Run as administrator", but the current user is a member of administrator group.
However, in the same CML window, if I install the EXE directly, it works. It just fails when the installation is executed by Java.
So anyone can give me a tip?
Thanks a lot,
Michael
To correctly install an application which includes writing to system-protected areas can't be done without elevating through UAC. That means the CML window must be Run as administrator.
Java executables are marked with manifest which requests asInvoker privileges. So the process would start with administrator tokens dropped if the parent process wasn't elevated. It's the whole point of UAC: even if you are member of Administrators group, you don't get the full, unlimited privileges until you elevate.
What do you mean by "install the exe directly"?

Not able to run psservice.exe and plink.exe from servlet deployed in Tomcat 6.0 using runtime exec and processbuilder

I am trying to run psservice.exe and plink.exe from servlet using runtime exec. It will be used for starting or stopping services on remote computer running windows and unix aix.
I have set system variables so that i am able to run them from command prompt. These commands are running perfectly from command prompt and java program
I am using below code in Servlets for remote windows machine
Runtime.getRuntime().exec(serverPropLoader.getServerProperties("psservice \\\\172.xx.xx.xx -u username -p password stop MySQL"));
I am using below code in Servlets for remote unix aix 5.3 machine
Runtime.getRuntime().exec(serverPropLoader.getServerProperties("PLINK.exe -ssh -pw "password" username#172.xx.xx.xx /home/mysql/stopservice.sh"));
Below are my observations :
If i run above statement from Eclipse (ver 3.4.2) using Tomcat6 it runs perfectly fine, but if export my web app as WAR and deploy it in Tomcat6 mannually it dosen't run. ( i have tried deploying it in mine and other system)
I have tried puting these command in Batch file and calling it from servlet but no success. From Batch file "net" and "sc" command are working but i am not able to run pservice and plink command. also "sc" command is working for local processes only.
After execution of servlet i am able to see psservice.exe and plink.exe in windows task manager but required services on local and remote system is not starting / stopping
The problem here is, you need to add admin previladges for the tomcat user.
Because this Apache Tomcat Monitor program requires permission to interact with system services, it cannot be executed as a standard user.
Do following tasks, you will be fine
Locate the tomcat7w.exe program in Windows Explorer (the default directory is C:\Program Files\Apache Software Foundation\Tomcat 7.0\bin).
Right-click the name of this file and select the Properties context menu item.
The tomcat7w Properties dialog displays.
Select the Compatibility tab and click either the "Show settings for all users" button or the "Change settings for all users" button at the bottom of the dialog.
A new tomcat7w.exe Properties dialog displays with a single tab entitled Compatibility for all users.
At the bottom of this dialog, in the Privilege Level group box, select the Run this program as an administrator.
The Apache Tomcat Monitor executable will now execute with the required privileges when run from a standard user account.
for more information pls refer
https://supportcontent.ca.com/cadocs/0/CA%20Automation%20Point%20Base%2011%204-ENU/Bookshelf_Files/HTML/AP--RelNotes/index.htm?toc.htm?2009998.html

Categories