Guide 3 Notes
Guide 3 Notes
Basic Commands:
To open Command Prompt: cmd in Windows Start Menu.
dir: Displays list of directories and files in a specific folder.
cls: Clears the screen of the Command Prompt.
help: Displays a list of available commands. You can get more information on a specific
command by typing help followed by the command name (e.g., help color).
Common Commands:
cd c:\: Changes the directory to the root of the C: drive.
tree: Displays the directory structure of a path or directory.
start: Opens a new Command Prompt window or launches an application, e.g., start
notepad opens Notepad.
Batch Files
Batch Files: Text files containing a sequence of commands for Windows to execute. The
Command Prompt interprets these commands in sequence.
Common Batch Commands:
echo: Displays a message on the screen.
set: Used to define variables (e.g., %Random% generates a random number).
if: Allows conditional execution of commands based on comparisons (e.g., if variable
equals X, execute Y).
goto: Jumps to a specific label in the script for execution.
Example:
To create a simple batch file that clears the screen and waits for input:
The guide walks through creating a number guessing game using a batch file. Here's an outline of
how the game works:
Important Points:
1. Command Prompt vs GUI: The Command Prompt allows access to system files and folders
that might not be visible in the graphical user interface (GUI), especially hidden files.
2. Commands as Building Blocks: Commands are building blocks for scripts that automate
repetitive tasks.
3. Batch File Flexibility: Batch files provide flexibility by allowing sequences of commands to
run without user interaction, making them powerful tools for automating tasks.
Recap
The Command Prompt is crucial for professionals who want to perform tasks faster and
automate processes on Windows.
Batch files are essential for automating tasks and can be created easily with basic
command-line knowledge.
The number guessing game project demonstrates how simple logic, loops, and conditions
can be used in batch scripting.
Steps to Create the Game (the example project):
Add logic to take the user's input and compare it with the generated number.
Use if statements to check if the guess is too high, too low, or correct.
Keep track of how many guesses the user has made.
Start by opening guessgame.bat in Notepad. Here’s how you can write the complete batch script
step by step:
First, add these lines to clear the screen and set the environment for the game:
@echo off
cls
Use the %Random% variable to generate a random number between 0 and 100:
%Random% generates a number between 0 and 32,767. By using % 101, you limit it to a
number between 0 and 100.
set /a Attempts=0
Step 4: Start the Game Loop
Now, you need a loop to prompt the user for guesses until they find the correct number. Add
a label to mark the start of the loop:
:Start
Use ifstatements to check if the guess is too high, too low, or correct:
set /a Attempts+=1
goto Start
set /a Attempts+=1
goto Start
set /a Attempts+=1
goto End
Add an Endlabel to finish the game when the correct number is guessed:
:End
pause
exit
Full Script:
@echo off
cls
set /a Attempts=0
:Start
set /a Attempts+=1
goto Start
set /a Attempts+=1
goto Start
set /a Attempts+=1
goto End
:End
pause
exit
How It Works:
Final Notes:
The game will keep looping (via goto Start) until the user guesses the correct number.
Once the number is guessed correctly, it displays how many attempts it took, then exits.
PowerShell Overview:
PowerShell is a modern command-line interpreter that includes the best features of
other popular shells.
Unlike the traditional Command Prompt (cmd.exe), PowerShell accepts and returns
objects, not just text.
It's included in Windows versions (7, 8.1, 10, 11) and Windows Server versions, as well as
Linux and macOS.
Key Concepts:
1. Cmdlets:
PowerShell commands are called cmdlets (command-lets).
They follow a verb-noun naming convention, such as Get-Process. This makes it easier to
understand the command's purpose.
You can filter cmdlets by their verb or noun.
2. Differences from Command Prompt:
PowerShell can execute commands from Command Prompt, but not the reverse.
It’s much more powerful, with the ability to write modern scripts and handle complex
administrative tasks.
1. Opening PowerShell:
In the Windows Start Menu, type "PowerShell" and select Run as Administrator.
The interface looks similar to the Command Prompt but is more robust.
2. Learning Curve:
PowerShell may seem intimidating at first, but it’s designed to help you learn
progressively.
Use the get-help and get-command cmdlets to explore and learn about available
commands.
Useful Cmdlets:
1. get-command:
Retrieves a list of all available commands on your system.
You can filter results with parameters like -name or -noun, e.g., get-command -name
*service* lists commands related to services.
2. get-help:
Provides detailed help for any cmdlet. For example, get-help clear-host gives instructions
on using the clear-host cmdlet.
You can also get examples by adding the -examples parameter, or view online help using
-online.
3. get-psdrive:
Displays information about the different drives on the system, including FileSystem drives
(like C:) and Registry drives (HKCU and HKLM).
4. get-content:
Retrieves and displays the contents of a file, e.g., get-content -path
"C:\Users\Documents\file.txt".
You can limit the number of lines displayed using -totalcount for the beginning of the file
or -tail for the end.
5. get-childitem:
Lists the contents of a folder. You can filter results or exclude certain file types using -filter,
-include, or -exclude.
6. set-location:
Changes the directory, equivalent to the cd command in Command Prompt, e.g., set-
location "C:\temp".
7. get-item:
Retrieves details about a specific item (file or folder) and displays its properties like
creation time, last accessed, and modified times.
8. new-item:
Creates new files or folders. E.g., new-item -path "C:\temp" -name "file.txt" -itemtype file
creates a text file in the "C:\temp" directory.
9. remove-item:
Deletes files or directories. Use -recurse and -force to delete entire directories and their
contents.
PowerShell Aliases:
Comparison Operators:
PowerShell uses comparison operators to evaluate conditions. These operators return true or
false:
Operator Description
-eq Equal to
PowerShell ISE:
Integrated Scripting Environment (ISE) lets you write, run, and debug scripts in a user-
friendly interface.
To open it, search for PowerShell ISE in the Start Menu and run it as an administrator.
Simple Loop Example:
Example of a basic script:
Start-Sleep:
The Start-Sleep cmdlet pauses script execution for a specified period (seconds or
milliseconds), e.g., Start-Sleep -s 1.
get-random:
Returns a random number. You can limit the range using -minimum and -maximum, e.g.,
get-random -minimum 1 -maximum 100.
Practical Scripts:
1. Number Guessing Game:
Using get-random and read-host cmdlets, you can build a simple number guessing game
where the system picks a random number and the user has to guess it.
2. Count-down Timer with Sound:
Combine loops, Start-Sleep, and Console.Beep() to create a countdown timer with sound
effects.
Recap:
PowerShell provides immense flexibility and is essential for system administrators, developers,
and database administrators, enabling powerful automation and task management capabilities.
Chapter 7: Bureautique
Introduction to Bureautique
Office Suites: These are packages of office software tools that often include word
processors, spreadsheets, and presentation software.
Examples: Microsoft Office, LibreOffice, WordPerfect Office.
Microsoft Office:
WordPerfect Office:
Developed by Corel, also a paid suite with tools similar to Microsoft Office:
WordPerfect: Word processor.
Quattro Pro: Spreadsheet software.
Presentations: Presentation software.
Has a traditional menu interface, unlike Microsoft's ribbon-based UI.
LibreOffice:
OpenOffice:
FreeOffice:
Developed by SoftMaker and available in both free and paid versions.
Includes:
TextMaker: Word processor.
PlanMaker: Spreadsheet software.
Presentations: Presentation software.
Limitations in Free Version: Lacks advanced features like spell check and thesaurus, style
creation in PlanMaker, etc.
Optimized for touchscreens and downloadable from FreeOffice.
Final Recap
LibreOffice is a versatile, free, open-source office suite that includes tools for word
processing, spreadsheets, presentations, database management, and more.
Microsoft Office and WordPerfect Office are paid alternatives, while FreeOffice offers a
free, lightweight solution with some limitations.
Each suite is designed to handle everyday office tasks like creating reports, presentations,
and data analysis.
Customization of user interfaces in LibreOffice allows users to tailor the experience to their
preference, closely mimicking Microsoft Office if needed.
Extra Exercises:
To explore available cmdlets in PowerShell, use the get-command cmdlet. This lists all available
commands, including cmdlets, functions, aliases, and scripts.
get-command
If you want to filter cmdlets based on a specific task (e.g., file management), you can use
wildcards (*). For instance, if you're looking for cmdlets related to "item" (such as creating,
retrieving, or deleting items), run:
get-command *item*
PowerShell provides a built-in help system to understand cmdlets in more detail. To get
information about a cmdlet, use get-help followed by the cmdlet name.
For example, to get help on the new-item cmdlet, which is used to create files and folders, run:
get-help new-item
To get detailed examples of how to use new-item, append the -examples parameter:
This will show practical, real-world usage examples of the new-item cmdlet.
You can create a new directory using the new-item cmdlet. Specify the path where the folder
should be created and set the -itemtype parameter to directory.
To create a new folder called "NewFolder" in your Documents directory:
The -path parameter specifies the location where the new folder will be created.
The -itemtype parameter is used to define what kind of item you are creating. In this case, it’s
a directory (folder).
To delete a file or folder, use the remove-item cmdlet. When deleting directories that contain files,
use the -recurse flag to ensure all contents are deleted.
To delete a file:
The -recurse parameter ensures that all files and subdirectories within the specified folder are
deleted.
You can write a simple PowerShell script to loop through all the files in a directory and list them.
This involves using the get-childitem cmdlet to retrieve the files and a foreach loop to iterate
through them.
Define the directory where the files are located. For example:
$directory = "C:\Users\YourUsername\Documents"
Use a foreach loop to iterate over each file and display its name using Write-Host:
$directory = "C:\Users\YourUsername\Documents"
Save this as a .ps1 script (for example, list-files.ps1), and you can run it in PowerShell to list the files
in the specified directory.
1. Cmdlet Exploration: Use get-command to explore available cmdlets, and filter by specific
keywords.
2. Cmdlet Help: Use get-help to find detailed explanations and examples for any cmdlet.
3. Create a Directory: Use new-item with the -itemtype directory option to create new folders.
4. Delete Files/Directories: Use remove-item with the -recurse option to delete files or
directories and their contents.
5. Loop Through Files: Write scripts using get-childitem and foreach to loop through and list
files in a directory.
These steps walk through the foundational file management tasks you would perform in
PowerShell, which are important for scripting and automation.