Answer the question
In order to leave comments, you need to log in
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
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
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.
Rampage1410 ,
a person who is far from the computer. letters ran the script without problemswhy should such a person even run a script that modifies the registry? What is the purpose?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question