using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
namespace WindowsFormsApplication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
var newProcessInfo = new System.Diagnostics.ProcessStartInfo();
newProcessInfo.FileName = @"C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe";
newProcessInfo.Verb = "runas";
System.Diagnostics.Process.Start(newProcessInfo);
newProcessInfo.Arguments = @"sfc /scannow";
}
}
}
Donc, mon code fonctionne jusqu'à un certain point. vous cliquez sur le bouton de l'application du formulaire Windows et il va exécuter windows Powershell en 64bit en tant qu'administrateur mais ne va pas exécuter un script .ps1 "c: \ path \ script.ps1" ou la commande directement écrite comme le "sfc/scannow" au dessus.Exécutez une commande Powershell en tant qu'administrateur - Commandes elle-même ne se chargera pas
Je lisais que les commandes powershell ne fonctionneront pas parfois si le "Set-ExecutionPolicy Unrestricted" n'est pas chargé quelque part au début du code.
Aidez s'il vous plaît! J'ai cherché partout une réponse.
'[...] \ SysWOW64 \ [...] \ powershell.exe' est * 32-bit * powershell –
pourquoi n'exécutez-vous pas la commande sans powershell? –
C'était juste un exemple. J'utiliserai réellement les commandes de Powershell pour une partie de la programmation. Alors, quel dossier est le PowerShell 64 bits si celui-ci n'est pas correct. le SysWOW64 devrait être toute la version 64 bits du système Windows. – DDJ