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.
Related
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.
I have a USB line display, similar to the ones that are used in store point of sale systems.
To print ABC to this line display, I run the following command:
echo ABC > \\.\LCLD9\
This prints ABC to the line display.
I'm trying to figure out how to control this output from a website, if possible, although I am not sure if it would be possible, as I can see security issues with being able to run arbitrary commands form web pages.
I'm trying to figure out how to control this output from a website, if possible, although I am not sure if it would be possible, as I can see security issues with being able to run arbitrary commands form web pages.
This is indeed not possible on an unmodified system. There is no way for a web page to run an arbitrary command on the user's machine -- that is the definition of a security vulnerability.
If you can get the user to install software ahead of time, you could use a Chrome extension with the serial, usb
or nativeMessaging APIs to expose this functionality to web pages.
Check out function shell_exec. http://php.net/manual/en/function.shell-exec.php
There are several ways to do this. One way is to simply have your website store the current text somewhere and then build a script on the local PC that asks your website for the current text and updates the display. You can schedule that script to run periodically using the Task Scheduler.
This script can be as simple as this (assuming PHP is installed on your local PC):
<?php
$text = file_get_contents('https://example.com/current_text.php');
shell_exec('echo "' . $text . '" > \\.\LCLD9\');
If you don't have PHP installed and don't want to install it, you can probably do something similar in a Powershell script or in a plain old batch file.
Note that you probably want to add some extra checks to this, you don't want to accidentally clutter your display with a 404 error page, a 500 internal server error or a network error.
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
I want my program to start before the user logs into the computer. This means that I would like to start my program before the user logs into the computer by entering the password.
In fact my program is one which senses the person in front of the computer and get him logged into the computer using the password which would have already been provided by the user before. For this I would have to put up a screen during the log in process.
Also please help me out about how use the user password to get him logged in.
You need to install your program in such a way that it run as a service on operating system.
Using a third party tool like advanced installed, you could easily do this. Its as simple as a creating a wizard. Check here - http://www.advancedinstaller.com/user-guide/tutorial-java-service.html#preparing
Regarding your second goal, you perhaps want to build something like a 'Fingerprint login' which is common on laptop PC now-a-days.
In the same manner, you need to have some way to capture an identifying data of the user. say a face recognition through a webcam. Your service should get input from the webcam and able to identify the person. Then using the logon service of the operating system, it may supply the pre-input password to automatically login into the system.
We have a java process running as the local system user on windows that needs to access a file that is owned by another user on the system. From what I understand the local system user should have permissions to impersonate that user. To do this we pass the tid and pid of a program that is accessing the file and get the user information (a token) from that. Then we set the token on the current thread. Something like this:
DuplicateTokenEx(hToken,MAXIMUM_ALLOWED,NULL,SecurityImpersonation,TokenImpersonation,&hTokenDup);
SetThreadToken(NULL, hTokenDup);
Where hToken is obtained by opening the thread and then process via their ids.
The problem is when I try to access a file that is only accesible by the user and no one else I am unable to read it. I get an access denied error. So the question is whether or not I should be able to access this file via impersonation and if so is this the correct to impersonate another user given a threadid and pid. I guess also would I see different behavior between windows 7 and windows xp.
For starters, you should always test the return values of your Windows API calls.
Only then will you be sure that the token has indeed been copied and assigned to your process.
Impersonation requires some privileges, which I'm not really not sure you'd have if you're a simple user. I suspect the DuplicateTokenEx function fails.
Try again with administrator privileges (use the "Run as..." tool), and let us know how it goes.