Thursday, July 9, 2009

Send Popup Message to all Logged in Oracle APPS users

Requirement : - To send Popup Message to all Logged in Oracle APPS user

First I use below query to find the user_name of Logged in user.

select distinct d.user_name
from apps.fnd_logins a,
v$session b,
v$process c,
apps.fnd_user d
where b.paddr = c.addr
and a.pid=c.pid
and a.spid = b.process
and d.user_id = a.user_id
and (d.user_name = 'USER_NAME' OR 1=1)

You all can user above query and make JDBC connection to get user_name.

To Send Message to user I have used net send command :

Uses of net send Command
------------------------------

net send username/IP Address/machine name "Test Message"

Now I have tried to access Machine name from Active Directory Service and It may possible the
Single person is having one or more machine registered on his/her name. Then below jave programming section will return all machine name for single user.


Hashtable env = new Hashtable();
String adminName = "Your Domain Name\\Your user ID";
String adminPassword = "Your Login Password";
String ldapURL = "ldap://your domain URL.com:389";
String searchFilter=null;
String searchBase = null;
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.SECURITY_AUTHENTICATION,"simple");
env.put(Context.SECURITY_PRINCIPAL,adminName);
env.put(Context.SECURITY_CREDENTIALS,adminPassword);
env.put(Context.PROVIDER_URL,ldapURL);
LdapContext ctx = new InitialLdapContext(env,null);
SearchControls searchCtls = new SearchControls();
String returnedAtts[] = {"sn", "givenName", "mail"};
searchCtls.setReturningAttributes(returnedAtts);
searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
searchFilter = "(&(objectClass=computer)(CN=*"+Place search user id+"*))";
searchBase = "DC=your domain,DC=,DC=com";
NamingEnumeration answer = ctx.search(searchBase, searchFilter, searchCtls);
while (answer.hasMoreElements()) {
SearchResult sr = (SearchResult)answer.next();
// You can place your own logic to find out machine name to index out
String Machine = sr.getName().substring(sr.getName().indexOf("=")+1,sr.getName().indexOf(","));
}


Now we have got machine name from above process in Machine variable.

Please below java logic to send message.


try
{
int i=0;

String[] command = new String[3];


command[0] = "cmd";
command[1] = "/C";
command[2] = "net send "+ Machine+"Your Message";


i++;
Process p = Runtime.getRuntime().exec(command);
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));

BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));


String s = null;
System.out.println("Here is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}

// read any errors from the attempted command

System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}


}

catch (Exception e)
{
System.out.println(e);
}

}

}
select.close();
con.close();
}
catch( Exception e ) {
e.printStackTrace();
}

Thats All. Enjoy :)









No comments:

Post a Comment