Adding Registry Keys on Remote Windows Server Machine not working - msbuild

I have two domain joined machines (ServerA & ServerB) running Windows Server 2012 R2.
I want to add new registry key in ServerB from ServerA.
I am running below command in ServerA:
reg add \\ServerB\HKLM\SOFTWARE\MyCompany\MyApp /v Username /t REG_SZ /d ABC123 /f
Output from above command: The operation completed successfully.
But when I checked registry in ServerB, I didn't find the newly added key.
I am using MSBuild to run this command inside a script in ServerA.
Deploy.proj
<Target Name="Deploy_Registry">
<!--Make sure the Remote Registry service is started-->
<ServiceController MachineName="ServerB" ServiceName="Remote Registry" Action="Start" ContinueOnError="true"/>
<Exec Command='reg add \\ServerB\HKLM\SOFTWARE\MyCompany\MyApp /v Username /t REG_SZ /d ABC123 /f' ContinueOnError='false' /></Target>

Related

Setting up Password Free SSH from Linux to Windows 10

I'm trying to set up a password free ssh path from a linux server to a windows machine. I currently have MobaSSH running on the windows machine. I can ssh from the linux server to the windows machine fine and execute commands just fine but I have to enter a password.
I create a public RSA key on the linux system and using WinSCP I copied the file over to the C:\Users\MyUserName\.ssh folder and restarted the MobaSSh service on the windows machine.
It still won't let me ssh in without a password. What am I missing here? Any help vastly appreciated.
OpenSSH is available for Windows 10 and has worked very reliably for me. I can consistently connect from a Linux machine without a password. Here is how to set it up.
upgrade to Windows 10 version 1809 or higher
check via: powershell -c "(Get-Item 'HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion').GetValue('ReleaseID')"; see also systeminfo | findstr /B /C:"OS Name" /C:"OS Version" for Pro vs. Home, build number
upgrade via Windows Update settings or Download Windows 10 (the latter works around an issue where some systems are stuck at 1803)
install SSH client and server (as administrator; source) - in Windows PowerShell:
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Start-Service sshd # remote login should be possible following this command
Set-Service -Name sshd -StartupType 'Automatic'
Get-NetFirewallRule -Name *ssh* # there should be a firewall rule named "OpenSSH-Server-In-TCP" # optional
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0 # optional
enabling public key login for administrators (source) - from Linux command-line:
scp ~/.ssh/id_rsa.pub administrator#remote_computer_name:'C:\ProgramData\ssh\administrators_authorized_keys' # if using an alternate method, ensure file is not UTF-16 encoded
icacls C:\ProgramData\ssh\administrators_authorized_keys /remove "NT AUTHORITY\Authenticated Users"
icacls C:\ProgramData\ssh\administrators_authorized_keys /inheritance:r
get-acl C:\ProgramData\ssh\ssh_host_dsa_key | set-acl C:\ProgramData\ssh\administrators_authorized_keys
enabling public key login for non-administrators - in Windows PowerShell:
Install-Module -Force OpenSSHUtils -Scope AllUsers # for: Repair-AuthorizedKeyPermission
cd C:\Users\...
ssh-keygen # create ~/.ssh
# add key(s) to ~/.ssh/authorized_keys
$ConfirmPreference = 'None'; Repair-AuthorizedKeyPermission -FilePath .ssh\authorized_keys
# if above fails, try ''%%Set-ExecutionPolicy Unrestricted -Scope CurrentUser%%''; see also https://github.com/PowerShell/Win32-OpenSSH/issues/1245#issuecomment-440388604

SQL Server enters single user mode after cmd installation

I am installing SQL Server Express 2017 using the command line. Once the install is done I use a batch file to create a database. The database creation fails giving a message that : login with 'sa' failed, The server is in single user mode
I have used the installation syntax given on the msdn website and my DB creation script is a batch file which creates a DB after confirming that SQL 2017 is installed. I am logging the errors in a file which gives me the single mode error information. Below is the installation statement I am using through cmd
SETUP.exe /q /ACTION=Install /BROWSERSVCSTARTUPTYPE=Automatic /SQLSVCSTARTUPTYPE=Automatic /FEATURES=SQL /INSTANCENAME=SQLEXPRESS /SQLSVCACCOUNT="NT AUTHORITY\Network Service" /SQLSYSADMINACCOUNTS="BUILTIN\ADMINISTRATORS" /AGTSVCACCOUNT="NT AUTHORITY\Network Service" /SQLSVCINSTANTFILEINIT="True" /IACCEPTSQLSERVERLICENSETERMS /SAPWD=<Password> /SECURITYMODE=SQL
The code to install the DB is :
%OSQLEXE% -S %SERVER% -U %USERNAME% -P %PASSWORD% -i "%AgentPath%\CreateDatabase.sql" >> c:\InstallLog.txt
Ideally my DB should be created but for some reason I get this error. Can someone please help?

Getting error in SQL Server executing get-wmiobject

