Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Disable Autorun
- $autorunKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer"
- try {
- New-ItemProperty -Path $autorunKey -Name NoDriveTypeAutoRun -PropertyType DWORD -Value 149
- } catch [System.Security.SecurityException] {
- Write-Host "Insufficient permissions to modify registry key. Run the script as administrator."
- }
- # Block USB Access (Group Policy)
- # Requires administrative privileges and domain environment
- $gpoPath = "ComputerConfiguration\Administrative Templates\System\Removable Storage Access"
- try {
- Get-GPO -Name "Default Domain Policy" | Set-GPO -Path $gpoPath -Value "Deny all access"
- } catch [System.Exception] {
- Write-Host "Error blocking USB access through Group Policy. This might require additional configuration or domain environment."
- }
- # Block USB Access (Hardware Switch)
- # Requires specific laptop models with hardware switch
- $usbPortStatus = Get-CimInstance -ClassName Win32_PnPEntity | Where-Object { $_.Name -like "USB*Port*" }
- try {
- $usbPortStatus | ForEach-Object { Set-CimInstance -CimInstance $_ -Property @{Status = "Disabled"} }
- } catch [System.Exception] {
- Write-Host "Error disabling USB ports. This might require specific hardware capabilities."
- }
- # Update Operating System
- Start-Process -FilePath powershell -ArgumentList "-ExecutionPolicy Bypass -Command & { Install-WindowsUpdate }"
- # Prompt User to Scan USB Drives with Preferred Antivirus
- Register-CimEvent -Source "Win32_PnPDeviceProperty" -Event "DeviceArrival" -Filter @{SystemName = ".*", "PnPDeviceID" = "USBSTOR\\.*"} -Action {
- # Extract drive letter
- $driveLetter = Get-CimInstance -ClassName Win32_LogicalDisk -Filter @{DeviceID = $_.DeviceID} | Select-Object DeviceID -First 1
- # Check if drive letter is valid
- if ($driveLetter) {
- # Notify user and suggest antivirus scan
- Write-Host "A USB drive has been detected at $driveLetter."
- Write-Host "Please scan the drive with your preferred antivirus solution."
- # Start antivirus scan with user confirmation
- $confirm = Read-Host "Would you like to start a scan with your preferred antivirus now? (Y/N)"
- if ($confirm -eq "Y") {
- # Modify this line with the actual command and path for your antivirus software
- Start-Process "C:\Program Files\Antivirus\Scan.exe" -ArgumentList "$driveLetter"
- }
- } else {
- Write-Host "Unable to determine drive letter for the detected USB device."
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement