Search the Registry key if the Registry Key delete through command Prompt - command-line

I want to search the Registry Key, if the registry key is exist it has to delete the Registry key through command Prompt.

I'd try using Powershell,
check out
http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/12/weekend-scripter-use-powershell-to-easily-modify-registry-property-values.aspx
I am sure that there are loads of other great examples good luck

Related

How to run powershell quietly from registry key?

I've added an option to copy a proper UNC path to the context menu of all directories via PowerShell.
Edit:
I didn't mention that I'm actually using two different keys: One to copy the UNC of the current directory, and one to copy it from a different directory. I didn't think it would make a difference, but it does.
End Edit
Currently, the key value is as follows:
powershell.exe -WindowStyle Hidden -Command . <path I have to censor>\Save-To-Clipboard.ps1 \"%L%\"
Expected behaviour:
The PowerShell script is run quietly.
Actual behaviour:
A PowerShell Window pops up and closes itself.
The same thing happens with cmd.
I've tried using a VBS wrapper as well, but it needs the current path as an argument, which I can't figure out how to do. Simply putting it after the filename as you would in the command line results in the error:
This file does not have an app associated with it for performing this
action. Please install an app or, if one is already installed, create
an association in the Default Apps settings page.
Key value here:
<path I have to censor>\ClunkyWrapper.vbs \"%L%\"
Admittedly, this is my first time running a command from a registry key, and I can't seem to find any resources about this topic. (I might just not know what exactly to google for.) So I would be thankful for more general information on how to run commands from registry keys as well.
Okay, I found a way.
First of all, apparently whether you need to use %L% or %V% depends on the key. I can't tell you why, unfortunately.
That solves the error message of the VBA script, but it still wouldn't run like this.
So I then used wscript.exe, and it finally worked.
wscript.exe <secret path>\ClunkyWrapper.vbs "%V%"

Error: Can not install PostgreSQL 9.5.11 on Windows 10 machine

So, I came across the same issue as posted here, BUT my error log says something different (see below, please). I have been trying to install PostgreSQL 9.5.11 on Windows 10 (x64) using Enterprise DB interactive installer. But, no success (I am aware about the BigSQL installers but I prefer the Enterprise DB one :)).
I googled already and tried the suggested solutions here, here and here. However, no use. Can someone please help me to resolve this error?
Here is the lovely error message I am getting:
Log started 04/17/2018 at 11:28:34
Preferred installation mode : qt
Trying to init installer in mode qt
Mode qt successfully initialized
Executing C:\my_user\AppData\Local\Temp/postgresql_installer_676baef523/temp_check_comspec.bat
Script exit code: 0
Script output:
"test ok"
Script stderr:
Could not find registry key HKEY_LOCAL_MACHINE\SOFTWARE\PostgreSQL\Installations\postgresql-x64-9.5 Data Directory. Setting variable iDataDirectory to empty value
Could not find registry key HKEY_LOCAL_MACHINE\SOFTWARE\PostgreSQL\Installations\postgresql-x64-9.5 Base Directory. Setting variable iBaseDirectory to empty value
Could not find registry key HKEY_LOCAL_MACHINE\SOFTWARE\PostgreSQL\Installations\postgresql-x64-9.5 Service ID. Setting variable iServiceName to empty value
Could not find registry key HKEY_LOCAL_MACHINE\SOFTWARE\PostgreSQL\Installations\postgresql-x64-9.5 Service Account. Setting variable iServiceAccount to empty value
Could not find registry key HKEY_LOCAL_MACHINE\SOFTWARE\PostgreSQL\Installations\postgresql-x64-9.5 Super User. Setting variable iSuperuser to empty value
Could not find registry key HKEY_LOCAL_MACHINE\SOFTWARE\PostgreSQL\Installations\postgresql-x64-9.5 Branding. Setting variable iBranding to empty value
Could not find registry key HKEY_LOCAL_MACHINE\SOFTWARE\PostgreSQL\Installations\postgresql-x64-9.5 Version. Setting variable brandingVer to empty value
Could not find registry key HKEY_LOCAL_MACHINE\SOFTWARE\PostgreSQL\Installations\postgresql-x64-9.5 Shortcuts. Setting variable iShortcut to empty value
Could not find registry key HKEY_LOCAL_MACHINE\SOFTWARE\PostgreSQL\Installations\postgresql-x64-9.5 DisableStackBuilder. Setting variable iDisableStackBuilder to empty value
[11:28:39] Existing base directory:
[11:28:39] Existing data directory:
[11:28:39] Using branding: PostgreSQL 9.5
[11:28:39] Using Super User: postgres and Service Account: NT AUTHORITY\NetworkService
[11:28:39] Using Service Name: postgresql-x64-9.5
Executing cscript //NoLogo "C:\my_user\AppData\Local\Temp\postgresql_installer_676baef523\prerun_checks.vbs"
Script exit code: 1
Script output:
CScript Error: Loading script "C:\my_user\AppData\Local\Temp\postgresql_installer_676baef523\prerun_checks.vbs" failed (Access is denied. ).
Script stderr:
Program ended with an error exit code
Error running cscript //NoLogo "C:\my_user\AppData\Local\Temp\postgresql_installer_676baef523\prerun_checks.vbs": Program ended with an error exit code

VSCode Keep asking for passphrase of SSH key

I have recently upgrade my VSCode version 1.10.2.
As I put passphrase on my private SSH key, it started to ask for it frequently even when I entered it multiple times, which is very annoying. Is there anyway I can get rid of it? Thanks.
Yes, you can avoid this prompt, without removing the passphrase.
To do so is usually fairly simple and relies on the ssh-agent program. First, before starting VSCode, at a bash shell prompt, run:
$ eval `ssh-agent`
This will start an ssh-agent process in the background that will remember the decrypted private key in its memory. The reason for eval is ssh-agent prints two environment variable settings that need to be added to the shell. (You can also just run it normally, then manually copy and paste its output back into the shell.)
Next, run:
$ ssh-add
This will prompt you for your passphrase, after which ssh-agent will provide private key services to any other process that needs it.
Finally, start VSCode from the same shell you ran the first command:
$ code
This way VSCode will inherit the environment variables it needs to get key services from ssh-agent, and therefore will not prompt for your passphrase so long as the ssh-agent process continues running.
Further References
Unfortunately, despite it being so useful, good (concise, readable) documentation on ssh-agent is hard to find. But here are some possibilities:
The man page is, as is typical for man pages, heavy on detail and light on examples.
The article http://rabexc.org/posts/using-ssh-agent is pretty good, and it covers some more advanced situations, especially agent forwarding.
The Stack Exchange question, "what's the purpose of ssh-agent?" is also good.
For Windows 10, if you have stumbled across this issue using the Remote - SSH plugin, run the following in powershell (as admin):
# Make sure you're running PowerShell as an Administrator
Set-Service ssh-agent -StartupType Automatic
Start-Service ssh-agent
Get-Service ssh-agent
(As suggested by the documentation that is pointed to by this comment on a git (non-)issue.)
The only solution I've found was remove the passphrase:
ssh-keygen -p
It will ask your current passphrase and leave blank the new passphrase to remove it.
Disable auto fetching with git.autofetch = false in the settings
There is a great guide on how to solve it in Windows here:
https://www.cgranade.com/blog/2016/06/06/ssh-keys-in-vscode.html
Summary:
Install Required Software (Putty)
Setup Private Keys (use ssh-keygen which will create private and public keys in .ssh folder)
Set up SSH Agent: have Pageant tool run on Windows startup
import your key to ppk format
Run PuTTYgen from the Start Menu and select File → Load Key.... From there, navigate to C:\Users\.ssh\ and select id_rsa (the private key). You may have to drop down the file types selector in the dialog box to see this, as PuTTYgen defaults to filtering out everything but files ending in *.ppk. Once selected, you’ll be prompted by PuTTY to unlock your key by typing in your passphrase. Do so, and PuTTYgen will show the corresponding public key. Select File → Save private key to export your private key in PuTTY, rather than OpenSSH, format. I suggest saving it as id_rsa.ppk in the same folder as id_rsa
run Pageant
Finally, run Pageant from the Start Menu (in the future, this will be handled automatically by the shortcut we created above). This will add a new icon to your system tray. It may be hidden by the arrow; if so, click the arrow to make all fo the system tray icons visible. Right-click on Pageant and select Add Key. Browse to where you saved id_rsa.ppk and select it. You’ll be prompted to unlock your key. Upon doing so, your unlocked key will then be made available in Pageant until you log out or quit Pageant.
Add fingerprints, in shell run one of those two (depending on your needs)
'C:\Program Files (x86)\PuTTY\plink.exe' git#github.com
'C:\Program Files (x86)\PuTTY\plink.exe' git#bitbucket.org
Configure GIT_SSH to be C:\Program Files (x86)\PuTTY\plink.exe

