home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2004 April
/
PCWorld_2004-04_cd.bin
/
software
/
temacd
/
remotany
/
RemotelyAnywhere.msi
/
Processes.sma
< prev
next >
Wrap
Text File
|
2003-08-19
|
5KB
|
183 lines
////////////////////////////////////////////////////////////////////////////////
// //
// RemotelyAnywhere Sample 'SMALL' Scripts //
// //
// RemotelyAnywhere provides a mechanism for scripting via a built-in //
// language. The language is called Small, and more information about //
// it can be found at http://compuphase.com/small.htm. //
// //
// Before you use these sample scripts, you should tailor their //
// behavior to better suit your configuration and your needs. //
// //
// THIS SOFTWARE IS PROVIDED BY 3AM LABS LTD ``AS IS'' AND //
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE //
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE //
// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE //
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL //
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS //
// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) //
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT //
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY //
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF //
// SUCH DAMAGE. //
// //
////////////////////////////////////////////////////////////////////////////////
#include <ra>
public main()
{
new pid, name[64], cpu, mem;
htmlBeginOutput("Processes");
//
// Check whether process enumeration was successful
//
if (raEnumProcs()) {
htmlBeginTable("PID", "Name", "CPU", "Memory");
//
// Loop through each process
//
new num=raGetProcessNum();
for (new i=0; i<num; i++) {
new tmp[20];
raGetProcess(i, pid, name, cpu, mem);
//
// Format process information
//
htmlBeginTableRow();
sprintf(tmp, "%d", pid);
htmlTableCell(tmp);
//
// Show process name as a link to a callback "callb"
// and pass the "tokill" parameter with the PID
//
htmlBeginTableCell();
htmlCBLink(name, "callb", "tokill", tmp);
htmlEndTableCell();
sprintf(tmp, "%d", cpu);
htmlTableCell(tmp);
sprintf(tmp, "%d", mem);
htmlTableCell(tmp);
htmlEndTableRow();
}
htmlEndTable();
raEnumProcsClose();
} else {
htmlWrite("Failed to show process list<BR>");
}
//
// Show the input form to execute a process
//
htmlBeginForm();
// Show an edit field named "cmd"
htmlEdit("cmd", "dir c:\\");
// Show a button to call the "exec" function
htmlButton("Execute", "exec");
// Show a button to go back to the Scripts page
htmlButtonBack("Back", false);
htmlEndForm();
htmlEndOutput();
}
//
// Callback function to kill a process
//
public callb()
{
htmlBeginOutput("Kill process");
new buf[256]="", buf2[256];
//
// Get the "tokill" parameter: the PID of the process to be killed
//
htmlGetParam("tokill", buf);
if (raKillProcess(atoi(buf)))
sprintf(buf2, "Process with pid %s has been killed<BR><BR>", buf);
else
sprintf(buf2, "Can't kill process with pid %s<BR><BR>", buf);
htmlBeginForm();
htmlBeginDialog("Result");
htmlWrite(buf2);
htmlButton("Back", "main");
htmlWrite("<BR><BR>");
htmlEndDialog();
htmlEndForm();
htmlEndOutput();
}
//
// Callback function to execute a command
//
public exec()
{
new cmd[256], out[1024];
htmlBeginOutput("Execute command");
//
// Get the "cmd" parameter: the command to be executed
//
if (htmlGetParam("cmd", cmd)) {
//
// Execute "cmd", load its output to "out"
//
if (raExecuteCmd(cmd, out, 1024, 10000)) {
new msg[128];
sprintf(msg, "\"%s\" returned:<BR><PRE></CENTER>", cmd);
htmlWrite(msg);
// The output need to be converted to html format
// so we pass "true" in the htmlize parameter
htmlWrite(out, true);
htmlWrite("</PRE><CENTER><BR><BR>");
} else {
sprintf(out, "Failed to execute \"%s\"<BR><BR>", cmd);
htmlWrite(out);
}
}
//
// Show back button
//
htmlBeginForm();
htmlButton("Back", "main");
htmlEndForm();
htmlEndOutput();
}