The following is a nice? sample for an automation task. This
batch is like the one in Tipps.
It will be executed every time a device connects to your PC via
ActiveSync. You will need the itsutils.
As you can read, the batch (script) first tries to check, if
it has already been run on the device. This is done by looking for a
file called "\OnConnect.done". In real, the batch deletes a local file
(line 13) "OnConnect.done" and then simply copies the file from the
device (line16). If the file is found, this device has been already
processed (line 17) and the batch gos on with line 66.
If the file is not found, the batch continues with setting the
registry changes. It uses saved REG files and the nice tool pregutl to
do it remotely (line 22 to 24). After doing the changes, the device
will be queried for different registry keys which will be saved to
database.txt for later use. The registry keys platform (line 29) and
version (line 30) are available on all devices, but OSBuildInfo (line
59) and system (line 48) are only available on CK3x or 7xx.
So in line 33, we try to find the model string for CK3x
devices and in line 39 for CN2 devices. In line 43 and 44 we will use
the saved model names to jump over the part, that is only valid for PPC
(7xx): dump psminfo.txt into database.txt. The OSBuildInfo registry is
only been executed for CK3x models.
Finally we put a OnConnect.done onto the device, so we later
know, that it was handled. At the very end, we sync the time of the
device with the PC.
rem use database.txt template file, if no database.txt exists
12
if EXIST DataBase.txt goto OldDatabase
13
echo "Creating new database"
14
copy DataBase.tmpl DataBase.txt
15
16
:OldDatabase
17
echo "Using old database"
18
echo "auto calibrating device..."
19
pput -f NoWelcome.exe \NoWelcome.exe
20
prun \NoWelcome.exe
21
22
echo "checking if already processed device..."
23
REM check if already processed
24
REM delete the local check file
25
del OnConnect.done >NUL
26
rem create a new local bak file
27
echo onconnect >OnConnect.bak
28
29
REM try to load the checkfile from device
30
pget \OnConnect.done >NUL
31
32
REM the database will be
filled once
33
if exist OnConnect.done (
34
goto OldDevice
35
) else (
36
echo "This device has already been processed"
37
goto NewDevice
38
)
39
40
:NewDevice
41
:NoCalib
42
echo "...NoCalib.."
43
REM put device in database
44
echo. >>database.txt
45
echo "building a new database entry..."
46
rem Copy DumpMac util to device
47
pput -f DumpMac.exe \DumpMac.exe
48
rem start DumpMac util on device
49
prun \DumpMac.exe
50
rem delete local file
51
del DumpMac.txt >NUL
52
rem download DumpMac.txt from device
53
pget \DumpMac.txt
54
rem copy DumpMac.txt at end of database.txt
55
type dumpmac.txt >>database.txt
56
rem put flag file on device to avoid duplicate processing
57
pput OnConnect.bak \OnConnect.done
58
59
:OldDevice
60
REM uncomment, if you like to get a list of installed apps
61
REM pregutl HKEY_LOCAL_MACHINE\SOFTWARE\Apps >>database.txt
62
REM psynctime will be executed always
63
echo "syncing time..."
64
psynctime
65
echo on
66
rem pause DEBUG
67
68
:EXIT
69
rem close this
70
exit
Some Notes:
The script/batch is written to run from c:\OnConnect. Please patch it,
if you want to run it from another place. You must change also change
the PcTools\ActiveSyncOnConnectWINDOWS.reg file. Please adjust the
windows dir in the reg file too, if c:\windows is not your windows dir.
REGEDIT4 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows CE Services\AutoStartOnConnect] "OnConnect"="\"c:\\windows\\system32\\cmd.exe\" /c c:\\OnConnect\\install.bat"
You will also find reg files to disable/enable the Partnership dialog
of ActiveSync in the PcTools dir of the download file.
REGEDIT4 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows CE Services] "GuestOnly"=dword:00000001
Code Comments
Lines 11-14 will copy a template file for the database containing the
header line, if there is not already a database.
Lines 16-20 will auto calibrate the device. This will only work for
known devices, see \NoWelcome.log.txt on device. This all is to avoid
the manual calibration and Dr.Johnson test.
Lines 22-38 will check, if the device has already been processed. This
is done by checking, if the file \OnConnect.done exists on the device.
These lines should ensure, that you dont get a device listed several
times in the database. You will get duplicate entries, if your device
has been cold booted, as this removes all non-OS image files from the
device.
Lines 40-57 will copy a tool called DumpMac to the device, execute it
remotely and get the output file written by the tool.. The single
DumpMac.txt is then appended to the database file. In line 57 the
device will be 'marked' as allready processed.
Lines 59-66 will sync the time of the device to the PCs time. You can
uncomment the line "REM pregutl HKEY_LOCAL_MACHINE\SOFTWARE\Apps
>>database.txt", but this will change the layout of the
database.txt and you will get problems using database.txt in excel.