Problems with .ssh directory in windows XP

I am trying to use (git) ssh with SSH keys in windows XP using Powershell.
When I run ssh it always attempts to get the keys and known hosts from a location that doesn't really make sense in a windows context.
i.e.
prompt> ssh -vvv user#server
...
debug1: Trying private key: /.ssh/id_rsa
debug3: no such identity: /.ssh/id_rsa
...
prompt>
In windows 7 this behaviour seems to cause the .ssh directory to be created or read from the c:\Program Files (x86)\Git\bin. However, in Windows XP this does not seem to be the behaviour
Try to specify it directly:
ssh -i $HOME/.ssh/id_rsa
It seems that this problem is caused / related to the way environment variables work in Powershell and Windows.
Utimately it would seem that (git) ssh is picking up the value of $env:HOME which in powershell is different to the value of $HOME.
In Windows 7 this value can be set with the command setx HOME /c/Users/james. If you wanted to set your home location to be a drive (i.e. z:) you would have to use the trailing slash else setx will assume it is a flag. i.e. setx HOME /z/
This will have effect in the next Powershell window that you open (but not in the current one)
In windows XP setx is not always available (it is on SP2 and SP3) and if you read the Microsoft documentation you might believe that setx is just a short hand for reg add but this is actually a lie.
If you use the command reg add HKCU\Environment /v HOME /t REG_SZ /d "/c/Documents and Settings/james/"
While this updates the registry in seemingly the same way as setx. The changes are not avilable in (Git) ssh until after a logoff / login cycle.

Powershell set-itemproperty doesn't change registry setting

I have a script that I run to lockdown a windows 7 computer to run a VM Client when booted.
when it runs it creates the local user account that is going to be used for logging in
Checks for the DefaultPassword reg key and if is not there creates the key
It sets the registry values for
AutoAdminLogon value to 1
DefaultdomainName value to the local machine name
DefaultPassword value to the local user account password
DefaultUsername value to the local user that was setup in the script
ForceAutoLogon value to 1
LogonType value to 0
After this is done the computer reboots and should login as the local user automatically
but it doesn't. I've check the keys and prior to the reboot everything is correct. But after reboot its back to what it was before the script was run.
The weird thing is .. if I run the script again .. everything works.
Has anyone got any ideas why this is happening???
As I said if I run the same script again AFTER the reboot it set the registry entries with no problems and they stay after the 2nd reboot. So I'm thinking there something going on after the first reboot .. my first thoughts where Domain Group Policies but if that was the case then I would get the same results on the 2nd run of the script and reboot. I have another script that I run after this one that sets the local user startup to launch the VMClient and disables taskmanager , lockworkstation, and change password functions when they use ctlr-alt-del keys, which is done in the registry .. this work just fine.
My instinct says that it's a feature of ForceAutoLogon, rather than a problem with PowerShell's Set-ItemProperty.
ForceAutoLogon Article
Extract:
"In addition to logging on an account automatically, the ForceAutoLogon setting also logs you back on after you log off.
Setting the ForceAutoLogon setting effectively locks out all users aside from the one you are forcing."
After search and search for a resolution to my problem I finally found the issue.
One of the Forums I check mentions the AUTOLOGONCOUNT reg key .. when I looked at my computer it was not there.. after I had rebooted the computer .... This is a Corporate Computer and we use MDT to reimage the computers ... so it does autologon a couple of times. Which when it is done the count is set to zero and the autologon is set to zero .. but the AUTOLOGONCOUNT reg key is still there. so when I ran my script it would set it and at reboot .. unset it .. DUH me LOL .. any I re-image a computer and delete this key and ran my powershell script and all is good
thanks for those that gave me ideas