none
Get system32 Path RRS feed

  • Question

  • Hi,

    I have a 64bit OS but my application is 32Bits which will be to run on a 32Bit OS tablet. I need to load the OSK (on screen keyboard) and being a 32bit OS everything works fine since the visual studio variables (SpecialFolder.System, Environment.SystemDirectory, or direct path) all indicate the same path and the correct file, but if we pass a 32bit app for OS 64Bit things go wrong.
    Example:

    string cmd1 = $"{Environment.GetFolderPath(Environment.SpecialFolder.System)}{System.IO.Path.DirectorySeparatorChar}cmd.exe";
    string cmd2 = $"{Environment.SystemDirectory}{System.IO.Path.DirectorySeparatorChar}cmd.exe";
    string cmd3 = $"c:\\windows\\system32\\cmd.exe";
    
    System.IO.FileInfo fl1 = new System.IO.FileInfo(cmd1);
    System.IO.FileInfo fl2 = new System.IO.FileInfo(cmd2);
    System.IO.FileInfo fl3 = new System.IO.FileInfo(cmd3);
    
    string txt = $"Cmd folders{Environment.NewLine}" + 
                 $"SpecialFolder.System: {fl1.Directory} | {fl1.Length/1024} | {fl1.Name}{Environment.NewLine}" +
                 $"Environment.SystemDirectory: {fl2.Directory} | {fl2.Length/1024} | {fl2.Name}{Environment.NewLine}" +
                 $"c\\windows\\system32 (direct path): {fl3.Directory} | {fl3.Length/1024} | {fl3.Name}";
    
                        

    Output

    SpecialFolder.System: C:\WINDOWS\system32 | 231 KB | cmd.exe
    Environment.SystemDirectory: C:\WINDOWS\system32 | 231 KB | cmd.exe
    c\windows\system32 (direct path): c:\windows\system32 | 231 KB | cmd.exe

    After a google search I saw that all the results appear the same because all refer to an existing system32 folder inside the syswow64 folder that has the cmd.exe of 231 KB.

    The problem is that the cmd.exe of the system32 folder of a 64bit OS has 272KB and when loading the OSK by the example variables it does not appear.

    If i navigate throw explorer to \windows\system32 (in my 64Bits OS) i found the correct cmd.exe with 272 KB.

    cmd_system32

    Any solution?


    TcoUpLoad (Vb6 and VbNet | starting learning C# and LINQ)


    • Edited by Tcomsn Thursday, May 16, 2019 4:10 PM add imagem
    Thursday, May 16, 2019 4:06 PM

Answers

  • I have a 64bit OS but my application is 32Bits which will be to run on a 32Bit OS tablet. I need to load the OSK (on screen keyboard)

    To launch OSK  (tested from a 32-bit app on Windows 10 64) :

    bool bWow64 = false;
    IsWow64Process(Process.GetCurrentProcess().Handle, out bWow64);
    if (bWow64)
    {
        IntPtr OldValue = IntPtr.Zero;
        bool bRet = Wow64DisableWow64FsRedirection(out OldValue);
    }
    System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo("OSK.EXE");
    info.Verb = "open";
    System.Diagnostics.Process.Start(info);

    Declarations :

    [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
    private static extern bool IsWow64Process(IntPtr hProcess, out bool Wow64Process);
    
    [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
    private static extern bool Wow64DisableWow64FsRedirection(out IntPtr OldValue);

    • Marked as answer by Tcomsn Thursday, May 16, 2019 4:47 PM
    Thursday, May 16, 2019 4:18 PM

All replies

  • I have a 64bit OS but my application is 32Bits which will be to run on a 32Bit OS tablet. I need to load the OSK (on screen keyboard)

    To launch OSK  (tested from a 32-bit app on Windows 10 64) :

    bool bWow64 = false;
    IsWow64Process(Process.GetCurrentProcess().Handle, out bWow64);
    if (bWow64)
    {
        IntPtr OldValue = IntPtr.Zero;
        bool bRet = Wow64DisableWow64FsRedirection(out OldValue);
    }
    System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo("OSK.EXE");
    info.Verb = "open";
    System.Diagnostics.Process.Start(info);

    Declarations :

    [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
    private static extern bool IsWow64Process(IntPtr hProcess, out bool Wow64Process);
    
    [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
    private static extern bool Wow64DisableWow64FsRedirection(out IntPtr OldValue);

    • Marked as answer by Tcomsn Thursday, May 16, 2019 4:47 PM
    Thursday, May 16, 2019 4:18 PM
  • Thanks.

    Those lines save a lot of work. I was copping cmd in installation setup and then app verified if the file was the correct file.



    • Edited by Tcomsn Thursday, May 16, 2019 4:49 PM
    Thursday, May 16, 2019 4:47 PM