Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 450 Vote(s) - 3.51 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there a way to make a PowerShell script work by double clicking a .ps1 file?

#11
Or if you want all PS1 files to work the way VBS files do, you can edit the registry like this:

HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\open\command

Edit the Default value to be something like so...

"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -noLogo -ExecutionPolicy unrestricted -file "%1"

Then you can just double click all your .PS1 files like you would like to. in my humble opinion, be able to out of the box.

I'm going to call this "The Powershell De-castration Hack". LOL enjoy!
Reply

#12
You can use the Windows 'SendTo' functionality to make running PS1 scripts easier. Using this method you can right click on
a PS1 script and execute. This is doesn't exactly answer the OP question but it is close. Hopefully, this is useful to others. BTW.. this is helpful for
a variety of other tasks.


* Locate / Search for Powershell.exe
* Right click on Powershell.exe and choose Open File Location
* Right click on Powershell.exe and choose Create Shortcut. Temporarily save some place like your desktop
* You might want to open as Admin by default. Select Shortcut > Properties > Advanced > Open As Admin
* Open the Sendto folder. Start > Run > Shell:Sendto
* Move the Powershell.exe shortcut to the Sendto folder
* You should now be able to right click on a PS1 script.
* Right Click on a PS1 file, Select the SendTo context option > Select the Powershell shortcut
* Your PS1 script should execute.
Reply

#13
This worked for me on Windows 10 and powershell 5.1:

- right click on the .ps1 file
- Open with...
- Choose another app
- Copy the location of powershell.exe to the address bar (by default it won't show windows folder) i.e. C:\Windows\System32\WindowsPowerShell\v1.0
- select powershell.exe
- select "Always use this app to open .ps1 files"
- click OK
Reply

#14
You may set the default file association of `ps1` files to be `powershell.exe` which will allow you to execute a powershell script by double clicking on it.

In Windows 10,

1. Right click on a `ps1` file
1. Click `Open with`
1. Click `Choose another app`
1. In the popup window, select `More apps`
1. Scroll to the bottom and select `Look for another app on this PC`.
1. Browse to and select `C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe`.
1. List item

That will change the file association and `ps1` files will execute by double-clicking them. You may change it back to its default behavior by setting `notepad.exe` to the default app.

[Source][1]


[1]:

[To see links please register here]

Reply

#15
I used this (need to run it only once); also make sure you have rights to execute:

from PowerShell with elevated rights:

Set-ExecutionPolicy=RemoteSigned

then from a bat file:

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

ftype Microsoft.PowerShellScript.1="C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe" -noexit ^&'%%1'

assoc .ps1=Microsoft.PowerShellScript.1

-----------------------------------------
auto exit: remove -noexit

and voila; double-clicking a *.ps1 will execute it.
Reply

#16
In Windows 10 you might also want to delete Windows Explorer's override for file extension association:

`HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ps1\UserChoice`

in addition to the `HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\open\command` change mentioned in other answers.

See

[To see links please register here]

Reply

#17
I wrote this a few years ago (run it with administrator rights):

<#
.SYNOPSIS
Change the registry key in order that double-clicking on a file with .PS1 extension
start its execution with PowerShell.
.DESCRIPTION
This operation bring (partly) .PS1 files to the level of .VBS as far as execution
through Explorer.exe is concern.
This operation is not advised by Microsoft.
.NOTES
File Name : ModifyExplorer.ps1
Author : J.P. Blanc - [email protected]
Prerequisite: PowerShell V2 on Vista and later versions.
Copyright 2010 - Jean Paul Blanc/Silogix
.LINK
Script posted on:

[To see links please register here]

.EXAMPLE
PS C:\silogix> Set-PowAsDefault -On
Call Powershell for .PS1 files.
Done!
.EXAMPLE
PS C:\silogix> Set-PowAsDefault
Tries to go back
Done!
#>
function Set-PowAsDefault
{
[CmdletBinding()]
Param
(
[Parameter(mandatory=$false, ValueFromPipeline=$false)]
[Alias("Active")]
[switch]
[bool]$On
)

begin
{
if ($On.IsPresent)
{
Write-Host "Call PowerShell for .PS1 files."
}
else
{
Write-Host "Try to go back."
}
}

Process
{
# Text Menu
[string]$TexteMenu = "Go inside PowerShell"

# Text of the program to create
[string] $TexteCommande = "%systemroot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command ""&'%1'"""

# Key to create
[String] $clefAModifier = "HKLM:\SOFTWARE\Classes\Microsoft.PowerShellScript.1\Shell\Open\Command"

try
{
$oldCmdKey = $null
$oldCmdKey = Get-Item $clefAModifier -ErrorAction SilentlyContinue
$oldCmdValue = $oldCmdKey.getvalue("")

if ($oldCmdValue -ne $null)
{
if ($On.IsPresent)
{
$slxOldValue = $null
$slxOldValue = Get-ItemProperty $clefAModifier -Name "slxOldValue" -ErrorAction SilentlyContinue
if ($slxOldValue -eq $null)
{
New-ItemProperty $clefAModifier -Name "slxOldValue" -Value $oldCmdValue -PropertyType "String" | Out-Null
New-ItemProperty $clefAModifier -Name "(default)" -Value $TexteCommande -PropertyType "ExpandString" | Out-Null
Write-Host "Done !"
}
else
{
Write-Host "Already done!"
}
}
else
{
$slxOldValue = $null
$slxOldValue = Get-ItemProperty $clefAModifier -Name "slxOldValue" -ErrorAction SilentlyContinue
if ($slxOldValue -ne $null)
{
New-ItemProperty $clefAModifier -Name "(default)" -Value $slxOldValue."slxOldValue" -PropertyType "String" | Out-Null
Remove-ItemProperty $clefAModifier -Name "slxOldValue"
Write-Host "Done!"
}
else
{
Write-Host "No former value!"
}
}
}
}
catch
{
$_.exception.message
}
}
end {}
}
Reply

#18
If you are familiar with advanced Windows administration, then you can use [this ADM package][1] (instructions are included on that page) and allow running PowerShell scripts after double click via this template and Local GPO. After this you can simply change default program associated to .ps1 filetype to `powershell.exe` (use search, it's quite stashed) and you're ready to run PowerShell scripts with double click.

Otherwise, I would recommend to stick with other suggestions as you can mess up the whole system with these administrations tools.

I think that the default settings are too strict. If someone manages to put some malicious code on your computer then he/she is also able to bypass this restriction (wrap it into .cmd file or .exe, or trick with shortcut) and all that it in the end accomplishes is just to prevent you from easy way of running the script you've written.

[1]:

[To see links please register here]



Reply

#19
Simple PowerShell commands to set this in the registry;

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT
Set-ItemProperty -Path "HKCR:\Microsoft.PowerShellScript.1\Shell\open\command" -name '(Default)' -Value '"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -noLogo -ExecutionPolicy unrestricted -file "%1"'
Reply

#20
I tried the top-most answers to this question, but encountered error messages. Then I found the answer here:

[To see links please register here]


What worked well for me was to use this solution:

powershell -ExecutionPolicy Bypass -File script.ps1

You can paste that into a .bat file and double-click on it.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through