You can catch the location of a running script by its command line.

So, this hybrid code script allows you to retrieve a list of all running processes on your system, along with their corresponding command lines.

The script excludes any processes related to web browsers, such as Chrome, Firefox, Internet Explorer, Edge, and Opera.

The output is saved to a text file and displayed in an interactive grid view.


<# : Batch Script Section
@rem # The previous line does nothing in Batch, but starts a multiline comment block in PowerShell.
@rem This allows a single script to be executed by both interpreters.
@rem This section is a Batch script that configures the environment and runs the PowerShell script.
@rem It copies the Batch script to a temporary PowerShell script file, runs the PowerShell script, then deletes this temporary file.
@echo off & Mode 85,3 & Color 1B 
Title Get all processes and their command lines, excluding browsers. By [Hackoo]
If [%1] NEQ [Admin] (Powershell start -verb runas '%0' Admin & Exit)
setlocal
cd "%~dp0"
Color 1B & echo( & echo(
Echo(        Get all processes and their command lines, excluding browsers ...
set "__thisBatchFile=%~f0"
copy /y "%__thisBatchFile%" "%TEMP%\%~n0.ps1" >NUL && powershell -NoProfile -ExecutionPolicy Bypass -File "%TEMP%\%~n0.ps1" %*
Del "%TEMP%\%~n0.ps1"
EndLocal & Timeout /T 1 /NoBreak>nul & Exit
#>
##########################   Powershell Script Section  #################################
# The Powershell Script section starts here...
# Here we run our PowerShell commands...
Clear-Host
# Specify the output file path
$outputFilePath = "$env:userprofile\desktop\ProcessLog.txt"
Write-Host "`n         Get all processes and their command lines, excluding browsers" -fore Yellow
# Get all processes and their command lines, excluding browsers and the current powershell script
$processes = Get-WmiObject Win32_Process | 
    Where-Object { 
        $_.CommandLine -ne "" -and 
        $_.CommandLine -ne $null -and 
        $_.Name -notmatch "chrome|firefox|iexplore|edge|opera|powershell" -and 
        $_.ProcessId -ne $currentScriptPID
    } | 
    Select-Object Handle, Name, CommandLine
# Create an array to store the output
$output = @()
# Build the output content
foreach ($process in $processes) {
    $output += "Process Name: $($process.Name)"
    $output += "Command Line: $($process.CommandLine)"
    $output += "-----------------------------"
}
# Save the output to the file
$output | Out-File -FilePath $outputFilePath
# Display a message indicating where the output is saved
Write-Host "Output saved to: $outputFilePath"
# Display the results in Out-GridView
$processes | Out-GridView -Title "Get all processes and their command lines, excluding browsers. [By Hackoo]" -Wait
ii $outputFilePath

To use this script, follow these steps:


  1. Copy the provided code and save it with notepad or any text editor like notepad++ as Get-MyProcesses.bat.
  2. Double-click the Get-MyProcesses.bat file to execute it.
  3. The script will generate a text file named ProcessLog.txt in your desktop.
  4. Open pastebin.com in your web browser.
  5. Copy the contents of the ProcessLog.txt file and paste them into the text area on Pastebin.
  6. Click the "Create New Paste" button to generate a unique URL for your paste.
  7. Share the generated URL with the person who requested the analysis.

By following these steps, you will be able to execute the hybrid code script, save the output to a text file, and share the results for further analysis.

Edit
Pub: 16 Jan 2024 13:05 UTC
Edit: 04 Feb 2024 23:37 UTC
Views: 30