AnonymousDev
AnonymousDev

Reputation: 247

Run cmd as administrator using Java Code

I want to execute the following mysql query, using java code:

mysqldump -uroot -ppassword temp1>C:\abc.sql

After a lot of search I found out that this needs cmd to run as admin I don't know how to run as admin using java code. I tried this but it doesn't work

runtimeProcess = Runtime.getRuntime().exec(new String[] { "runas /profile /user:Administrator \"cmd.exe", executeCmd });

Does any one has any idea regarding this. Thanks in advance.

Upvotes: 3

Views: 7613

Answers (1)

cshu
cshu

Reputation: 5944

You can use runas /savecred to execute, but I suggest you use JNI instead:

CreateProcessWithLogonW

CreateProcessAsUser

You can find examples here:

http://blogs.msdn.com/b/alejacma/archive/2007/12/20/how-to-call-createprocesswithlogonw-createprocessasuser-in-net.aspx

Upvotes: 1

Related Questions