I am trying to execute following PowerShell query in SQL Server
xp_cmdshell "get-WmiObject Win32_LogicalDisk -AV-RISCVMSQL114 | Format-Table -Property DeviceID,FreeSpace,Size"
After executing this, I am getting error:
'get-WmiObject' is not recognized as an internal or external command,
operable program or batch file.
I want to execute this command in all SQL Servers. It's getting executed on SQL Server 2008, but on SQL Server 2012, it's throwing that error due to version or some PowerShell component is not installed.
Can you to please look at the code and let me know
Try:
xp_cmdshell 'PowerShell.exe -noprofile -command "get-WmiObject Win32_LogicalDisk -AV-RISCVMSQL114 | Format-Table -Property DeviceID,FreeSpace,Size"'
If this doesn't work logon to the server open PowerShell with administrator rights. Type Get-ExecutionPolicy and check that Execution Policy is set to Unrestricted. If it isn't then enter the following, then type 'A' (Yes to All):
Set-ExecutionPolicy Unrestricted
If this still doesn't work try upgrading to at least PowerShell V3. But if this is not possible you can try repair your corrupt PowerShell V2 WMI repository with:
winmgmt /verifyrepository
If repository is found to be inconsistent run Winmgmt /salvagerepository and Winmgmt /resetrepository and verify after each. If it is still inconsistent try the following steps:
Go to Task Manager>> Services >> Open Service >> Windows Management Instrumentation service, and change the start up type to Manual.
Stop the WMI service:
net stop winmgmt
Rename the repository folder (C:\Windows\System32\wbem\Repository) to some else 'Repository_OLD'.
Start the WMI service:
net start winmgmt
Set the service back to auto start.
Failing Re-register all of the dlls and recompile the .mofs in the Wbem directory with the following .bat script and then reboot.
#echo off
sc config winmgmt start= disabled
net stop winmgmt /y
%systemdrive%
cd %windir%\system32\wbem
for /f %%s in (‘dir /b *.dll’) do regsvr32 /s %%s
wmiprvse /regserver
winmgmt /regserver
sc config winmgmt start= auto
net start winmgmt
for /f %%s in (‘dir /s /b *.mof *.mfl’) do mofcomp %%s

Uninstalling IE 10 Using a batch file

I found a way to uninstall IE 10 using a batch file which below and it works great like it's suppose to. It uninstalls and restarts the computer after about a minute.
FORFILES /P %WINDIR%\servicing\Packages /M Microsoft-Windows-InternetExplorer-10..mum /c "cmd /c echo Uninstalling package #fname && start /w pkgmgr /up:#fname /norestart /quiet"
shutdown -r
But I wanted to take this further and Hide IE 10 from windows updates which will prevent windows to install this update actually in the future and to do that, Microsoft provides an executable file which you can download from here
http://www.microsoft.com/en-us/download/details.aspx?id=36512 After extracting this executable, you get 3 files, IE10_Blocker.adm, IE_blocker.cmd and IE10_BlockerHelp.htm and Microsoft instructions are "In the Command Prompt, goto the folder where you have extracted these 3 files and type “ie9_blocker.cmd /B” and hit Enter to set the blocker on the machine."
I decided to make one batch file for all this so right now I got this far.
FORFILES /P %WINDIR%\servicing\Packages /M Microsoft-Windows-InternetExplorer-10..mum /c "cmd /c echo Uninstalling package #fname && start /w pkgmgr /up:#fname /norestart /quiet"
mkdir “C:\IE10”
copy /Y \file01p\Users\test\public\IE Update blocker\IE10*.* “C:\IE10”
start /d C:IE10\IE10_Blocker.cmd /b
shutdown -r
mkdir “C:\IE10” This command is suppose to create the directory called IE10 on C drive
copy /Y \file01p\Users\test\public\IE Update blocker\IE10*.* “C:\IE10” This command will copy those executable from the network public folders to their C:\IE10 which I just created in the previous step.
This script doesn't work. Only up to uninstalling IE 10 it works but it doesn't create the directory and so it doesn't copy the files from the network. How can do this?
Thanks
Thanks
Try running your batch as administrator.
in an administrator : command prompt it makes the directory without issue.
also, it could be that you do not have access to make the directory on C:
you could try locating it elsewhere that you are sure you have write access.

Running commands on Remote machine using PsExec from Msbuild invoked via Jenkins

I am using psexec(with MSbuild Script) to run an xCopy on a server from Jenkins(Hudson). The command runs ok when run through Command Prompt(as System user), but gives the following error when tried using Jenkins. This is the command I am using from Msbuild script:
psexec \\<RemoteMachine> /accepteula -i -u <Domian\User> -p <Pass> -s cmd /c xcopy <Path1> <Path2> /e /i
PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com
The handle is invalid.
Connecting to ..
Couldn't access :
Connecting to ...
**error MSB3073: The command "psexec \\<RemoteMachine> /accepteula -i -u <Domian\User> -p <Pass> -s cmd /c xcopy <Path1> <Path2> /e /i " exited with code 6.**
I have tried too many options but no luck so far.
Does anyone tried the same using Jenkins? Help will be really appreciated.
Are there any other ways to achieve this using some other tools without any problem. Please share.
Just wanted to post the solution here, as I figured it after some time.
The Remote Machine should have this user added in the Administrators Group.
This will resolve the connection issue. :)