ok dudes,

There have been times in the past when I have wanted to issue commands to a server or workstation, but couldn't because I was not on the network... so

Here is a system where you can email commands to a computer and it will do them:

What you need:
1: A PC running MS Outlook Express(OE)(you can prob use OutLook or other MS mail product, but I have only tested this on Express)

2: This script running on a (semi)regular basis. Use AT on NT or that scheduler program on win9x.

Setup:
1: Create a folder in OE called RER (or whatever you like, but remember it and change the KiX script to suit)

2: Create a RULE in OE that MOVEs all mail with the SUBJECT "Remote Execution Request" to the aforementioned folder. Again, you can change this, but you must change the KiX script too...


How it works:

The script goes to the registry to get the path to your OE folders. If this doesn't work for you, check your registry and get the correct path.

So far, this only works when someone is logged in, so if you want to use this scriupt for an unattended server, login and lockup...Also, OE must be running.

When a new email comes in, OE puts it in our folder and stores email in clear text (well mine does) and the KiX script uses the FIND command to search the folder for any email with the subject line as defined in the script $subject.

If KiX finds an email with the subject, it then scans that email message for a line starting with :: if this is found, the command is taken from that line and run.

So, if you email that computer a message like this:

From: chrismat@ozemail.com.au
To: chrismat@ozemail.com.au
Subject: Remote Execution Request
Body:

Hello,

Please run these commands for me on \\server
::del c:\temp\*.txt
::net send chrism "all done"

thanks, cj

when the script runs, the two commands will be executed and then the email deleted.

If you delete the OE folder file, it re-creates it when a new message comes in.

Note: You cannot run the script if you are browsing in that folder in OE... as the folder file is locked.

ok, well here is the script...

cj

P.S. any questions?

code:

cls
break on

;
; this program will search for commands from a MS Outlook Express
; mailbox and execute them
;
; The commands must be in an email with a subject line "Remote Execution Request"
; Then each command line must start with ::
;
; An example email:
;
; From: chrismat@ozemail.com.au
; To: chrismat@ozemail.com.au
; Subject: Remote Execution Request
; Body:
;
; Hello,
;
; Please run these commands for me on \\server
;
; ::del c:\temp\*.txt
; ::net send chrism "all done"
;
; thanks, cj
;

; get $source from registry at
;
; HKEY_CURRENT_USER\Identities\{DF8CC2CB-493E-418E-824A-EB4A086C003D}\Software\Microsoft\Outlook Express\5.0
;
; The {DF8CC2CB-493E-418E-824A-EB4A086C003D} might be for me only...
; so have a look in the reg on your PC.
$path=readvalue("HKEY_CURRENT_USER\Identities\{DF8CC2CB-493E-418E-824A-EB4A086C003D}\Software\Microsoft\Outlook Express\5.0", "Store Root")
; other vars and constants
$source=$path+"RER.dbx" ; MS Outlook Express folder that contains the email
$subject="Subject: Remote Execution Request" ; required subject line - case sensitive!!
$command="::" ; the chars that the commands follow
$output="c:\scan.txt"

; delete previous failed use of this program
del "$output"

; search mailbox for command email
shell 'cmd /c find "$subject" $source > $output'

; if $output is 0 bytes then FIND couldn't find the file
if getfilesize($output)=0
exit
endif

; open scan file
$=open(1, "$output")
if @error<>0
"Error @error occurred accessing $output:" ?
"@serror" ? ?
exit
endif

$bFound="false"
$search=readline(1)
while @error=0
if $search=$subject
$bFound="true"
endif
$search=readline(1)
loop

if $bFound="false"
? "No Remote Execution Requests found, aborting."
$=close(1)
del "$output"
exit
endif

$=close(1)

; found the subject, now look for commands
shell 'cmd /c find /i "$command" $source > $output'

$bFound="false"
$=open(1, "$output")
$search=readline(1)
while @error=0

if instr($search, $command)=1
$bFound="true"
$strip=substr($search, 3, len($search)-2)
shell "cmd /c $strip"
endif
$search=readline(1)
loop

if $bFound="false"
? "No Commands found, aborting."
else
? "Commands executed."
endif

$=close(1)
del "$output" ; delete our text file
del "$source" ; delete the mailbox folder