Script Commands for Windows Desktop Classic Devices

Use the options and examples below to help you create your own powerful script commands.

Note: Not all script commands are compatible with all devices within a platform. Limitations are noted in the table entries.

Legend

Format Meaning
text Enter the command exactly as shown.
text Replace with the requested information.
[text] Information contained within square brackets is optional to the command.
text|text Choose one of the options separated by the vertical pipe.

Commands

Command Syntax
abortpkg

Halts the installation of a package and forces the installation status in the SOTI MobiControl console to report "Failed" when used in a SOTI MobiControl pre-install script.

See Using Package Studio for more information.

abortpkg
abortsync

When used in a SOTI MobiControl pre-sync script, it stops the file synchronization process.

See Using File Sync Rules for more information.

abortsync

Example

To abort file synchronization if the first octet of the device's IP address is 169 (when the IP is in the form 169.254.0.1):

set firstoctet=ipoctet %IP% 1

if %firstoctet%==169 abortsync

attrib

Displays or changes file attributes.

attrib [+R | -R] [+A | -A] [+S | -S] [+H | -H] [drive:][path][filename]

Where

  • + sets an attribute
  • - clears an attribute
  • R is the read-only file attribute
  • A is the archive file attribute
  • S is the system file attribute
  • H is the hidden file attribute

Example

To archive a file:

attrib +A 1:\database_info.txt

cd

Changes the current directory.

cd [directory]

Example

To change to the Chocolate directory:

cd Chocolate

certimport

Imports a user-specified certificate of X.509 type, which could be either DER or Base64 encoded.

certimport -cert "filepath" -stype "storagetype" -storage "Storage"

Where

  • filepath is the relative or absolute path of the certificate (.cer) file to import.
  • storagetype is the type of storage into which to import the certificate. Not all operating systems support all of the available options:
    • CSSCS is the current system service certificate storage
    • CSSCU is the current user certificate storage
    • CSSCUGP is the current user group policy certificate storage
    • CSSLM is the local machine certificate storage
    • CSSLME is the local machine enterprise certificate storage
    • CSSLMGP is the local machine group policy certificate storage
    • CSSS is the system services certificate storage
    • CSSU is the user's certificate storage
  • storage is the storage location into which to import the certificate. Not all operating systems support all of the available options
    • MY is the personal user certificate storage
    • ROOT is the root certificate storage.
    • CA is the certificate authority certificate storage
    • Trust is the trusted certificate storage
    • SPC is the software publisher certificate storage

Example

To import a certificate test.cer into current user storage of "MY" type:

certimport -cert "test.cer"

To import a certificate test.cer into root user storage of the local machine:

certimport -cert "test.cer" -storagetype "CSSLM" -storage "ROOT"

cls

Clears the device screen.

cls
copy

Copies one or more files to another location.

On Windows Mobile/CE and Desktop Classic devices, you can copy files between desktop computers and mobile devices.

On Android devices, you can only copy files locally.

copy source destination

Example

To copy all files with the extension .txt from the C:\ to the temp directory on the device:

C:\tempt\*.txt 1:\temp

del

Deletes one or more files.

del filename

Example

To delete example.txt in the current directory:

del example.txt

To delete all files with the extension .tmp in the current directory and its subfolders:

del *.tmp

dir

Displays a list of files and subdirectories in a directory.

dir [drive:][path][directoryName]

Example

To list the files in the Temp directory of the device:

dir 1:\Temp\

echo

Displays messages or switches command echoing on or off.

echo [on | off] or echo message

Example

To turn command echoing off:

echo off

To turn command echoing on:

echo on

To display the message "Copying Files ...":

echo Copying Files ...

exit

Closes the remote help desk application window.

exit
find

Finds a file on the device.

find [/S] [filename]

Where /S applies the search to any subfolders

Example

To search for all files with a .txt file extension including subfolders:

find /S *.txt

finishpkg

