Giter Site home page Giter Site logo

Comments (2)

jonax69 avatar jonax69 commented on August 11, 2024

Dirty cheap solution: Script to do the reg hack to stop warnings, call ocsinventory and revert registry to it's initial state.

Another possibility is to create two dumb plugins to do the registry things. In that case take in care that vbs are run first and ps1 later on.

from windowsagent.

jonax69 avatar jonax69 commented on August 11, 2024

FWIW, I mark the question as closed. I paste the piece of code I wrote to get it working. In my case I try to leave the computer registry in the previous state when OCSInventory has finished. If not wanted, most of the function code can be deleted.

`#*****************************************************************

Script: ocsUNC.ps1

Version: 1.0

Autor: Jon de Isusi

Date: 20/10/2017

Descripción: ejecución de OCSInventory desde una ruta UNC sin necesidad de hacer mapeos

Se modifica el registro y luego se revierte al estado anterior

#*****************************************************************

definiciones

$sOCS = "OCSinventory.exe"
$sOCSdir = "\RUTAUNC\CARPETAOCS"
$sOCSurl = "https://servidorocs/ocsinventory"
$sOCScert = "certificado.cer"
$sargs_OCS = "/NO_SERVICE /S /SERVER=$sOCSurl /NOTAG /hkcu /ssl=1 /ca=""$sOCScert"""

función para habilitar o deshabilitar los mensajes de UNC teniendo en cuenta un estado anterior

se generan 2 valores para guardar el valor anterior y controlar que no se esté en medio de una ejecución

Function controlarUNCWarning ( [bool]$bHabilitar ){
$REGKEY = "HKCU:\Software\Microsoft\Command Processor"
$VALOR = "DisableUNCCheck"
$VALORBACKUP = "DisableUNCCheckBackup"
$VALOREXEC = "OCSExec"

if ( -not ($bHabilitar) ) {
	# deshabilitar mensajes de warning
	try{
		if ( (Get-ItemPropertyValue -Path $REGKEY -Name $VALOR ) -eq 0){
			# estaba a 0, lo ponemos a 1
			New-ItemProperty -Path $REGKEY -Name $VALOR -Value 1 -PropertyType DWORD -Force | Out-Null
		} else {
			try{
				# get-itempropertyvalue a la fecha actual no admite erroraction silentlycontinue.
				# revisamos que no esté en medio de una ejecución
				Get-ItemPropertyValue -Path $REGKEY -Name $VALOREXEC | Out-Null
			} catch {
				# ya existía a 1 y no estamos en una ejecución, creamos una copia del valor para luego restaurarla
				New-ItemProperty -Path $REGKEY -Name $VALORBACKUP -Value 1 -PropertyType DWORD -Force | Out-Null
			}
		}
	} catch {
		# no existe el valor, se crea
		New-ItemProperty -Path $REGKEY -Name $VALOR -Value 1 -PropertyType DWORD -Force | Out-Null
	}
	
	try{
		# se crea un valor de control de ejecución por si se para
		New-ItemProperty -Path $REGKEY -Name $VALOREXEC -Value 1 -PropertyType DWORD -Force | Out-Null
	} catch {
	}
} else {
	# habilitar mensajes de warning
	try{
		if (Get-ItemPropertyValue -Path $REGKEY -Name $VALORBACKUP){
			# al deshabilitarlos el valor ya estaba a 1. Se creó una copia que ahora borramos
			Remove-ItemProperty -Path $REGKEY -Name $VALORBACKUP -Force -ErrorAction SilentlyContinue
		}
	} catch {
		# no había copia, así que dejamos el equipo limpio
		Remove-ItemProperty -Path $REGKEY -Name $VALOR -Force -ErrorAction SilentlyContinue
	}
	
	# borramos el control de ejecución
	Remove-ItemProperty -Path $REGKEY -Name $VALOREXEC -Force -ErrorAction SilentlyContinue
}

}

ejecución

if (test-path $sOCSdir){
Set-Location "$sOCSdir"
controlarUNCWarning $false
Start-Process $sOCS -Arg $sargs_OCS -Wait
controlarUNCWarning $true
}
`

from windowsagent.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.