Quantcast
Viewing all articles
Browse latest Browse all 10

PowerShell e Arquivos INI/PowerShell and INI Files

Mais uma dica. Com o .NET Framework há uma tendência de ir jogando configurações para arquivos XML ao contrário de arquivos INI, como antigamente muito se usou. Mas como sempre é possível ter a necessidade de usar/configurar programas antigos, em [1] são mostrados 3 scripts que juntos ajudam na tarefa de manipular arquivos INI.

O primeiro (Invoke-WindowsApi.ps1) é um workaround para se usar a API Windows no PowerShell. Não há no .NET Framework uma classe que lide com arquivos INI diretamente, então nos dois scripts seguintes (Get-PrivateProfileString.ps1 e Set-PrivateProfileString.ps1) é possível usar passando somente os parâmetros necessários.

Segue o código dos scripts (Thanks Lee!):

=============================================

One more tip. With .NET Framework there is a tendency to throw application settings for XML files as opposed to INI files, as much has been used previously. But as you can always have the need to use/configure older programs, in [1] are shown 3 scripts that together help in the task of manipulating INI.

The first (Invoke-WindowsApi.ps1) is a workaround to use the Windows API into PowerShell. There is no .NET Framework a class that deals with INI files directly, then in the following two scripts (Get-PrivateProfileString.ps1 and Set-PrivateProfileString.ps1) you can use only those passing the required parameters.

Below goes the code of scripts (Thanks Lee!):

 

==================================

 

[1] Managing INI Files with PowerShell


Publicado em Admin, Microsoft, Plays, PowerShell, Windows, Windows API Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 10

Trending Articles