Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 26 days ago.
The community is reviewing whether to reopen this question as of 26 days ago.
Improve this question
I am working on a JavaFX project. At some point in the program I need to ask the user for elevated rights to perform a certain action.
How can I code this action?
My program is coded to work on Windows 10.
My program does not need any permission to work in the usual operation, only for this action is needed.
My program detects some devices that I have designed. The problem I have is that sometimes I need to change the VLAN ID of my network card. To do this I do it as follows:
public void VlanChanged (int vlanId) {
StopDeviceSearch();
try {
Runtime rt = Runtime.getRuntime();
String cmd = "cmd /c \"Echo S|powershell set-netadapter -InterfaceDescription 'Killer E2400 Gigabit Ethernet Controller' -VlanID " + vlanId + "\"";
rt.exec(cmd);
} catch (Exception e) {
System.out.println (e);
}
RestarDeviceSearch();
}
If I run myProject.jar as administrator the above code works correctly, but if I don't run it as administrator the above code doesn't work.
Could I run my program and when the user activates the "VlanChanged" function that my program asks the user for administrator permissions to run CMD as administrator and be able to perform the VLAN ID change action correctly?
I have tried with the command
"runas /profile /user: Administrator"
but it doesn't work.
I would like the Windows banner to be opened that asks you:
"Do you want to allow this application to make changes to the device?"
That the window has the title: "User Account Control".
I have been searching and I just want the "UAC dialog".
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
In my Test script have to write waiFor(5) for every excution, else Test fails.
Am using POM, and have separate class.
#Test(priority=2)
public void TestMedical() throws InterruptedException {
waitFor(5);
MedicalPage medicalpage = new MedicalPage(driver);
waitFor(5);
medicalpage.PhysicianName(Repo.getProperty("fName"));
medicalpage.seteditableLastName(Repo.getProperty("lName"));
waitFor(5);
medicalpage.setPhone(Repo.getProperty("Phone"));
waitFor(5);
medicalpage.setEmail(Repo.getProperty("Email"));
}
This is my Login Page (Object)-
// Created methods in this page, and using Testng trying to call all the below methods. But getting failure message Unable to Locate Element, If there is no wait time watFor(5). With Wait time its running fine.In base page have explicit wait time method, but its not working. After input the data in text field when i click on submit button page is doing some Java Script or Ajax.
Ajax call takes 60 sec max.
driver.findElement(firstName).click();
driver.findElement(editableFirstName).clear();
driver.findElement(editableFirstName).click();
driver.findElement(editableFirstName).sendKeys(fName);
}
Added try - catch, works fine now
WebElement element = driver.findElement(XYZ);
boolean clicked = false;
do{
try {
element.click();
} catch (WebDriverException e) {
continue;
} finally {
clicked = true;
}
} while (!clicked);;
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm trying to write an extension for OpenOffice.
This extension would be written in java (compiled, I don't want people to see the code).
It should do actions when I start openOffice writer, when I click on a button and when I print.
I've already added the button but I can't find how to link it with the code of what it should do.
I've read the wiki and the DevGuide but I don't find it very clear.
Could you please help me to start understanding how to create an extension (where should I put my code, how to link it with the GUI etc...)?
As an example, follow instructions at https://wiki.openoffice.org/wiki/OpenOffice_NetBeans_Integration#Configuration. Install the Apache OpenOffice API Plugin by going to Tools -> Plugins.
Click on the link that says OpenOffice.org Add-On Project Type to get more instructions. If you haven't yet, download AOO 4.1.2 and the AOO 4.1.2 SDK. (The plugin did not work for me using LibreOffice, but the resulting extension did work in LibreOffice).
After the code is generated according to the instructions, then add this code to the dispatch method of TestAddOn.java:
if ( aURL.Path.compareTo("HelloWorld") == 0 )
{
// add your own code here
com.sun.star.frame.XController xController = m_xFrame.getController();
if (xController != null) {
XModel xModel = (com.sun.star.frame.XModel) xController.getModel();
XTextDocument xTextDocument = (com.sun.star.text.XTextDocument)
UnoRuntime.queryInterface(XTextDocument.class, xModel);
XText xText = xTextDocument.getText();
XTextRange xTextRange = xText.getEnd();
xTextRange.setString( "Hello World (in Java)" );
return;
}
}
Now compile and deploy the extension. When the "Hello World" toolbar button is clicked, it should put "Hello World (in Java)" in the document.
The code was adapted from https://forum.openoffice.org/en/forum/viewtopic.php?f=47&t=72459.
In order to handle events like when the document is opened, I also tried calling a method of the extension from Basic code like this:
Sub CallJavaMacro
MSPF = createUnoService("com.sun.star.script.provider.MasterScriptProviderFactory")
scriptPro = MSPF.createScriptProvider("")
xScript = scriptPro.getScript("vnd.sun.star.script:" & _
"com.example.testaddon.TestAddOn.PutHello?" & _
"language=Java&location=user:uno_packages/TestAddOn.oxt")
Thing = xScript.Invoke()
End Sub
However the Basic routine said it could not find the method. Maybe I did not declare the method properly or something.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Can you help me figure out how to make it so my app has users check mark an I agree box before my app goes to the main menu? I need it to only show this screen the very first time the user uses the app. I am new to android studio so any help would be appreciated.
Thanks!
You can easily use SharedPreferences to accomplish this. try doing something like:
final String PREF_NAME = "MyPref";
// getting saved preferences
SharedPreferences settings = getSharedPreferences(PREF_NAME, 0);
if (settings.getBoolean("my_first_time", true)) {
//the app is being launched for first time, do something
Log.d("Comments", "First time");
// first time task
runUserAgreements();
// record the fact that the app has been started at least once
settings.edit().putBoolean("my_first_time", false).commit();
}
Then declare a function named runUserAgreements() and run an activity or dialog showing User Agreements and stuff.
EDIT:
I suggest to put above code in a class extending Application
to check firstrun generally not in the default activity:
public class MyApp extends Application {
#Override
public void onCreate() {
super.onCreate();
// CODE HERE
}
}
and DO NOT forget to call the class in AndroidManifest.xml:
<application android:name=".MyApp"
android:label="#string/app_name"
.
.
...>
....
</application>
Take a look at the Google's iosched project example, specifically this Activity: Welcome Activity. IMHO it has a pretty good UI design too.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
My application contains an upload option from which the user can upload files(any file).
I know that users have the ability to write code/scripts in excel worksheet.So how can i prevent that from happening as it can lead to security breach.
Or what check can i apply to know that the uploaded worksheet contains any function?
I assume from the Java tag that your appliction to which the sheet gets uploaded is a Java application.
Using Apache POI, you can use a POIFSReader (see this doc) to read the file on a lower level.
There is an example by RĂ©al Gagnon which shows how you can check the content by looking at the name.
I had to modify the listener (added another comparision)
class MacroListener implements POIFSReaderListener {
[...]
#Override
public void processPOIFSReaderEvent(POIFSReaderEvent event) {
System.out.println(" Event: Name " + event.getName() + ", path "
+ event.getPath());
if (event.getPath().toString().startsWith("\\Macros")
|| event.getPath().toString().startsWith("\\_VBA")
|| event.getPath().toString().contains("_VBA_")) {
this.macroDetected = true;
}
}
}
so that it worked for some test files. You might have to tune/extend the checks.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am new in Android.
I was working for uploading Image/Video on Twitter. I used the twitpic for this purpose.
I first sent image to twitpic and then updated the status in twitter with url of the tweet.
Image is successfully loading as per my selection from gallery.
But I am stuck in uploading video on Twitter. As there is option of twitpic or twitvid for uploading video. But there is no such type of code or sdk given. So confused that how to do this, which classes has to be used.
I need a sample code for uploading video.
Was stuck on this for a while myself as well (not a lot of examples around) and found a non-working example here on SO which I've managed to hammer into shape...
First you'll need the twitvid Java API
1 download the jar file (I used twitvid-java 1.6.1)
2 put it in your "libs" folder
3 right-click on your project and go to "properties"
4 select "Java build path" and include the jar ("libraries" tab) and make sure it's built ("order and export" tab)
The code that follows assumes you've already made a token with the regular twitter4j methods:
private void postToTwitvid(String videoPath){
AccessToken token = mTwitter.getAccessToken();
Values values = new Values();
values.setSession(new Session());
TwitvidApi api = new TwitvidApi(values);
api.setSecureUrlEnabled(false);
Session session;
try {
session = api.authenticate(new TwitterAuthPack.Builder()
.setConsumerKey(twitter_consumer_key)
.setConsumerSecret(twitter_secret_key)
.setOAuthToken(token.getToken())
.setOAuthTokenSecret(token.getTokenSecret())
.build());
api.getValues().setSession(session);
final UploadHelper helper = new UploadHelper(api);
File file=new File(videoPath);
TwitvidPost twitvidPost = new TwitvidPost.Builder()
.setFile(file).setChunkSize(10485760)
.setMessage("Twitvid test")
.setPostToTwitter(true)
.create();
try {
if (helper.upload(twitvidPost))
{
Toast.makeText(TwitterShare.this, "Posted on Twitter and Twitvid", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(TwitterShare.this, "Post failed", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (ApiException e1) {
e1.printStackTrace();
}
}
The token depends on how you've implemented the regular posting to twitter, just include yours.
Hope this helps!
PS: I had to force the UI thread to accept network connections to make this work
(My first answer! w00t!)