Run macro on other computer

Syntax

int net(computer password macro [retval] [arg1 ...])

 

Parts

computer - name or IP address (e.g. "125.45.245.1") of the remote computer.

password - password that is required to run macros on the remote computer. It is the password that is set in remote computer's Network dialog in QM Options. Can be "" for macros that the remote computer allows to run without a password. Can be encrypted (in Options -> Security, use "net" as function name) (QM 2.1.8.5).

macro - name of a macro or function on remote computer. If macro begins with \, it is interpreted as QM item path. For example, to find macro "Next" that is in "Mouse" folder, you can use "\Mouse\Next".

retval - str variable that receives the return value of the macro. The macro can return a numeric or string value.

arg1 ... - up to 31 string or numeric values. The macro receives them as arguments (function).

 

Remarks

Launches a macro or function on other computer in local network or Internet. If retval is used, waits until the macro ends.

 

The return value is 0 or an error code:

0 the macro was started successfully. If retval is used, the macro ran successfully, unless it was terminated by the user, in which case the retval variable is empty or "0".
1 computer not found.
2 could not connect. For example, the remote computer is not running, or not connected to the network or Internet, or QM is not running, or QM does not allow to run macros from other computers (Options -> Network -> Allow ... is unchecked on remote computer), or the remote computer is on the Internet and uses a firewall, or different port is specified, or the port is in use.
3 password incorrect, or, if password is "", this macro is not allowed to run without a password.
4 macro not found.
5 could not start the macro. For example, it contains errors, or other macro is running.
6 could not send arguments. The macro did not run.
7 could not retrieve the return value. The macro ran successfully.
8 run-time error in the macro.

 

The _command variable of the macro that runs on the remote computer contains caller computer's IP address.

 

Initially, accessing QM from other computers is disabled. You can enable this feature in the Options -> Network. You don't have to enable it on your computer if you only want to run macros on other computers (to use net).

 

You can see your computer's name and IP addresses in Options -> Network. You can change computer name in My Computer's Properties.

 

Both computers must use the same port. QM port number is displayed and can be changed in the Network dialog. Initially it is 8177. If it conflicts with other applications, etc, you can change it. Recommended values are between 5000 and 65000. If QM on the remote computer uses a different port, you can specify the port number in computer, using syntax computer:port (e.g., "125.45.245.1:8178").

 

If your Internet connection uses a firewall or other security features, QM may be inaccessible from the Internet or even from your network. You would have to configure a firevall to allow incoming connections on QM port. To configure Windows XP (prior to SP2) Internet Connection Firewall, right-click your connection in Control Panel -> Network Connections, click Properties, Advanced, Settings, Add, type QM as service description, enter your computer name or 127.0.0.1, and enter QM port. If you have Windows XP SP2 or later, it is done automatically if you click Unblock in the Windows Security Alert dialog when QM network features are enabled first time. If you click Keep Blocking, QM cannot be accessed from network too. You can configure firewall to allow accessing QM only from your network. You must be logged on as administrator to do this.

 

To identify a computer on the Internet, is used different IP address than in local network. You may see two IP addresses in the Network dialog. One can be used to access your computer from other computers in the local network, other - from the Internet. The Internet IP often is dynamic, that is, your Internet Service Provider assigns your computer a different IP address each time you connect to the Internet.

 

To send a local macro to a remote computer, you can use the NetSendMacro function, which runs the NewItem function (same as newitem) on the remote computer. You can also send and receive files. See the examples.

 

To control a remote computer visually, use Windows XP Remote Desktop or other remote control software.

 

See also: network setup, shared files, mac

 

Examples

 run function NetworkMessage on computer John, and pass "Hello!" as argument
net "John" "passw555" "NetworkMessage" 0 "Hello!"

 function NetworkMessage (on computer John)
function $message
mes message
 ______________________________________

 get file from another computer
int r
str s
r=net("123.234.35.1" "pppassw" "net_GetFile" s "$personal$\test.txt")
if(r or !s.len) end "failed" ;;the remote macro net_GetFile did not run or did not return the requested file
s.setfile("$personal$\test.txt") ;;save it on this computer

 function net_GetFile
function'str $file_
str s.getfile(file_)
ret s
 ______________________________________

 send file to another computer
int r
str data.getfile("$personal$\test.txt")
str sr
r=net("123.234.35.1" "pppassw" "net_SetFile" sr "$personal$\test.txt" data)
if(r or sr!="1") end "failed" ;;the remote macro net_SetFile did not run or did not return 1

 function net_SetFile
function# $file_ str'data
data.setfile(file_)
ret 1
 ______________________________________

 send and run function Function7 on Computer3
str c("Computer3") p("p765") m("Function7")
if(NetSendMacro(c p m)) end "could not send"
if(net(c p m)) end "could not launch"
 ______________________________________

 This macro upgrades QM on several computers.

str setupfile="$desktop$\quickmac.exe" ;;QM setup program. Macro will send and run it on each computer.
str computers="computer1[]computer2[]computer3" ;;list of computers
str password="passw" ;;assume, all computers use same password (Options -> Network)
str cmdline="/silent" ;;install without the setup wizard, using the same settings as when installing last time

str c sd.getfile(setupfile)
int r

str sm=
 function str'filedata $cmdline
 str temp="$temp$\quickmac.exe"
 filedata.setfile(temp)
 run temp cmdline

foreach c computers
	r=net(c password "NewItem" 0 "NetUpgradeQm" sm "Function" "" "\User\Temp" 17) ;;send macro that receives and runs setup file
	if(!r) r=net(c password "NetUpgradeQm" 0 sd cmdline) ;;if ok, run the macro
	if(r) out "Cannot upgrade QM on %s (error %i)" c r
	else out "QM upgraded on %s" c