1

I am trying to create an app that would setup bitlocker PIN Programmatically.

the app works as well as the PowerShell Command, However, I am unfortunately unable to execute it.

I am getting the following Error when Executing:

"Application Attempted to perform an operation not allowed by the security policy. To grant this application the required permissions, contact your system administrator or use Microsoft .Net Configuration Tool"

private void Submit_Click(object sender, EventArgs e)
        {
             if (PIN.Text.Length < 20)
            {
                MessageBox.Show("Passwords must be at least 20 characters long.");
                return;
            }
             else if (PIN2.Text != PIN.Text)
             {
                 MessageBox.Show("Password & Confirmation are not identical, Please ensure that both Passwords are the same");
                 return;
             }
             else
             {
                 PowerShell ps = PowerShell.Create();
                 ps.AddCommand("$PIN = \"" + PIN.Text + "\" | ConvertTo-SecureString -AsPlainText -Force; Enable-BitLocker -MountPoint \"C:\" -PIN $PIN -TPMAndPinProtector -SkipHardwareTest");
                 ps.Invoke();
                 MessageBox.Show("Your Pre-Boot PIN has now been Setup - Please reboot after 30 Minutes and login with your PIN");
                 Application.Exit();

I have set assembly: SecurityRules(SecurityRuleSet.Level1) but issue remains.

is it a GPO that would need to be amended at all? or would i be able to bypass in the App somehow?

majdinuk
  • 13
  • 3

1 Answers1

0

Have you tried making an actual PowerShell script file and then running the file?

take a look at this

IP.AF
  • 1
  • 1
  • 1
    In general: While the linked page may answer the question, it is [better to include the essential parts _here_](http://meta.stackexchange.com/a/8259/248777) and provide the link only for reference / additional information. Link-only answers can become invalid if the linked page disappears or changes substantially. If you can only offer a link, please consider posting it as a _comment_ rather than as an answer (requires 15 or more reputation points, however). – mklement0 Nov 09 '21 at 18:32
  • Hello there and thank you, runing the ps1 script file works, however i need to hard code it into the app and use the textbox values to set a pin – majdinuk Nov 09 '21 at 18:36
  • Well I mean you can try writing the command as plain text (using IO streams I guess) into a file and then save the file with "name.ps1" as filePath (it will be saved on the executable directory) and then running the file like this : https://stackoverflow.com/questions/1283584/how-do-i-launch-files-in-c-sharp/1283593 – IP.AF Nov 09 '21 at 19:41
  • btw have you tried running your app as administrator? – IP.AF Nov 09 '21 at 19:45
  • Ahh understodd, Unfortunately this is not possible as we are unable to save any form of files into the machines that contain passwords so that is why i am trying to run a dynamic code to do it, and yes, running as Administrator does not work either unfortunately – majdinuk Nov 09 '21 at 20:47