Changing User Environment with ProcessBuilder + java -


i'm trying change user of child process user minor privileges when execute start method of processbuilder subprocess exec same user of parent

        linkedlist<string> commands = new linkedlist<string>();         commands.add("vlc");         processbuilder builder = new processbuilder(commands);         map<string,string> enviroment = builder.environment();         enviroment.clear();                     enviroment.put("user", "otheruser");         enviroment.put("logname", "otheruser");         enviroment.put("pwd", "/home/otheruser");         enviroment.put("home", "/home/otheruser");         enviroment.put("username", "otheruser");         enviroment.put("shell", "/bin/false");         builder.directory(new file("/home/otheruser"));                      process process = builder.start();         process.waitfor(); 

i'm working in linux(ubuntu)

jim absolutely right. if still want run program different user have user platform dependent tools.

windows: use runas command, e.g.: runas /user:domain\jamesbond regedt32.exe unfortunately runas requires user type password manually. following article explains how work around problem: http://www.windowsnetworking.com/kbase/windowstips/windowsxp/admintips/miscellaneous/runprogramsasanotheruserinwindows2000windowsxp.html

alternatively can write own utility in vbs , run java. see post details: http://weblogs.asp.net/hernandl/archive/2005/12/02/startprocessasuser.aspx

unix: see reference of su , sudo. su fine requires password (unless current user root). work around can create expect script (see http://en.wikipedia.org/wiki/expect). expect installed on unix distributions default.

good luck!


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

c# - How to execute a particular part of code asynchronously in a class -

c# - Asterisk click to call -