J'ai une application C# Winforms qui appelle un simple script Powershell en utilisant la méthode suivante:application C# Appel Powershell Script Questions
Process process = new Process();
process.StartInfo.FileName = @"powershell.exe";
process.StartInfo.Arguments = String.Format("-noexit \"C:\\Develop\\{1}\"", scriptName);
process.Start();
Le script Powershell lit simplement une clé de Registre et délivre les sous-clés.
$items = get-childitem -literalPath hklm:\software
foreach($item in $items)
{
Write-Host $item
}
Le problème que j'ai est que je reçois un ensemble différent de résultats quand je lance le script de l'application C# je reçois un ensemble de résultats, mais quand je lance la version autonome de script (à partir de la ligne de commande PowerShell) entièrement.
Les résultats de l'exécution du C# application sont:
HKEY_LOCAL_MACHINE\software\Adobe
HKEY_LOCAL_MACHINE\software\Business Objects
HKEY_LOCAL_MACHINE\software\Helios
HKEY_LOCAL_MACHINE\software\InstallShield
HKEY_LOCAL_MACHINE\software\Macrovision
HKEY_LOCAL_MACHINE\software\Microsoft
HKEY_LOCAL_MACHINE\software\MozillaPlugins
HKEY_LOCAL_MACHINE\software\ODBC
HKEY_LOCAL_MACHINE\software\Classes
HKEY_LOCAL_MACHINE\software\Clients
HKEY_LOCAL_MACHINE\software\Policies
HKEY_LOCAL_MACHINE\software\RegisteredApplications
PS C:\Develop\RnD\SiriusPatcher\Sirius.Patcher.UI\bin\Debug>
Lorsqu'il est exécuté à partir de la ligne de commande PowerShell je reçois:
PS M:\> C:\Develop\RegistryAccess.ps1
HKEY_LOCAL_MACHINE\software\ATI Technologies
HKEY_LOCAL_MACHINE\software\Classes
HKEY_LOCAL_MACHINE\software\Clients
HKEY_LOCAL_MACHINE\software\Equiniti
HKEY_LOCAL_MACHINE\software\Microsoft
HKEY_LOCAL_MACHINE\software\ODBC
HKEY_LOCAL_MACHINE\software\Policies
HKEY_LOCAL_MACHINE\software\RegisteredApplications
HKEY_LOCAL_MACHINE\software\Wow6432Node
PS M:\>
La deuxième série de résultats correspondent à ce que j'ai dans le registre , mais le premier ensemble de résultats (qui proviennent de l'application C#) ne le fait pas.
Toute aide ou pointeurs seraient grandement aprécié :)
Ben
Voulez-vous dire \ "C: \\ Développer \\ {0} \" » au lieu de {1} – abatishchev
une solution finale à ce sujet – Kiquenet