Registry change isn't silent

时间:2018-03-09 19:11:35

标签: powershell

When ran with elevated privileges, the code does what it is supposed to do by turning off the laptop's onboard microphone, but it needs to be totally silent. This will be sent out to over 1600 systems. It will be pushed via logon script to the local systems. So it needs to run as Admin and without any user intervention. How do I keep it running elevated and how to get it to run without the UAC prompt?

-TIA

$audioCaptureRegPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture" 

$MICS = Get-Item $audioCaptureRegPath
$MICS.GetSubKeyNames() | % {`
    if($(Get-ItemProperty -Path $audioCaptureRegPath"\"$_).DeviceState -eq 1 ){`

    $systemNameData=$(Get-ItemProperty -Path $audioCaptureRegPath"\"$_\Properties).$systemNameVal
    if(!($systemNameData -match "plant") -or !($systemNameData -match "HDX"))
    {   
    $tmpFileFullPath = [System.io.Path]::getTempFileName()
    "Windows Registry Editor Version 5.00" | Out-File -FilePath  $tmpFileFullPath -Append
    " " | Out-File -FilePath  $tmpFileFullPath -Append
    "[$($MICS.Name)\$_]" | Out-File -FilePath  $tmpFileFullPath -Append
    "`"DeviceState`"=dword:10000001" | Out-File -FilePath  $tmpFileFullPath -Append
    " " | Out-File -FilePath  $tmpFileFullPath -Append
    regedit.exe /S $tmpFileFullPath

    }
    }
    }

0 个答案:

没有答案