Finishes the current script without processing the rest of the package and reports package installation as successful to the deployment server. This is useful particularly in packages that involve wiping a device. This script command can be used to skip reinstalling the package but still report back as successfully installed to the deployment server.

If a hard reset is initiated from a package's post-install script, the entire package will reinstall after the reset. A check can be included in the pre-install script that determines whether the package's files have already been installed.

Note: This command is not useful as a script command in and of itself but in the event of a package that involves a cold boot.
"path\to\package"finishpkg

Example

"1:\PersistentStorage\subfolder" finishpkg

For platforms that support the if command, you use finishpkg conditionally: If a package's post-install script contains:

md "1:\PersistentStorage\subfolder"reset /w

then the pre-install script could contain a check to prevent the package from reinstalling endlessly:

if exist "1:\PersistentStorage\subfolder" finishpkg

goto

Directs script execution to a labelled line in a script.

Only use this command in scripts.

goto label

Example

To go to label ":end"

copy *.* 1:\tmp

goto end

...

:end

help or ?

Displays a list of the commands supported and a brief description of each command.

help
if

Performs conditional actions if the specified conditions are found.

See The if Command for more information

ipoctet

Returns the specified octet of an IP address and saves it to an environment variable, when called from within a SOTI MobiControl device script.

ipoctet IPAddress octetNumber

Example

To save the value of the fourth octet of an IP address to the environment variable myOctet:

set myOctet=ipoctet 192.168.1.225 4 This gives myOctet the value 225

To save the value of the first octet of the device's IP address to an environment variable in a device script:

set myOctet=ipoctet %IP% 1 This gives myOctet the value 192 if the IP address is of the form 192.XXX.XXX.XXX

kill

Terminates a process that is currently running on the device.

kill executable

Example

To terminate the pword.exe process on the device:

kill pword.exe

lockdevice

Activates the lockscreen on a device for the specified number of minutes.

Note: Minimum time is one minute.
lockdevice minutes

Example

To lock a device for 1 minute

lockdevice 1

log

Sends a customs message to the SOTI MobiControl deployment server from the device. This message appears in the Logs tab of the Device Information panel in the SOTI MobiControl console.

log type message

Where type is the type of the associated message and the options are:

  • -e for Error
  • -w for Warning
  • -i for Information

Example

To send a notification to the SOTI MobiControl console at certain intervals during a software push:

Note: Put the command in the pre-install script

log -i "Starting Software Push"

mkdir or md

Creates a new directory.

mkdir [drive:] path

Example

To create a directory named "test" from the current directory:

mkdir test

To create test\test1\test2\test3 recursively:

mkdir test \test1 \test2 \test3

move

Moves a file from specified source location to specified destination location.

Note: You can rename the file at the same time by specifying a name for the destination filename.
move [sourceFilePath] filename destinationFilePath [filename]

Example

To move the file test.bat:

move test.bat 2:\

move test.bat 2:\test.bat

To move and rename a file at the same time:

move 1:\test.bat 2:\test2.cmd

To move folder to root folder:

move Mars /

pause

Prompts device user and waits for user input to continue.

pause

Example

To show "Press any key to continue..." on the device screen:

pause

ps

Lists the running processes on the device.

ps
regdelkey

Deletes a key from registry on a device.

regdelkey registryKey

Example

To delete registry key HKEY_CLASSES_ROOT\.2bp: :

regdelkey HKEY_CLASSES_ROOT\.2bp:

regdelval

Deletes a value from the registry on a device.

regdelval registryKey valueName

Example

To delete registry value HKEY_CURRENT_USER\Start\test:

regdelval HKEY_CURRENT_USER\Start\test

regload

Imports a registration file to the registry on the device.

regload registryFilePath

Example

To import registration file c:\test.reg to the device's registry:

regload c:\test.reg

regsave

Exports the device registry subtree to a specified file.

regsave [-A | -U] [drive:] [path] filename subtree [regpath]

