Monday, May 14, 2018

PowerShell change service autorestart

This is script for set autorestart service

#Change these three to match up to the extracted registry data and run as Admin
$YourInput = "00,00,00,00,00,00,00,00,00,00,00,00,03,00,00,00,14,00,00,00,01,00,00,00,60,ea,00,00,01,00,00,00,60,ea,00,00,01,00,00,00,60,ea,00,00"

$RegPath   = 'HKLM:\SYSTEM\ControlSet001\services\servicename'
$AttrName  = "FailureActions"

$hexified = $YourInput.Split(',') | % { "0x$_"}
#IF(!(Test-Path ($RegPath+'\'+$AttrName)))
if (Get-ItemProperty -Path $RegPath -Name $AttrName -ErrorAction SilentlyContinue)
{
    'set'
    Set-ItemProperty -Path $RegPath -Name $AttrName -Value ([byte[]]$hexified)
}
else
{
    'new'
    New-ItemProperty -Path $RegPath -Name $AttrName -PropertyType Binary -Value ([byte[]]$hexified)
}

Wednesday, May 9, 2018

MS SQL script for compress all database

This script was created for the development server. We have high-speed disks and not enough space, and developers need more databases.
Run this script in MS SQL for compress all database


Declare @DatabaseName as NvarChar(500);
Declare @CURSOR CURSOR;
Declare @SQL nvarchar(max);


SET @CURSOR = CURSOR SCROLL
FOR

SELECT name AS [Database Name]
--,recovery_model_desc AS [Recovery Model]
FROM sys.databases
where name not in ('master', 'tempdb', 'model', 'msdb')
and name not like '%veeam%'
and recovery_model_desc!='SIMPLE'

OPEN @CURSOR

FETCH NEXT FROM @CURSOR INTO @DatabaseName
WHILE @@FETCH_STATUS = 0
BEGIN
print @DatabaseName;
SET @SQL='';
SET @SQL= @SQL+
'USE [master];

ALTER DATABASE ['+@DatabaseName+'] SET RECOVERY SIMPLE WITH NO_WAIT;

use ['+@DatabaseName+'];
EXEC sp_MSforeachtable ''ALTER INDEX ALL ON ? REBUILD WITH (DATA_COMPRESSION = PAGE)'';

EXEC sp_MSforeachtable ''ALTER TABLE ? REBUILD PARTITION = ALL WITH (DATA_COMPRESSION = PAGE)'';

USE ['+@DatabaseName+'];

DBCC SHRINKDATABASE(N'''+@DatabaseName+''', 1 );
';
print @SQL
EXEC(@SQL);



FETCH NEXT FROM @CURSOR INTO @DatabaseName
END
CLOSE @CURSOR

GO

Wednesday, April 25, 2018

Arduino button sketch

I decided to work out arduino.
I had a problem with sticking the buttons, here is an attempt to solve the problem

const int relayPin = 7;
const int buttonPin = 2;
bool buttonpress = false;
bool stateswitch = false;


int buttonState = 0;
int lastButtonState = 0;
unsigned long buttonOnTime;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(relayPin, OUTPUT);
  pinMode(buttonPin, INPUT);
}

void loop() {

  buttonState = digitalRead(buttonPin);
  if ((buttonState == HIGH) && (millis() - buttonOnTime > 500)) {
    buttonOnTime = millis();
    if (stateswitch)
    {
      Serial.println("Button off");
    }
    else
    {
      Serial.println("Button on");
    }
    stateswitch = !stateswitch;
    //    delay(500);
  } else if ((buttonState == HIGH))
  {
    buttonOnTime = millis();
  }



  //
  //  buttonState = digitalRead(buttonPin);
  //   if ((buttonState == HIGH)) {
  //
  //    Serial.print("Button:");
  //    Serial.println(buttonState);
  //    Serial.print("Relay:");
  //    stateswitch = digitalRead(relayPin);
  //    Serial.println(stateswitch);
  //    digitalWrite(relayPin, !stateswitch);
  //
  //
  //   }
  // delay(200);
  //
  //  if (buttonState == HIGH) {
  //    //Serial.println("HIGH");
  //    digitalWrite(relayPin, HIGH);
  //  }
  //  else
  //  {
  //    //Serial.println("LOW");
  //    digitalWrite(relayPin, LOW);
  //  }
  // put your main code here, to run repeatedly:
  //  digitalWrite(relayPin, LOW);
  //  delay(5000);
  //  digitalWrite(relayPin, HIGH);
  //  delay(5000);
}

