Autor Beitrag
Lihlu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 53



BeitragVerfasst: Di 25.05.21 10:50 
Hallo zusammen,

ich habe eine Frage die für euch wahrscheinlich ein leichtes ist, ich aber nicht verstehe wieso:

Problem Beschreibung:
Ich habe eine Anwendung - normale WinForm mit einem Hyperlink. Über diesen Hyperlink sollen Benutzer ihren BitLocker Pin ändern können.

Ich dachte es wäre super simpel, es eben mit einzubauen doch leider funktioniert es einfach nicht. Den Bitlocker Pin ändert man über die exe bdechangepin in system32. Mein Code scheint auch korrekt zu sein und ich kann auch beliebige andere EXEN starten nur diese nicht.

Mein Code dazu sieht wie folgt aus:
ausblenden C#-Quelltext
1:
2:
3:
string Path = Environment.SystemDirectory + "\\bdechangepin.exe";
            //MessageBox.Show(Path);
            Process.Start(Path);


Die Message Box, gibt auch den korrekt Pfad wie gewünscht aus. Kopiert man diesen manuell in CMD geht auch die GUI zum ändern des PINs auf.

Fehlermeldung in Visual Studio: System.ComponentModel.Win32Exception: 'The system cannot find the file specified'

Eventuell liegt es daran, dass die App nicht als Admin gestartet wird. Darum habe ich auch folgendes Probiert mit dem selben Ergebnis von oben:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
 string pathsoft = "C:\\Windows\\System32\\bdechangepin.exe";
            if (File.Exists(pathsoft))
            {
                

                    Process proc = new Process();
                    proc.StartInfo.FileName = pathsoft;
                    proc.StartInfo.UseShellExecute = true;
                    proc.StartInfo.Verb = "runas";
                    proc.Start();

                }
                else {}

            }




Jemand eine Idee ? :(

Vielen Dank im Voraus
Lihlu Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 53



BeitragVerfasst: Di 25.05.21 11:06 
Dieser Artikel hat das Problem gelöst: ourcodeworld.com/art...-c-sharp-in-winforms

ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
using System;
using System.Runtime.InteropServices;

namespace Sandbox
{
    public class Wow64Interop
    {
        const string Kernel32dll = "Kernel32.Dll";

        [DllImport(Kernel32dll, EntryPoint = "Wow64DisableWow64FsRedirection")]
        public static extern bool DisableWow64FSRedirection(ref IntPtr ptr);

        [DllImport(Kernel32dll, EntryPoint = "Wow64RevertWow64FsRedirection")]
        public static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr);
    }
}

// Required namespaces
using System;
using System.Diagnostics;
using System.Windows.Forms;

IntPtr wow64Value = IntPtr.Zero;

try
{
    // 1. Disable initially the Wow64FSRedirection
    Wow64Interop.DisableWow64FSRedirection(ref wow64Value);

    // 2. Prepare the code that starts another executable
    // Run the application from the system32 directory
    // In this case we will run the dfrgui.exe app
    //
    // C:\Windows\system32\dfrgui.exe
    Process processToStart = new Process
    {
        StartInfo =
        {
            FileName = @"dfrgui.exe",
            WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.System)
        }
    };

    // Start the application
    processToStart.Start();
}
catch (Exception exc)
{
    Console.WriteLine("Unabled to disable/enable WOW64 File System Redirection");
    Console.WriteLine(exc.Message);
}
finally
{
    // 3. Let the Wow64FSRedirection with its initially state
    Wow64Interop.Wow64RevertWow64FsRedirection(wow64Value);
}
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19272
Erhaltene Danke: 1740

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 25.05.21 11:52 
Das ist viel zu umständlich. Du kannst einfach %windir%\Sysnative verwenden. Der Ordner c:\windows\sysnative wird dann bei einer 32-Bit Anwendung unter 64-Bit auf das reale c:\windows\system32 umgeleitet, während c:\windows\system32 auf c:\windows\syswow64 umgeleitet wird.