Where

  • -A specifies that the output file is in the ANSI format
  • -U specifies that the output file is in the Unicode format
  • drive: specifies the drive location where the registry subtree will be saved
  • path specifies the file path to the directory where the registry subtree will be saved
  • filename specifies the filename where the registry subtree will be saved
  • subtree specifies which part of the device's registry to export to a file. Possible values are:
    • * specifies everything
    • HKLM specifies HKEY_LOCAL_MACHINE
    • HKCU specifies HKEY_CURRENT_USER
    • HKCR specifies HKEY_CLASSES_ROOT

Example

To export the HKEY_LOCAL_MACHINE subtree from the device registry to a UNICODE file C:\hklm.reg:

regsave -U C:\hklm.reg HKEY_LOCAL_MACHINE

regset

Adds a key or a value to registry on the device.

regset registryKey [valueName] [data]

Example

To add a new key and two values to that key:

regset HKLM\software\apps testkey

regset HKLM\software\apps\testkey testvalue1 abc

regset HKLM \software \apps \testkey testvalue2 dword:123

rem

Inserts a comment line in a script/batch file.

rem [comment]

Example

To add a comment about pumpkins:

rem The pumpkins are looking great this harvest

rename

Renames a file or folder.

rename sourceFilename destinationFilename

Example

To rename the file test.txt to test.bak:

rename test.txt test.bak

replacetxt

Changes all occurrences of a particular character or string in the specified file to a new character or string.

replacetxt filename string/characterToReplace newString/Character

Example

To replace the "Device" string with the "Psion" string in the file My Device.txt in the temp folder:

replacetxt "\Temp\My Device.txt" Device Psion

reset

Performs a soft or hard reset of the device.

reset [/s | /H | /W | /E] [/delaysec]

Where

  • /s is the default option and soft resets the device. Any desktop remote control sessions will also be terminated.
  • /H is used to hard reset a device running on the Windows Pocket PC or Windows CE platforms. It clears any data stored in the volatile memory. On Windows Mobile 5.0 and later devices this is equivalent to a soft reset. The real-time clock may also reset depending on the device make and model.
  • /W is used to wipe data stored on the device and reset the device to factory default settings.
    Note: The wipe command is only supported on the Windows Mobile 5 operating system with AKU2 or later and newer versions of Windows Mobile.
  • /E is used to wipe data stored on the device and its external storage as well as reset the device to factory default settings.
  • /P is used to bypass factory reset protection. It is only supported on Android Enterprise Work Managed devices.

On Android Plus devices it is possible to specify a /delay parameter (in seconds): reset /s /delay 10

If /delay parameter is not defined, the default value is 5 seconds

Example

To soft reset a device:

reset /s

To reset an Android Plus device to its factory settings in 30 seconds:

reset /E /delay 30

rmdir or rd

Deletes a directory.

rmdir [/S] path

Where /S removes any subdirectories

On Android Plus and Linux devices, this command requires the /S option and will delete the specified item whether it is a directory or a file.

Example

To remove an empty directory named "test" from the current directory:

rmdir test

To remove a directory named "test" and all of its contents from the current directory:

rmdir /S test

To provide location:

rmdir /sdcard/Download/test

set

Sets, edits or shows values of environment variables.

set [environmentVariable] [=|++|--] [string]

Where

  • set used alone, lists all environment variables
  • = deletes the environment variable it is used with
  • ++ increases the value of the specified environment variable. The variable must have an integer value.
  • -- decreases the value of the specified environment variable. The variable must have an integer value.

You can also use set to set the value of an environment variable to the string returned by the substring command:

set environment variable=substring "string" startposition [numberOfCharacters]"

Example

To display all environment variables:

set

To set the value of the environment variable Var1 to test:

set Var1=test

To set the value of environment variable Var2 to test:

set Var2=substring testing 1 4

shellexecute

Launches the registered application for the given file extension.

shellexecute filepath -verb [-wseconds]

Where

  • -verb is the action you want the shell to execute
  • -w tells the command to wait for the specified length of time (in seconds) before executing

