C# PSAPI_VERSION. and sevral other question [modified] [Partialy Solved]
-
In MSDN I found this for dll import used with PInvoke: Kernel32.dll on Windows 7 and Windows Server 2008 R2; Psapi.dll if PSAPI_VERSION=1 on Windows 7 and Windows Server 2008 R2; Psapi.dll on Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP/2000 So how do i do programaticly find PSAPI_VERSION? I already Can determent windows version. But i am missing from the List Windwos 2008 and R2. I am doing the folowing way:
public static EnumWinVer GetWindowsVersion()
{OperatingSystem os = Environment.OSVersion; Version vs = os.Version; // This switch is pre-NT version if (os.Platform == PlatformID.Win32Windows) { switch (vs.Minor) { case 0: return EnumWinVer.Win95; case 10: if (vs.Revision.ToString() == "2222A") return EnumWinVer.Win98SE; else return EnumWinVer.Win98; case 90: return EnumWinVer.WinME; } } else if (os.Platform == PlatformID.Win32NT) { switch (vs.Major) { case 3: return EnumWinVer.WinNT3\_51; case 4: return EnumWinVer.WinNT4\_0; case 5: if (vs.Minor == 0) return EnumWinVer.Win2000; else return EnumWinVer.WinXP; case 6: if (vs.Minor == 0) return EnumWinVer.WinVista; else return EnumWinVer.Win7; default: break; } } // This is supposed to be unreachable area. return EnumWinVer.Undefined;
}
I am looking into GetModuleFileNameEx. QueryFullProcessImageName also can do the job. But minimum OS is Vista. So what would happen when Dllimport calls function that doesn't exsist on current OS. So how do i handle that. Thanks in advance for any answers to those question. Have a nice day edit:
[DllImport("kernel32.dll", EntryPoint = "GetModuleFileNameEx")]
static extern int K32GetModuleFileNameEx(IntPtr hProcess, IntPtr hModule, StringBuilder lpFilename, int nSize);[DllImport("psapi.dll", EntryPoint = "GetModuleFileNameEx")]
static extern int PSAPIGetModuleFileNameEx(IntPtr hProcess, IntPtr hModule, StringBuilder lpFilename, int nSize);After this i will Handle System.EntryPointNotFoundExpection. No
-
In MSDN I found this for dll import used with PInvoke: Kernel32.dll on Windows 7 and Windows Server 2008 R2; Psapi.dll if PSAPI_VERSION=1 on Windows 7 and Windows Server 2008 R2; Psapi.dll on Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP/2000 So how do i do programaticly find PSAPI_VERSION? I already Can determent windows version. But i am missing from the List Windwos 2008 and R2. I am doing the folowing way:
public static EnumWinVer GetWindowsVersion()
{OperatingSystem os = Environment.OSVersion; Version vs = os.Version; // This switch is pre-NT version if (os.Platform == PlatformID.Win32Windows) { switch (vs.Minor) { case 0: return EnumWinVer.Win95; case 10: if (vs.Revision.ToString() == "2222A") return EnumWinVer.Win98SE; else return EnumWinVer.Win98; case 90: return EnumWinVer.WinME; } } else if (os.Platform == PlatformID.Win32NT) { switch (vs.Major) { case 3: return EnumWinVer.WinNT3\_51; case 4: return EnumWinVer.WinNT4\_0; case 5: if (vs.Minor == 0) return EnumWinVer.Win2000; else return EnumWinVer.WinXP; case 6: if (vs.Minor == 0) return EnumWinVer.WinVista; else return EnumWinVer.Win7; default: break; } } // This is supposed to be unreachable area. return EnumWinVer.Undefined;
}
I am looking into GetModuleFileNameEx. QueryFullProcessImageName also can do the job. But minimum OS is Vista. So what would happen when Dllimport calls function that doesn't exsist on current OS. So how do i handle that. Thanks in advance for any answers to those question. Have a nice day edit:
[DllImport("kernel32.dll", EntryPoint = "GetModuleFileNameEx")]
static extern int K32GetModuleFileNameEx(IntPtr hProcess, IntPtr hModule, StringBuilder lpFilename, int nSize);[DllImport("psapi.dll", EntryPoint = "GetModuleFileNameEx")]
static extern int PSAPIGetModuleFileNameEx(IntPtr hProcess, IntPtr hModule, StringBuilder lpFilename, int nSize);After this i will Handle System.EntryPointNotFoundExpection. No
-
Why are you using unmanaged code? It seems that Process.MainModule.FileName will get this information without worrying about this sort of thing (which is the entire purpose of using a framework like .Net in the first place).
Because I am gonna use WriteProcessMemory and ReadProcessMemory. Those calls does not support in .NET. I am creating a Memory Scanner. My personal project for hobby. I am creating similar to CheatEngine. The second thing is I want to learn PInvoke, even if it is harder.
-
Because I am gonna use WriteProcessMemory and ReadProcessMemory. Those calls does not support in .NET. I am creating a Memory Scanner. My personal project for hobby. I am creating similar to CheatEngine. The second thing is I want to learn PInvoke, even if it is harder.