add GetExecutablePath()

This commit is contained in:
2023-08-26 20:34:42 +02:00
parent 926951e268
commit 77cbcd0dcb
5 changed files with 60 additions and 8 deletions

26
Pilz.IO/Extensions.cs Normal file
View File

@@ -0,0 +1,26 @@
using Pilz.Runtime;
using Pilz.Win32.Native;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
namespace Pilz.IO
{
public static class Extensions
{
static readonly int MAX_PATH = 255;
public static string GetExecutablePath(bool checkRealOS = false)
{
if (RuntimeInformationsEx.IsOSPlatform(OSType.Windows, checkRealOS))
{
var sb = new StringBuilder(MAX_PATH);
Kernel32.GetModuleFileName(IntPtr.Zero, sb, MAX_PATH);
return sb.ToString();
}
else
return Process.GetCurrentProcess().MainModule.FileName;
}
}
}

View File

@@ -86,4 +86,8 @@
<LastGenOutput>Application.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Pilz.Win32\Pilz.Win32.vbproj" />
<ProjectReference Include="..\Pilz\Pilz.vbproj" />
</ItemGroup>
</Project>