Showing posts with label Windows. Show all posts
Showing posts with label Windows. Show all posts

Sunday, June 8, 2025

kill a process running on a specific port in Windows

 

Step 1: Find the PID (Process ID) using the port

Open Command Prompt (CMD) as Administrator and run:


netstat -aon | findstr :<PORT>

Replace <PORT> with the actual port number you're targeting.

📌 Example (for port 5000):


netstat -aon | findstr :5000

Look for a line like:


TCP 0.0.0.0:5000 0.0.0.0:0 LISTENING 1234

The last number (1234 in this example) is the PID.


🧨 Step 2: Kill the process by PID

Once you have the PID, run:


taskkill /PID <PID> /F

Replace <PID> with the number from the previous step.

📌 Example:


taskkill /PID 1234 /F


Make a batch Script

Option 1: Batch Script (Simple & Quick)

You can save the following as kill_port.bat and run it as Administrator:

---------------------

@echo off set /p PORT=Enter port number to kill: for /f "tokens=5" %%a in ('netstat -aon ^| findstr :%PORT%') do ( echo Killing process with PID %%a taskkill /PID %%a /F ) pause


-------------------------------------

How to Use:

  1. Open Notepad.

  2. Paste the script above.

  3. Save as kill_port.bat (use Save as type: All Files).

  4. Right-click it and choose Run as Administrator.


Option 2: PowerShell Script (More Robust)

------------------------------------------------------------------------------

$port = Read-Host "Enter port number" $connection = netstat -aon | Select-String ":$port" if ($connection) { $pid = ($connection -split '\s+')[-1] Write-Host "Killing process with PID $pid" Stop-Process -Id $pid -Force } else { Write-Host "No process found using port $port" }



-------------------------------------------------------------------------------

How to Use:

  1. Save it as Kill-Port.ps1.
  2. Run it from PowerShell as Administrator.


Wednesday, January 10, 2024

How to install Linux on Windows with WSL - Windows Subsystem for Linux

 WSL on Windows

--------------

Windows Subsystem for Linux currently has several limitations. First, it does not support all Linux applications; it is intended to provide a tool to handle bash and major Linux command-line utilities. WSL does not support Linux graphical user interface (GUI) environments such as Gnome or K Desktop Environment.

How to install Linux on Windows with WSL

https://learn.microsoft.com/en-us/windows/wsl/install


Run Below command in Power Shell ( better to run with Administrator mode )

1. wsl --install

 Note

The above command only works if WSL is not installed at all. If you run wsl --install and see the WSL help text, please try running wsl --list --online to see a list of available distros and run wsl --install -d <DistroName> to install a distro. To uninstall WSL, see Uninstall legacy version of WSL or unregister or uninstall a Linux distribution.

2. Check which version of WSL you are running

wsl -l -v


3. Check version

wsl --version

4. wsl --status

may give sample output like

-------------------------------------------------------------------------------------------------------

Default Distribution: Ubuntu

Default Version: 2

Windows Subsystem for Linux was last updated on 7/7/2023

WSL automatic updates are on.

Kernel version: 5.10.16

------------------------------------------------------------------------------------------------------------

5. help

wsl --help

6. To run as specific user

wsl --user {username}

wsl --user myname

7. Update 


8.To shutdown

wsl --shutdown



https://learn.microsoft.com/en-us/windows/wsl/basic-commands


Monday, August 28, 2023

How to check Wifi password from Windows machine

 It is east to use shell commands to find the password

1. open power shell

2. find all the listed wifis

3. check the password of the selected wifi network


Step 2:

netsh wlan show profile "name=SLT wifi" key=clear

Step 3:

netsh wlan show profile "name=your wifi name" key=clear


3PRnfigqWlCS85vZkZmYa6zS

Friday, May 26, 2023

Windows Process useful commands

 

windows find port usage

netstat -aon | findstr<port_number>

eg: netstat -ano | findstr 8081


windows check details of process id

tasklist /fi "pid eq <process id>"

eg: tasklist /fi "pid eq 4716"


Kill Process forcefully

taskkill /im myprocess.exe /f

The "/f" is for "force". If you know the PID, then you can specify that, as in:

taskkill /pid 4716 /f

Wednesday, June 2, 2021

Create a bat file to set path

 you may have to set path manually so many times due to various reasons. In a scenario like that best thing is to make a bat file and set path at once. below is simple sample bat file for that.

1. create notepad and save with content to PATH variable as below and save as "path.bat", file name can be any name as per requirement.

SET PATH=C:\Program Files\Java\jdk-12.0.1\bin;C:\Project\New2019-07-22\sw\apache\apache-maven-3.5.4\bin;



Sunday, November 1, 2020

Clearing Space in your Machine

 Recently I have seen my  hard drive space has been reduced. When i looked at, just saw "User/{you username} takes around 50GB.

I am searching how to reduce this and take some space. Below are few steps I did in my Window 10 machine.


Clear Temp Folder and Download Folder

C:\Users\{username}\AppData\Local\Temp

C:\Users\{username}\Downloads


Tuesday, August 27, 2019

Automate: Create Remote Desktop connection

How to connect to remote machine automatically running a bat file in Windows.
This will ease your life.

below is the sample line