Monday, March 26, 2018

Powershell скрипт для ускорения настройки 1С

Get-NetFirewallRule -DisplayName "Remote Desktop*" | Set-NetFirewallRule -enabled true
Get-NetFirewallRule -DisplayName "Удаленный рабочий стол*" | Set-NetFirewallRule -enabled true


$firewallRuleMSSQL = Get-NetFirewallRule -DisplayName 'MS SQL'
if (-Not $firewallRuleMSSQL)
{New-NetFirewallRule -DisplayName 'MS SQL' -Enabled true -LocalPort 1433 -Profile DOMAIN -Protocol TCP}

$firewallRuleragent = Get-NetFirewallRule -DisplayName 'ragent.exe'
if (-Not $firewallRuleragent)
{New-NetFirewallRule -DisplayName 'ragent.exe' -Enabled true -Program "c:\Program Files\1cv8\8.3.10.2561\bin\ragent.exe" -Profile DOMAIN}

$firewallRulermngr = Get-NetFirewallRule -DisplayName 'rmngr.exe'
if (-Not $firewallRulermngr)
{New-NetFirewallRule -DisplayName 'rmngr.exe' -Enabled true -Program "c:\Program Files\1cv8\8.3.10.2561\bin\rmngr.exe" -Profile DOMAIN}

$firewallRulerphost = Get-NetFirewallRule -DisplayName 'rphost.exe'
if (-Not $firewallRulerphost)
{New-NetFirewallRule -DisplayName 'rphost.exe' -Enabled true -Program "c:\Program Files\1cv8\8.3.10.2561\bin\rphost.exe" -Profile DOMAIN}

Add-LocalGroupMember -Group "Администраторы" -Member "kt\1Cv8", "kt\SystemVeeam"

#Прописываем зависимость sql от виртуального диска
$REGMSSQL = Get-ItemProperty -Path HKLM:\SYSTEM\ControlSet001\Services\MSSQLSERVER -name DependOnService
if (-Not $REGMSSQL)
{New-ItemProperty -Path "HKLM:\SYSTEM\ControlSet001\Services\MSSQLSERVER" -Name "DependOnService" -value "SPVVEngine" -PropertyType MultiString}
else
{Set-ItemProperty -Path "HKLM:\SYSTEM\ControlSet001\Services\MSSQLSERVER" -Name "DependOnService" -Value "SPVVEngine"}

#Прописываем зависимость 1С от скула
$REGMSSQL = Get-ItemProperty -Path "HKLM:\SYSTEM\ControlSet001\Services\1C:Enterprise 8.3 Server Agent (x86-64)" -name DependOnService
if (-Not $REGMSSQL)
{New-ItemProperty -Path "HKLM:\SYSTEM\ControlSet001\Services\1C:Enterprise 8.3 Server Agent (x86-64)" -Name "DependOnService" -value "Tcpip", "Dnscache", "lanmanworkstation", "lanmanserver", "MSSQLSERVER" -PropertyType MultiString}
else
{Set-ItemProperty -Path "HKLM:\SYSTEM\ControlSet001\Services\1C:Enterprise 8.3 Server Agent (x86-64)" -Name "DependOnService" -Value "Tcpip", "Dnscache", "lanmanworkstation", "lanmanserver", "MSSQLSERVER"}

Thursday, February 1, 2018

PDFtoPrinter for Windows

История: 1С и автоматизация работы под управляемые формы. Необходима печать PDF, фононо. Так и не нашел нормальной реализации.
Берем этот файлик https://www.dropbox.com/s/e1ttfk8mfy69ck1/PDFtoPrinter.exe?dl=1
качаем програмку для формирование настроек https://www.tracker-software.com/product/pdf-xchange-viewer, ставим, делаем настройки печати и сохраняем их в том же каталоге под именем "PDF-XChange Viewer Settings.dat", что и exe.
В отличии от adobe reader и foxit не оставляет зависших процессов в памяти, плюс как уже писал ранее возможна настройки печати


PDFtoPrinter for Windows:

'via Blog this'