Sunday 3 June 2012

DOS Tricks in JAVA

One of the most important DOS command is tasklist command.We can perceive this command in many ways.

"tasklist" is a DOS command that displays the running processes in the Windows OS.It displays all the applications and services running with their PID(process ID).


Syntax

tasklist[.exe] [/s computer] [/u domain\user [/p password]] [/fo {TABLE|LIST|CSV}] [/nh] [/fi FilterName [/fi FilterName2 [ ... ]]] [/m [ModuleName] | /svc | /v]

ParametersUses
/S systemSpecifies the remote system to connect to.
/U [domain\]userSpecifies the user context under which the command should execute.
/P [password]Specifies the password for the given user context. Prompts for input if omitted.
/M [module]Lists all tasks currently using the given exe/dll name. If the module name is not specified all loaded modules are displayed.
/SVCDisplays services hosted in each process.
/VDisplays verbose task information.
/FI filterDisplays a set of tasks that match a given criteria specified by the filter.
/FO formatSpecifies the output format. Valid values: "TABLE", "LIST", "CSV".
/NHSpecifies that the "Column Header" should not be displayed in the output. Valid only for "TABLE" and "CSV" formats.


Filters
Filter NameValid OperatorsValid values
STATUSeq, neRUNNING | NOT RESPONDING | UNKNOWN
IMAGENAMEeq, neImage name
PIDeq, ne, gt, lt, ge, lePID value
SESSIONeq, ne, gt, lt, ge, leSession number
SESSIONNAMEeq, neSession name
CPUTIMEeq, ne, gt, lt, ge, leCPU time in the format of hh:mm:ss.hh - hours,mm - minutesss - seconds
MEMUSAGEeq, ne, gt, lt, ge, leMemory usage in KB
USERNAMEeq, neUser name in [domain\]user format
SERVICESeq, neService name
WINDOWTITLEeq, neWindow title

MODULES

eq, ne

DLL name

 


Now let us see how we can make utilization of this command with the help of some examples:-

  •  tasklist /s Computer
tasklist /s
Process info of local/remote System
  • tasklist -v
  • tasklist -fi
tasklist -fi
Filter Result of tasklist
  • tasklist -v -fi "ImageName eq VLC.exe" /fo csv
To get VLC Windows Title


CODE SNIPPET to get current sound Track name in VLC


public String CallMe()
{
  Runtime runtime = Runtime.getRuntime();
           String cmds[] = {"cmd", "/c", "tasklist","/v","/fi","ImageName eq VLC.exe","/fo","CSV"};
           Process proc;
           String val = null;
try {
proc = runtime.exec(cmds);
           InputStream inputstream = proc.getInputStream();
           InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
           BufferedReader bufferedreader = new BufferedReader(inputstreamreader);
           String line;
           int count = 0;
while ((line = bufferedreader.readLine()) != null) {
   if(count==1)
   {
   String[] a = line.split(",");
val = a[9];
   }
   count++;
   }
} catch (IOException e) {
e.printStackTrace();
}
return val;
}


This can be used to set curent soundtrack as your GTalk status by using SMACK api to communicate with GOOGLE.
This will be explained in more depth in my next Blog.

No comments:

Post a Comment