cmdkey /generic:"IP Address" /user:"UserName" /pass:"Password"
mstsc /v:"IP Address"
eg:

cmdkey /generic:111.111.111.111 /user:Domain\user.name /pass:password
mstsc /v:111.111.111.111

Thursday, August 16, 2018

windows command : findstr


1.       Check pattern start at beginning
h\s1>findstr /b /c:"2017-01-31 11:37:35,85" Test.txt

/b    = from beginning
/c:  = give search string

Disable and enable windows taskschedular

move "C:\Windows\System32\Tasks\Test\TestPS" "C:\Windows\System32\Tasks\Test\TestPS.bak"


-- enable

move "C:\Windows\System32\Tasks\Test\TestPS.bak" "C:\Windows\System32\Tasks\Test\TestPS" 

Monday, July 23, 2018

Restart windows server at specific time

I day today activities, you may need to restart your servers daily, weekly etc. when you have so many servers, it may be a vert cumbersome task.
1. Restart server - create a script
2. run task at specific time  -create task schedular


1. below is the script
---------------------------------------
shutdown /r /f
----------------------------------------


2. create task

a.) General tab , tick "Run whether user log or not" and "Run with highest privileges"
b.) Trigger give time you need to execute the script

refer previous article to set up command
   https://cgenit.blogspot.com/2018/07/stop-iis-with-task-schedular.html

Stop IIS with Task Schedular


1. create a powershell with needed commands
2. create basic task with executing the powershell script with highest privileges and with whether user log or not.


Below is the powershell script

----------------------------------
# Start-Process powershell -Verb runAs

If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))


$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments
Break
}

# Do your adminy thing here...

iisreset /stop




2. Create Basic task

a.) General tab , tick "Run whether user log or not" and "Run with highest privileges"
b.) Trigger give time you need to execute the script
c.) Actions
     program script  = powershell.exe
    Arguments = -ExecutionPolicy Bypass  C:\Project\stopIIS.ps1








Tuesday, July 17, 2018

Windows task Schedulars

It was pretty hard to find a command to enable and disable the windows task schedulers.
Only way to do that was to rename the job files. Job files basically resides in "Task" folder.

This folder my have below paths
C:\Windows\Tasks
or
C:\Windows\System32\Tasks\


I renamed task files. Better to backup those files before doing this.

let's take a task scheduler created inside "Test" folder and name of the task as "TestPS"

the of the file would look like
C:\Windows\System32\Tasks\Test\TestPS


Disable  - rename as .bak
---------
move "C:\Windows\System32\Tasks\Test\TestPS" "C:\Windows\System32\Tasks\Test\TestPS.bak"

Enable  - rename as original file
------------------------------
move "C:\Windows\System32\Tasks\Test\TestPS.bak" "C:\Windows\System32\Tasks\Test\TestPS" 

Thursday, March 22, 2018

Extracting list of windows services and their status to a text file

Below will extract details of windows services to a text file

Get-Service | Export-Csv -path "C:\Services\services.csv"

With below you can retrieve the running windows services list

Get-Service | where {$_.Status -eq "Running"} | Export-Csv -path "C:\Service\services.csv"

Tuesday, January 23, 2018

Clean Boot

Issue     : the data collector set or one of t its dependencies is already in use
Solution :

Clean boot

Let’s disable all startup items and third party services when booting. This method will help us determine if this issue is caused by a loading program or service. Please perform the following steps:

1. Click the Start Button type "msconfig" (without quotation marks) in the Start Search box, and then press Enter.

Note: If prompted, please click Continue on the User Account Control (UAC) window.

2. Click the "Services" tab, check the "Hide All Microsoft Services" box and click "Disable All" (if it is not gray).

3. Click the "Startup" tab, click "Disable All" and click "OK".

Then, restart the computer. When the "System Configuration Utility" window appears, please check the "Don't show this message or launch the System Configuration Utility when Windows starts" box and click OK.

https://social.technet.microsoft.com/Forums/office/en-US/6c95b8cc-d7f5-46ed-8858-06e4f16204d3/start-and-stop-error-for-performance-counter-in-perfmon-of-windows-server-2008?forum=winserverManagement

Tuesday, December 26, 2017

Find the used ports in machine

We need to find the all the used ports in a machine. We can get to know easily with the command

netstat -ano

this will give the output as

Proto  Local Address          Foreign Address        State           PID
  TCP    0.0.0.0:85             0.0.0.0:0              LISTENING       5180
  TCP    0.0.0.0:135            0.0.0.0:0              LISTENING       892


IF you need to verify the PID with the processes, open Task Manager. This will show 'PID'

netstat -ano > log.txt

Monday, February 29, 2016

Setting screen size to fit the monitor, when login to remote machine

I have been working on a remote environment . I logged to remote desktop using "Remote Desktop Connection" in windows.
to adjust the screen size fit to the monitor follow below steps.

1. click "Remote Desktop Connection" in windows menu.
2. you can see the dialog box. enter your IP.
3. In the dialog box, left bottom corner click "Show Options"
4. go to "Display" tab
5. in the "Display" tab you will find "Display Configuration"
6. drag the slider to fit your screen, most probably to "Large" side. So drag the slider to right.