Example

To launch the registered application for the given file extension:

shellexecute 1:\temp\temp.upg -open then shellexecute 1:\temp\temp.upg -run -w5

showmessagebox

Displays a message box on the device screen.

Note: The Android Plus agent has the following limitations:
  • It does not support a complex showmessagebox that contains more than one command
  • It cannot return the user response
  • It does not support "if" and related keywords
showmessagebox message [timer] [type] [default button] [action]

Where

  • message is the message displayed in the message box. Use quotation marks (" ") if there are spaces in the message.
  • [timer] is the number of seconds until the message box disappears automatically. If you omit a timer value or add the keyword NO_TIMER, the message box will persist until the device user dismisses it.
  • [type] is type of of message box. Options are:
    • 1 displays an information window with an OK button
    • 2 displays a question window with Yes and No buttons
    • 3 displays a warning window with an OK button
    • 4 displays a question window with OK and Cancel buttons
    • 5 displays an error window with an OK button
  • [default button] sets the default buttons for message box types 2 (YES | NO) or 4 (OK | CANCEL)
  • NOTIFY_DEVICE notifies the device user of the message, depending on the notification settings applied to the device. That is, devices set to ring, will ring, set to vibrate, will vibrate, and muted devices will have no notification. Only supported on Android Plus devices with agents 14.0.0 or later.

The return values for the showmessagebox are stored in a global variable, ShowMessageBoxReturn This variable can be used in scripts as %ShowMessageBoxReturn% to execute actions based on user response. Possible return values are IDYES, IDNO, IDOK, IDCANCEL. The value for this global variable does not change if the type is not 2 or 4.

Example

To show a simple message:

showmessagebox "This is a test message"

To provide device information using a macro:

showmessagebox "Your device's IP address is %IP%"

To set a 3 second timer to your message:

showmessagebox "This is a test message with a 3 second timer" 3

To add YES and NO buttons to your message box with no timer

showmessagebox "This is a test message with Yes/No button and no timer" NO_TIMER 2

To provide followup actions to a user response to message box:

showmessagebox "Abort the operation?" NO_TIMER 2 YES
if %ShowMessageBoxReturn% == IDYES goto Exit
sleep

Initiates sleep mode on the device for a set period. Only use this command in scripts.

sleep [length]

Where length is in seconds

Example

To set the device to sleep for 5 seconds:

sleep 5

sleepex

Initiates sleep mode on the device for a set period. Only use this command in scripts.

sleep [length]

Where length is in milliseconds

Example

To set the device to sleep for 3.5 seconds:

sleep 3500

start

Starts a program on the device. When the /wait option is specified, the script processor waits for the initiated program to terminate before executing the next command in the script.

start [/wait] program
Note: On Windows devices, program must be enclosed in quotation marks.

Example

To start Pocket Word and wait until it is terminated:

start /wait "\software\apps\pword.exe"

turnoff

Shuts down the device. You can specify a delay (in milliseconds) before shutdown.

turnoff [time]

Example

To turn off the device in 3.5 seconds:

turnoff 3500

type

Displays the contents of a Unicode text file.

type filename

Example

To display the contents of the file test.cmd:

type test.cmd

writeprivateprofstring

Saves or deletes specified settings on a device.

See The writeprivateprofstring Command for more information.

writeprofstring

Writes a string into the specified section of an initialization file.

writeprofstring filename section [key] [value]

Where

  • filename is the name of the .ini file
  • section is the section in the .ini file where the value will be written. The name of the section is case-sensitive.
  • key is the name of the key. If the key does not exist in the specified section, it is created. If this parameter is not included, the entire section, including all entries within it, is deleted.
  • value is the string to be written to the file. If this parameter is not entered, the key is deleted

Use quotations (" ") if either the key or the value contains spaces.

Example

To set the Color key in the "Video" section of the \Movie\mov.ini file to a value of "Red":

writeprofstring \Movie\mov.ini Video Color Red