Скачиваний:
0
Добавлен:
15.04.2026
Размер:
573.08 Кб
Скачать

ФЕДЕРАЛЬНОЕ ГОСУДАРСТВЕННОЕ БЮДЖЕТНОЕ ОБРАЗОВАТЕЛЬНОЕ

УЧРЕЖДЕНИЕ ВЫСШЕГО ОБРАЗОВАНИЯ

«САНКТ-ПЕТЕРБУРГСКИЙ ГОСУДАРСТВЕННЫЙ УНИВЕРСИТЕТ

ТЕЛЕКОММУНИКАЦИЙ ИМ. ПРОФ. М.А. БОНЧ-БРУЕВИЧА»

(СПбГУТ)

ФАКУЛЬТЕТ ИНФОКОММУНИКАЦИОННЫХ СЕТЕЙ И СИСТЕМ (ИКСС)

КАФЕДРА ПРОГРАММНОЙ ИНЖЕНЕРИИ И ВЫЧИСЛИТЕЛЬНОЙ ТЕХНИКИ (ПИ И ВТ)

ДИСЦИПЛИНА: «Операционные системы и сети»

Лабораторная работа №1.

Анализатор приложений на диске

Выполнил:

Цыганков М.А.

Козлов Н.С.

Тюришев М.А.

Подпись____________

Принял:

Дагаев А.В.

Подпись____________

«_____»________ 2021

Цель работы

Написать программу для анализа приложений на диске в системе Microsoft Windows с использованием средств PowerShell.

Функционал

· Просмотр каталога

- Выводит на экран список папок и файлов, находящихся в текущем каталоге.

· Просмотр зависимостей

- Выводит на экран список зависимостей, используемых переданным в функцию приложением.

· Изменение каталога

- Позволяет изменить текущий каталог.

· Перезапуск программы

- Очищает историю работы программы.

· Выход из программы

- Завершает работу программы.

просмотр каталога

function WinXPlore_TableOfDirectoryContent {

Get-ChildItem -Path $global:currentDirectory |

Select-Object -Property BaseName, Extension, Length |

Format-Table -AutoSize -Wrap

}

while (1) {

...

switch ($userChoise) {

1 {WinXPlore_TableOfDirectoryContent; break}

}

...

}

просмотр зависимостей

function WinXPlore_ShowDependencies {

param (

$Path

)

$tmpPath = [string]::Concat($global:currentDirectory, $Path)

$date = Get-Date -Format "MM_dd_yyyy_HHmm"

$logName = [string]::Concat($Path, "_", $date)

Start-Process -PassThru $tmpPath | Get-Process -Module |

Format-Table -AutoSize -Wrap | Out-File -FilePath ./out/$logName.txt

Get-Content -Path ./out/$logName.txt

}

while (1) {

...

switch ($userChoise) {

2 { Write-Host "Enter application from current directory"

Write-Host -NoNewline "WinXPlore:> "

$app = Read-Host

WinXPlore_ShowDependencies -Path $app ;break

}

}

...

}

Изменение каталога

function WinXPlore_ChangeDirectory {

param (

$Path

)

$testDir = $Path

if (WinXPlore_CheckPath -Path $testDir == $true) {

$global:currentDirectory = $testDir

WinXPlore_GlobalSlashChecker

Write-Host "New directory has been successfully set" -ForegroundColor green

} else {

Write-Host "The directory does not exist or is not written correctly" -ForegroundColor -red

Write-Host "Directory info has been return to previous condition" -ForegroundColor red

}

}

while (1) {

...

switch ($userChoise) {

3 {

Write-Host "Enter new directory"

Write-Host -NoNewline "WinXPlore:> "

$directory = Read-Host

WinXPlore_ChangeDirectory -Path $directory ;break

}

}

...

}

перезапуск программы

while (1) {

...

switch ($userChoise) {

4 {$state = 0; break}

}

...

}

выход из программы

while (1) {

switch ($userChoise) {

5 {exit} } ... }

Пример работы программы

Вывод

В ходе выполнения лабораторной работы, было изучено средство автоматизации Microsoft – PowerShell и сопутствующий ему язык сценариев.

Код программы

# WinXPlore 1.0

################### VARIABLES ###################

$global:currentDirectory = $NULL

################### FUNCTIONS ###################

function WinXPlore_PrintApplicationHeader {

}

function WinXPlore_CheckPath {

param (

$Path

)

if (Test-path -Path $Path) {

return $true

} else {

return $false

}

}

function WinXPlore_GlobalSlashChecker {

if ($global:currentDirectory.endswith("\")) {

} else {

$global:currentDirectory = [string]::Concat($global:currentDirectory, "\")

}

}

function WinXPlore_TableOfDirectoryContent {

Get-ChildItem -Path $global:currentDirectory |

Select-Object -Property BaseName, Extension, Length |

Format-Table -AutoSize -Wrap

}

function WinXPlore_ShowDependencies {

param (

$Path

)

$tmpPath = [string]::Concat($global:currentDirectory, $Path)

$date = Get-Date -Format "MM_dd_yyyy_HHmm"

$logName = [string]::Concat($Path, "_", $date)

Start-Process -PassThru $tmpPath | Get-Process -Module |

Format-Table -AutoSize -Wrap | Out-File -FilePath ./out/$logName.txt

Get-Content -Path ./out/$logName.txt

}

function WinXPlore_ChangeDirectory {

param (

$Path

)

$testDir = $Path

if (WinXPlore_CheckPath -Path $testDir == $true) {

$global:currentDirectory = $testDir

WinXPlore_GlobalSlashChecker

Write-Host "New directory has been successfully set" -ForegroundColor green

} else {

Write-Host "The directory does not exist or is not written correctly" -ForegroundColor -red

Write-Host "Directory info has been return to previous condition" -ForegroundColor red

}

}

################### PROGRAM ###################

while (1) {

Clear-Host

WinXPlore_PrintApplicationHeader

Write-Host "Enter full directory path you want to work with"

Write-Host -NoNewline "WinXPlore:> "

$directory = Read-Host

if (WinXPlore_CheckPath -Path $directory == $true) {

$global:currentDirectory = $directory

WinXPlore_GlobalSlashChecker

Write-Host "The directory has been successfully picked!" -ForegroundColor green

Write-Host ""

[int]$state = 1

while ($state -ne 0) {

Write-Host "Show Directory [1] | Show Dependencies [2] | Change Directory [3] | Restart [4] | Quit [5]"

Write-Host -NoNewline "WinXPlore:> "

$userChoise = Read-Host

switch ($userChoise) {

1 {WinXPlore_TableOfDirectoryContent; break}

2 {

Write-Host "Enter application from current directory"

Write-Host -NoNewline "WinXPlore:> "

$app = Read-Host

WinXPlore_ShowDependencies -Path $app

;break}

3 {

Write-Host "Enter new directory"

Write-Host -NoNewline "WinXPlore:> "

$directory = Read-Host

WinXPlore_ChangeDirectory -Path $directory

;break}

4 {$state = 0; break}

5 {exit}

}

}

} else {

Write-Host "The directory does not exist or is not written correctly" -ForegroundColor red

}

}

Соседние файлы в папке Лабы