国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PowerShell > 正文

PowerShell時(shí)間記錄腳本

2020-05-30 20:20:27
字體:
供稿:網(wǎng)友

#initialization   $timeInterval = 30 #監(jiān)測間隔   $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]::Parse($groups[2].Value);    }}  }  #start to monitor  while ($true)  {    $titles = ps | ? {$_.MainWindowTitle} | select MainWindowTitle    $titles | % {      if ($_ -match "Google 閱讀器 - 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"]++;}      }}}}}}}}    }    sleep($timeInterval)    $count = ($count + 1) % 10 #為了防止數(shù)據(jù)丟失,每10次記錄寫入文件一次    if ($count -eq 0) {$record > "d:/temp/timeRecord$date.txt"}  }

為了解技術(shù)思路,研究了一下powershell.
整個(gè)開發(fā)與部署過程如下:

1.下載WindowsXP-KB926139-v2-x86-ENU

安裝powershell環(huán)境;

2.按照代碼要求,寫一個(gè)簡單的腳本;

3. 運(yùn)行powershell時(shí),同 bat是有區(qū)別的.注意以下方法:

1) 解除限制:

set-executionpolicy Unrestricted

2) 將文件名保存為ps1
3) 通過以下方法運(yùn)行(假如文件名是c:a.ps1)
PS C:> .a
[@more@]

示例代碼:

function foo ( [int] $x){$x = $x + 1echo $x}foo (1 )

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 云浮市| 扬州市| 肥乡县| 沙坪坝区| 通道| 甘肃省| 丹寨县| 华亭县| 项城市| 赤壁市| 镇原县| 长治市| 景谷| 娱乐| 当雄县| 兴义市| 莱州市| 高阳县| 北流市| 沙田区| 淄博市| 灵丘县| 峨眉山市| 洪洞县| 峡江县| 大姚县| 台中市| 四子王旗| 诸暨市| 容城县| 比如县| 广饶县| 台湾省| 浦城县| 石家庄市| 资兴市| 天水市| 余干县| 布拖县| 布拖县| 集安市|