Using java to run command line as %username%

Hi all,
can any one help with this?
I'm trying to run a command line from a database as %username% in Windows. So far I have the following script, courtesy of Frank Naude to build a java class that is published within a plsql procedure. A command line can then be passed to it.
rem -----------------------------------------------------------------------
rem Filename: oscmd.sql
rem Purpose: Execute operating system commands from PL/SQL
rem Notes: Specify full paths to commands, for example,
rem specify /usr/bin/ps instead of ps.
rem Date: 09-Apr-2005
rem Author: Frank Naude, Oracle FAQ
rem -----------------------------------------------------------------------
rem -----------------------------------------------------------------------
rem Grant Java Access to user USER1
rem -----------------------------------------------------------------------
conn sys/password@database as sysdba
EXEC dbms_java.grant_permission('USER1', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
EXEC dbms_java.grant_permission('USER1', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
EXEC dbms_java.grant_permission('USER1', 'SYS:java.io.FilePermission', '/bin/sh', 'execute');
EXEC dbms_java.grant_permission( 'USER1', 'SYS:java.io.FilePermission','C:\WINDOWS\system32\cmd.exe', 'execute' );
rem -----------------------------------------------------------------------
rem Create Java class to execute OS commands...
rem -----------------------------------------------------------------------
conn user1/password@database
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Host" AS
import java.io.*;
public class Host {
public static void executeCommand(String command) {
try {
String[] finalCommand;
finalCommand = new String[4];
finalCommand[0] = "C:\\WINDOWS\\system32\\cmd.exe";
finalCommand[1] = "/y";
finalCommand[2] = "/c";
finalCommand[3] = command;
// Execute the command...
final Process pr = Runtime.getRuntime().exec(finalCommand);
// Capture output from STDOUT...
BufferedReader br_in = null;
try {
br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String buff = null;
while ((buff = br_in.readLine()) != null) {
System.out.println("stdout: " + buff);
try {Thread.sleep(100); } catch(Exception e) {}
br_in.close();
} catch (IOException ioe) {
System.out.println("Error printing process output.");
ioe.printStackTrace();
} finally {
try {
br_in.close();
} catch (Exception ex) {}
// Capture output from STDERR...
BufferedReader br_err = null;
try {
br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
String buff = null;
while ((buff = br_err.readLine()) != null) {
System.out.println("stderr: " + buff);
try {Thread.sleep(100); } catch(Exception e) {}
br_err.close();
} catch (IOException ioe) {
System.out.println("Error printing execution errors.");
ioe.printStackTrace();
} finally {
try {
br_err.close();
} catch (Exception ex) {}
catch (Exception ex) {
System.out.println(ex.getLocalizedMessage());
show errors
rem -----------------------------------------------------------------------
rem Publish the Java call to PL/SQL...
rem -----------------------------------------------------------------------
CREATE OR REPLACE PROCEDURE host(p_command IN VARCHAR2)
AS LANGUAGE JAVA
NAME 'Host.executeCommand (java.lang.String)';
show errors
rem -----------------------------------------------------------------------
rem Let's test it
rem -----------------------------------------------------------------------
exec host('notepad');
The trouble is although this script works great for commands that can be run is the 'background' as SYSTEM is I want to pass a command to actually open something e.g. notepad in the above example nothing seems to happen. As far as I can make out the command line is running but not as %username% so it's not running notepad.exe in the foreground.
I'm happy to clarify more if necessary.
Can anyone help with this?
Cheers
Yog

Bill,
Thank you for the quick answer. I believe you are right in your assumption.
I have been searching but found nothing so far.
I need to be able to run this line "wmic
Product where name='XXX XXX XXX' call uninstall" 
in an elevated command prompt to uninstall the program.
I was looking for a VB script or PowerShell to execute it remotely on non domain roaming PCs.
Th3e command can be run remotely against stand-alone workstations but you must supply credentials.  Post in the platform forum for you version of Windows for help in using the WMIC utility.  WMIC /? will give you all of the command options fro
remote execution.  UAC only affects local systems.  You cannot use WMIC to remote back to the local system. WMIC does not allow impersonation to the local system.
Most installers will not automatically allow an unattended uninstall.  If there is any dialog at all the uninstall will fail and can hang.
I recommend contacting the vendor of the application to get more information.
In all cases you cannot bypass UAC as Bill has noted.  I am only noting that, sometimes, in a workgroup, you can use WMIC to remotely uninstall an application.
¯\_(ツ)_/¯

Similar Messages

  • "java.lang.UnsatisfiedLinkError" happen when I use java.exe in command line

    When I use Eclipse 3.01 to run the program it has any problem.But If I use the command line "java -classpath D:\Java_prj\Java\NativeMethod\out com.bruce.nativemethod.HelloNative",a error message will appear below:
    java.lang.UnsatisfiedLinkError: no ./out/com/bruce/nativemethod/ in java.library.path
         at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1403)
         at java.lang.Runtime.loadLibrary0(Runtime.java:788)
         at java.lang.System.loadLibrary(System.java:832)
         at com.bruce.nativemethod.HelloNative.<clinit>(HelloNative.java:21)My HelloNative.dll and HelloNative.class has all been putted in D:\Java_prj\Java\NativeMethod\out\com\bruce\nativemethod.
    My all source code is here:
    //HelloNative.java
    package com.bruce.nativemethod;
    import java.util.*;
    public class HelloNative{
         public static native void greeting();
         //Load the library
         static {
              System.loadLibrary("./out/com/bruce/nativemethod/HelloNative");
              //System.loadLibrary("HelloNative");
         public static void main(String args[]) {
              HelloNative.greeting();
    //HelloNative.c
    #include "HelloNative.h"
    #include <stdio.h>
    JNIEXPORT void JNICALL Java_com_bruce_nativemethod_HelloNative_greeting(JNIEnv* env,
        jclass cl)
        printf("Hello world!\n");
    //HelloNative.h
    //Generated by javah.exe
    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class HelloNative */
    #ifndef _Included_HelloNative
    #define _Included_HelloNative
    #ifdef __cplusplus
    extern "C" {
    #endif
    * Class:     HelloNative
    * Method:    greeting
    * Signature: ()V
    JNIEXPORT void JNICALL Java_HelloNative_greeting
      (JNIEnv *, jclass);
    #ifdef __cplusplus
    #endif
    #endifI thinked the code is not problem.But why I can't not run it use java.exe tool in command line?

    Thanks everybody! My problem has been solved.The path "./out/com/bruce/nativemethod/HelloNative" is right because it can run in Eclipse 3.01.I don't agree use the absolute path.If do so,it may not use in another machine. The problem is when I use the "java -classpath D:\Java_prj\Java\NativeMethod com.bruce.nativemethod.HelloNative" in the command line windows,I have putted it the C:\ directory to excute.laterly,I putted the command in the D:\Java_prj\Java\NativeMethod,the result "Hello world!" is appear.

  • Using computer variables in task sequence "Run Command Line"

    I am attempting to deploy VMs through VMware's vRealize Automation tool using CM. The process creates a CM computer object then creates a direct rule on a CM collection for the new computer object. During the creation of the computer object vRA creates computer
    variables provided by me on the computer object. I see the computer object built and i see the custom variables on the computer object:
    Name Value
    dns1 10.10.10.10
    dns2 10.10.10.11
    gateway 10.10.10.1
    ipAddress 10.10.10.2
    netMask 255.255.255.0
    In the task sequence the last step is to "Run Command Line":
    cmd /c netsh int ip set address name="Ethernet0" static %ipAddress% %netMask% %gateway% & cmd /c netsh int ip set dns name="Ethernet0" static %dns1% & cmd /c netsh int ip set dns name="Ethernet0" static %dns2% index=2
    When the TS gets to that step it doesn't substitute the variables in the command with the computer variables listed above. Looking at the smsts logs after the deployment is complete I see lines stating:
    Set Command Line:...
    Start executing command line:...
    Executing command line:...
    ProgramName = ...
    All of those lines show the command exactly as it is above with the %variables% intact.
    The command immediately fails with the error:
    Invalid address parameter (%ipAddress%). It should be a valid IPv4 address.
    Does anyone have a suggestion on why the TS isn't using the variables? I found this article https://technet.microsoft.com/en-us/library/bb693541.aspx but its for 2007 not 2012. I wasn't able to find something comparable for 2012.

    I don't know why anyone here thinks you *need* sccm osd to achieve fully automated customizations.
    Customer selects base image (2008 r2 core, 2008r2 gui, 2012 r2 core, 2012 r2 gui), which should be thin and with zero customizations anyway,
    vaai accelerated clone creates vm,
    ip addr/gateway/dns config is injected with powercli,
    customers config management engine agent of choice is installed via powercli script injection/execution (we have puppet users, ConfigMgr users, saltstack users, IEM users, Cheff users),
    the clone completes in ~2 minutes and a VM is presented to the customer in less than 5 minutes 
    Deploying windows VMs via SCCM OSD is not only slow, but requires dev work on the customer side to get things rolling which wastes everyone's cycles including your own

  • TS-Run Command Line-run as different user

    HI
    I needed to deploy one program which do not like SYSTEM account (do not installs). So I created TaskSequence with
    Run Command line and specified domain user which will be running this command.
    Is my domain users password safe or it will be provided in clear text in my network? Because this user must be Admin on local computer.

    Just to reinforce, the tasks use standard, core Windows APIs to impersonate the account and execute the command -- these APIs never send anything in clear text and if they did, then Windows has much bigger issues. It would actually take
    a huge amount of effort to not securely perform this operation.
    Jason | http://blog.configmgrftw.com

  • Using the Oracle Repository Command Line Tool under Linux

    I have to use the command lines of Linux for SCM commands(like repcmd,
    set workarea, checkin etc...)
    should I have to install something?
    I have documentation for using the oracle repository command line Toll
    for Windows and Unix, but I didn't found anything about using the oracle
    repository command line Tool for Linux.

    JDeveloper runs excellent on Linux and is supposed to be able to use the repository, but that's a GUI...

  • Compare two pdf files using adobe acrobat through command line

    Does anyone know how to compare two pdf files using adobe acrobat through command line. I want to do this via command line because we want to compare hundreds of file every day through some automated windows tasks.
    If command line option is not available in acrobat, then is it feasible to make use of acrobat javascript API to do this task?
    Any kind of help will be greatly.

    Command-line: Not possible.
    JavaScript: Possible, but very limited. Basically the only thing you can do is simulate clicking the Compare Documents button. The rest has to be done manually.
    However, it *might* be possible to automate this process a bit more using a plugin. Ask over at the Acrobat SDK forum for more information...

  • BO Edge 4.0 Installer stuck on "Run command-line executable"

    Hi,
    Our BO Edge BI Server 4.0 Installer on Windows Server 2008R2 is stuck on one of the last steps; "Run command-line executable".
    Before is was stuck on "WaitForCMSForTheFirstTime". We upped the RAM to 16GB and then the installer went past this, but after a full reset of the server and trying again it is now stuck a few steps later on "Run command-line executable". This is very frustrating, especially since there is no error message at all, no install log and the installer is just stuck indefinitely and we had to cancel it.
    At that point the Central Configuration Manager shows this:
    Apache Tomcat - Running
    BW Publisher Service - Stopped
    SAP BO Mobile Authentication Server - Stopped
    SAP BO Mobile Processing Server - Stopped
    Server Intelligence Agent - Running
    We can't deinstall from Windows to start over at this point because the installer says an install is in progress.
    What is going on?
    Help urgently needed and appreciated
    Edited by: J. Knulst on Jan 11, 2012 7:48 AM
    Edited by: J. Knulst on Jan 11, 2012 7:50 AM

    Hello,
    Yes, certain stages run for a long duration. "Run command-line executbale" runs for atleast 45 mins. It's normal.
    My suggestion would be to leave it for 45 mins-90 mins.
    Now that you have interrupted your installtion, try uninstalling it through the control panel.
    In case you can't see the software there, then you have to edit registry entries, which is very tiresome.
    Regards,
    Sonia

  • I can't find a class to run command line stuff...

    Does J2SE have the capability to run command line files/executable files? I need to run some things from command line on my local machine. This ap will be swing based. Thanks for any insight.
    nick

    that is what I need. I did not think to look there. Thanks so much.
    Nick

  • How to run executable Java app from command line: No Main( ) method

    This is the opposite question from what most users ask. I have the Java source code and a running Java executable version of the program in a windows environment. I don't want to run it in the normal way by double-clicking on it or using the executable. I need to be able to run the same application from the command line. If I can do this, I can then compile and run the code on my Mac, too, which is what I am ultimately trying to accomplish.
    Normally, this would be easy. I would look for a Main method, normally public static void main (String[] args ) or some variation. I cannot find a main() anything, anywhere when searching the files. There must be some windows executable that links to the Java classes. It's very clever, no doubt, but that's not helping me.
    I am trying to run what I can determine as the Main class, with a standard command line call, but that is not working either.
    It is a Java graphics program, so mostly Swing container stuff.
    I am not finding a manifest.txt file, telling me where a main method is, nor anything about the Main Class. There is no readme file for the program.
    Any insight that would point me in the right direction? What should I be looking for?
    Thanks in advance, Bloozman

    It's possible there's a clever Windows executable that runs the class. But if it's a plain old Java class then there's a good chance there's a constructor. Look for that; it's possible you may be able to start by writing another Java class that creates an instance of your mystery class.
    When you have that done, try running it. It's possible that just creating an instance might be sufficient to run it. Swing programs are sometimes written like that. If not, then start looking for methods with names like "run" or "go" or "start" that your little controller program can call.

  • Unable to build and run Javapetstore using  Sun SDK from Command Line

    Hi,
    Here is a problem I?ve come across building and running JavaPetstore from Command Line using Ant.
    It shows that Build is successful but there is an error message in very beginning:
    ?Unable to locate tools. jar. Expected to find it in C:\Program Files\Java\jre 1.5.0_11\lib\tools.jar?
    But there is no such a file in jre-1.5.0_11 or previous versions.
    The only place where the file with such name can be found is jdk\lib.
    All attempts to run end up with:
    ? BUILD FAILED.
    C:\<PETSTORE_HOME>\bp-project\command-line-ant-task.xml:77;unable to find javac compiler;com.sun.tools.javac.Main is not on the class path.
    Perhaps JAVA_HOME does not point to JDK."
    Directories C:\Sun\SDK\bin and C:\Sun\SDK\jdk are in the PATH.
    JAVA_HOME as a System variable is set up to C:\Sun\SDK\jdk.
    Building and running other applications like a BluePrints or Samples bring to same result.
    I will post more information if needed.
    Thank you in advance for help.

    If you are using Windows XP:
    1. Right click on my computer
    2. Select Properties from the popup dialog
    3. Click on the "Advanced" tab
    4. Click the button towards the bottom that says "Environment Variables"
    5. In the dialog that pops up, look in both the User variables and the System variables for a variable named CLASSPATH
    6. If its not there, you need to create it. If you want to make it available to all users of your computer, create it as a System variable. If you only want it to be available to the current user, add it as a User variable.
    7. If it is there, or if you just created it, it needs to contain the following values: the current directory (symbolically abbreviated as a period: "."), any class libraries you want to be available to the java compiler (javac) or the java interpreter (java). By default, jre/lib and jre/lib/ext are searched for classes, so you don't need to include anything located in one of these folders on the classpath.

  • Running java class in command line

    Hi.. i have a java class i want to run from the command line. the problem is that when i do, i get this exception:
    Exception in thread "main" java.lang.NoClassDefFoundError: (class name)
    The class uses some jars, so i used the -classpath option, and seperated the jars with ":".
    I read in a previous topic that the solution can be to add the JRE1.5.0 to the path.
    Can anyone tell me the syntax to do that? And if anyone has a different solution can they tell me? Im running it on linux debian.
    Thx.

    It sounds like you only have the jars in the -classpath option. If that's right, then java will only look in those jars for classes. You probably need for example .:jar1.jar:jar2.jar if you want java to look in the current directory as well as the jar files for classes.

  • [solved]can't run java apps from command line

    Every Java program that i've tried to run from command line gives me a error message like this:
    augusto java% java Test
    Exception in thread "main" java.lang.NoClassDefFoundError: Test
    Caused by: java.lang.ClassNotFoundException: Test
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    Could not find the main class: Test. Program will exit.
    `java Test.class` doesn't work too.
    but, the exact same code work from eclipse, am I missing something?
    Some info:
    % ls Test*
    Test.class Test.java Test.java~
    % cat Test.java
    public class Test{
    public static void main(String[] args){
    System.out.println("doesn't work");
    % echo $PATH
    /home/augusto/.bin:/home/augusto/.bin:/home/augusto/GNUstep/Tools:/opt/GNUstep/Local/Tools:/opt/GNUstep/System/Tools:/bin:/usr/bin:/sbin:/usr/sbin:/opt/java/bin:/opt/java/jre/bin:/usr/bin/perlbin/site:/usr/bin/perlbin/vendor:/usr/bin/perlbin/core:/opt/qt/bin
    Last edited by hack.augusto (2009-10-27 00:57:53)

    also make sure that you current directory is in your classpath.
    eg
    export CLASSPATH=".:$CLASSPATH"
    java Test
    your issue is more likely to be classpath related, as java doesn't read the path variable, and the java executable is found
    Last edited by bruce (2009-10-27 01:02:51)

  • Use java to run a shell script which called a crontab command at Unix

    I was trying to write an automate function using Java, which needs to call a shell script containing a crontab commend. The shell works fine without that crontab commend, but once I add it, the program won't execute that crontab commend.
    public void cron(){
    try
    Process proc = Runtime.getRuntime().exec("script1");
    BufferedReader br = new BufferedReader(new           InputStreamReader(proc.getInputStream()));
    String line;
    while ((line = br.readLine()) != null)
         System.out.println(line);
    int returnValue = proc.waitFor();
    br.close();
    } catch (Exception e){} //
    script1:
    #!/bin/sh
    crontab cronfile
    Can someone help me out for this? Thank you.

    Try this....
    Process p = Runtime.getRuntime().exec("sh");
    java.io.BufferedWriter bw = new java.io.BufferedWriter(new java.io.OutputStreamWriter(p.getOutputStream()));
    bw.write("script1");
    bw.flush();
    bw.close();

  • How to run command line argument programe

    Hi guys, I am doing pass command line argument programe in java but I don't know how to run this programe. Path for this programe in my my computer is C:\Users\Desktop\Mainjava\mycode\CommandProgjava*
    {code/}
    public class CommandProg
    public static void main(String[] args)
    System.out.println("d");
    for (int i = 0; i < args.length; i++)
    System.out.println(args);
    {code/}
    Where i need to go and what command i need to give so i can execute this programe(I am using window vista). I only know i have to give
    this command some where CommandProg arg1 arg2 arg3 arg4. Output should be
    Output:
    arg1
    arg2
    arg3
    arg4
    Please help me, Thanks in advance.
    Edited by: JayVirk on Dec 30, 2007 11:33 AM

    Jay,
    Your question isn't very clear, hence Joerg's well meaning but irrelevant advise.
    Do you mean:
    I've written a simple program in java which echos
    it's command-line arguments to back to the console.
    Here's my code:
    package forums;
    public class ArgsEchoer
      public static void main(String[] args) {
        for (String arg : args) {
          System.out.println(arg);
    But can't figure out how to compile and run the program.
    I'm using winblows shista, and it's cr@p.
    Please help me, Thanks in advance.So... where are you at? Have you installed the JDK (java development kit)? Which version? Is your path set? Is your classpath set?
    Start here: http://java.sun.com/developer/onlineTraining/new2java/

  • How to run command line tool in my program???

    Hi,all,I've got some tools that are usually,or take JDK for example,if we are not using an IDE,we need to open the command prompt,and then use the javac command to compile the source files and the "java "command to run the program,and both of them accept some command line params.The problem is that how could i integrate the tools in my own program,like JBuilder or some other IDE,you configure the params and compile and run in the IDE which don't need to open a command line prompt.Hope i have got my question clear:)
    Best regards..

    jesperdj ,thanks:)
    actually,i am using eclipse to run my ant tasks programmatically,but I got trouble with the AntRunner class.it seems that i should config a proper classloader for it,but i just don't know how.please lend a hand:)thanks
    robin

Maybe you are looking for

  • Mac freezes on finder

    My Imac boots up but it freezes on the finder. I can navigate via the key board and my mouse works,, but no programs will open.  I cannot open time machine to revert back to when it was working correctly I have a dialog box asking me if i want to ena

  • MegaPlayer 5538 problems with Win98SE

    Hi, I got a MegaPlayer 5538 with 1GB SD-Card. It works fine with Windows XP, but I have some problems with it running on Windows 98 SE. I tried to install it on three different Win98 SE PCs, but was only successful with one. On the other two I cannot

  • JAXB: Shared objects across multiple xsds

    Hi all, Have three xsd files which all contain a few shared classes, I use xjc to put each one into a different package, and then of course they're incompatible with each other. I've tried placing all generated code in one package but the object mana

  • RemoteException   vs   EJBException

    Hi In EJB 2.0 specification, it is mentioned that the use of java.rmi.RemoteException was deprecated for container-invoked callbacks (like ejbCreate, ejbPassivate, ejbActivate) and must use javax.ejb.EJBException instead. But when I create a new EJB

  • HT204266 Why did my lock button suddenly stop working?

    I just recently bought the Iphone 5. Its only been a couple of months and my lock button suddenly stopped working. My Iphone 5 isnt the only one that has done this, I know many other people whose phones have done the same thing. Does anyone know why