Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 Powershell, Execute file

views
     
TSUbuntuClient
post May 29 2025, 04:00 PM, updated 7 months ago

Regular
******
Senior Member
1,417 posts

Joined: Jun 2007
From: /puchong/cyberjaya/klang



Hi,

How to make batch script file so i can run from powershell with normal user?
CODE
# Make sure you're running [Powershell] as an Administrator.
Get-Service ssh-agent | Set-Service -StartupType Manual

# Start the service
Start-Service ssh-agent

# This should return a status of Running
Get-Service ssh-agent

# Now load your key files into ssh-agent
ssh-add "C:\Users\Tech Support\.ssh\id_rsa2.pub"


Now i run as manual and run as administrator.

Please advice.

Thanks.
TSUbuntuClient
post May 30 2025, 09:14 PM

Regular
******
Senior Member
1,417 posts

Joined: Jun 2007
From: /puchong/cyberjaya/klang



After google around, i have found the solution. It need change policy as describe in article below.
https://www.pdq.com/blog/writing-your-first...ershell-script/

The script need to be assign to run with powershell. You can use notepad ++ and save the file as .ps1. Then under file properties, choose run with administrator.
jimkayle
post Sep 25 2025, 02:28 AM

New Member
*
Newbie
23 posts

Joined: Apr 2017


The reason you need admin rights is because Set-Service and Start-Service touch the Service Control Manager, which requires elevated privileges. A normal user can’t do that by design. What you can do instead is configure the ssh-agent service to start automatically once, as admin, and then your batch/PowerShell script only needs to run the ssh-add part. That way normal users can use it without elevation.
Xploit Machine
post Sep 25 2025, 10:58 AM

❤️ 孤独な旅行者 ❤️​
*******
Senior Member
7,257 posts

Joined: Nov 2008
From: SINGAPORE💃

Windows has a security system that separates standard user actions from administrative actions. Modifying or starting system services (like ssh-agent) is considered a privileged operation that could affect the entire system .. "Run as administrator" option is how you temporarily "elevate" your privileges for a specific task, and the UAC prompt is the security gateway that ensures you have the authority to do so ..

try save this file as .PS1 and run using PowerShell

CODE
# setup-ssh-agent.ps1

Write-Host "Configuring the SSH Agent service..."
Get-Service ssh-agent | Set-Service -StartupType Manual

Write-Host "Starting the SSH Agent service..."
Start-Service ssh-agent

Write-Host "Current service status:"
Get-Service ssh-agent

Write-Host "Adding your SSH key to the agent..."
try {
   ssh-add "C:\Users\Tech Support\.ssh\id_rsa2"
   Write-Host "SSH key added successfully!" -ForegroundColor Green
}
catch {
   Write-Host "Error adding SSH key. Is the path correct and is the key passphrase-protected?" -ForegroundColor Red
}

# This keeps the window open so you can see the output
Read-Host "Press Enter to exit"


 

Change to:
| Lo-Fi Version
0.0142sec    0.69    5 queries    GZIP Disabled
Time is now: 16th December 2025 - 10:59 PM