R
R
Rampage14102021-07-06 13:44:38
PowerShell
Rampage1410, 2021-07-06 13:44:38

How to change the value of a registry key from the command line?

I can't change the registry value (you need CMD or Powershell).
CMD does not accept key value powershell.exe "-Command" "if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & '%1'" , gives syntax error: ERROR: Invalid syntax.
And Powershell gives an argument error.

Command example in CMD:
REG ADD HKCR\Microsoft.PowerShellScript.1\Shell\runas\command /v (Default) /t REG_SZ /d powershell.exe "-Command" "if((Get-ExecutionPolicy ) -ne 'AllSigned' ) { Set-ExecutionPolicy -Scope Process Bypass }; & '%1'"

Powershell example:
New-ItemProperty -Path HKCR:\Microsoft.PowerShellScript.1\Shell\runas -Name Default -PropertyType String -Value "powershell.exe "-Command" "if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set- ExecutionPolicy -Scope Process Bypass }; & '%1'""

Error:
New-ItemProperty : A positional parameter cannot be found that accepts argument '-Command if'.
At line:1 char:1
+ New-ItemProperty -Path HKCR:\Microsoft.PowerShellScript.1\Shell\runas ...
+ ~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-ItemProperty], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.

& : The term '%1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:233
+ ... 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & '%1'""
+ ~~~~
+ CategoryInfo : ObjectNotFound: (%1:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
MaxKozlov, 2021-07-06
@MaxKozlov

On the question - deal with quotes.
For life - don't do it!
Your goal is kind of vague.
Instead of setting policies once as you need, you are making some kind of game

A
Alexey Dmitriev, 2021-07-06
@SignFinder

Google "how to change the registry key from cmd" or "how to change the registry key from powershell"
You don't have examples - but some kind of nonsense.
In the example for cmd, for some reason, powershell is called, to which the command line is passed as a parameter, in the example with powershell - in general, the same thing - but also a cmdlet for creating keys - New-ItemProperty, instead of a cmdlet for changing registry keys Set-ItemProperty.

R
Roman Bezrukov, 2021-07-06
@NortheR73

Rampage1410 ,

a person who is far from the computer. letters ran the script without problems
why should such a person even run a script that modifies the registry? What is the purpose?
Push the script into the GPO, autorun, scheduler... you can still run it yourself remotely via Invoke-Command or PSSession

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question