#initialization $timeInterval = #监测间隔 $record = @{"coding" = 0; "Outlook Email" = 0; "Gmail" = 0; "Google Reader" = 0; "BBS" = 0; "Other Internet" = 0;
"Documents" = 0;} $count = 0 $date = date-format "YyyyMMdd" #try to resume if (Test-path "D:\temp\timeRecord$date.txt") {GC "D:\ Temp\timerecord$date.txt "| % {if ($_-match "\w+\s+\d+") {$groups = [Regex]::match ($_, "^ (\w+\s?\w+) \s+ (\d+)").
Groups; $record [$groups [1]. Value] = [int]::P arse ($groups [2].
Value); #start to monitor while ($true) {$titles = PS |? {$_. MainWindowTitle} | Select MainWindowTitle $titles |
% {if ($_-match "Google reader-Windows Internet Explorer") {$record [Google Reader]++}
else {if ($_-match "gmail-windows Internet Explorer") {$record ["Gmail"]++;}
else {if ($_-match "Internet Explorer") {$record ["Other Internet"]++;}
else {if ($_-match "Visual Studio") {$record ["Coding"]++;} else {if ($_-match "Microsoft Word") {$record["Documents"]++;}
else {if ($_-match Microsoft Office OneNote) {$record [Documents]++;}
else {if ($_-match "Microsoft PowerPoint") {$record [Documents]++;}
else {if ($_-match "message (HTML)") {$record [Outlook Email]++}
else {if ($_-match "BBS") {$record ["BBS"]++} $count = ($count + 1)% #为了防止数据丢失, write a file every 10 times if ($count-eq 0) {$reco}}}}}}
Rd > "D:\temp\timeRecord$date.txt"}}
In order to understand the technical thinking, studied the PowerShell.
The entire development and deployment process is as follows:
1. Download Windowsxp-kb926139-v2-x86-enu
Install PowerShell environment;
2. Write a simple script as required by the Code;
3. When running PowerShell, the same bat is different. Note the following methods:
1) Lifting Restrictions:
Set-executionpolicy Unrestricted
2 Save file name as PS1
3) Run (if the filename is C:a.ps1) by the following method
PS C:>. A
[@more @]
Sample code:
function foo ([int] $x)
{
$x = $x + 1
echo $x
}
foo (1)