A
A
AnViar2011-02-07 16:31:19
PowerShell
AnViar, 2011-02-07 16:31:19

Calling a powershell script with an argument

I have a script written in powershell. For the purity of the experiment, let's say it contains only one line:
exit 0
Create a section in the registry HKEY_CURRENT_USER\Software\Classes\*\shell\mycheck
We see that the item mycheck has appeared in the context menu of the file manager
Create another section in the registry Enter HKEY_CURRENT_USER\Software\Classes\*\shell\checksum\command
its default value
C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -command "& 'C:\Users\myuser\Documents\mycheck.ps1' '%1' "
Respectively replace the user name with your own.
This allows you to pass a filename to the script. Everything works on any file except *.exe !
If you call the script for execution and pass it the name of the exe file (not from the console, but from the context menu), then the program passed as an argument is launched for execution.
I assume that it is solved by some kind of shielding ...
Who has a solution to the problem?
PS OS Windows 7

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2011-02-07
@butteff

Can somehow zayuzat WinExec?

A
amirul, 2011-02-08
@amirul

Created c:\test.ps1 with the following content:

powershell -noexit "echo $args"

Added the following to HKCU\...\test\command\@:
C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -EP Bypass -File C:\test.ps1 "%1"

I did not notice any difference at startup for exe and other files. Generally speaking, a more correct way to pass parameters to scripts is to specify the param block.
test.ps1:
param($FilePath)
powershell -noexit "echo $FilePath"

HKCU\...\test\command\@:
C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -EP Bypass -File C:\test.ps1 -FilePath "%1"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question