Windows 10 移动企业应用程序中找不到 Coredll 错误
Coredll not found error in Windows 10 mobile enterprise application
我们正在开发一款适用于 Windows 10 家移动企业的移动应用程序。现在有将系统时间更改为特定值的需求。我们尝试了以下
[DllImport("coredll.dll", SetLastError = true)]
public static extern bool SetSystemTime(ref SYSTEMTIME st);
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEMTIME
{
public short wYear;
public short wMonth;
public short wDayOfWeek;
public short wDay;
public short wHour;
public short wMinute;
public short wSecond;
public short wMilliseconds;
}
SYSTEMTIME st = new SYSTEMTIME();
st.wYear = 2018; // must be short
st.wMonth = 6;
st.wDay = 21;
st.wHour = 0;
st.wMinute = 0;
st.wSecond = 0;
SetSystemTime(ref st);
但它抛出找不到 coredll。我们使用 uwp 和 C# 作为语言。
在 UWP 应用程序中使用 DllImport
调用 Win32 API 是一种 hack。
我找到了 and this blog post。
首先,您只能调用一组选定的API。 SetSystemTime
不在 list 中。设置系统时间是一个受限制的权限,我的猜测是系统没有给应用程序这样的权限。
其次,根据链接的答案,DllImport API
的签名是从 api-ms-win-core-sysinfo-l1-2-0.dll
之类的东西导入的,很奇怪,对吧?
您无法在UWP 应用程序中设置系统时间,并且DateTimeSettings
API only available in IoT device. I found you want to import coredll.dll
static method. Unfortunately, it is not available in UWP . For setting system time within UWP app, there are many roundabout way. For example, you could launch system date setting 页面然后设置时间。
var uriDateSetting = new Uri(@"ms-settings:dateandtime");
// Set the option to show a warning
var promptOptions = new Windows.System.LauncherOptions();
promptOptions.TreatAsUntrusted = true;
// Launch the URI
var success = await Windows.System.Launcher.LaunchUriAsync(uriDateSetting, promptOptions);
我们正在开发一款适用于 Windows 10 家移动企业的移动应用程序。现在有将系统时间更改为特定值的需求。我们尝试了以下
[DllImport("coredll.dll", SetLastError = true)]
public static extern bool SetSystemTime(ref SYSTEMTIME st);
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEMTIME
{
public short wYear;
public short wMonth;
public short wDayOfWeek;
public short wDay;
public short wHour;
public short wMinute;
public short wSecond;
public short wMilliseconds;
}
SYSTEMTIME st = new SYSTEMTIME();
st.wYear = 2018; // must be short
st.wMonth = 6;
st.wDay = 21;
st.wHour = 0;
st.wMinute = 0;
st.wSecond = 0;
SetSystemTime(ref st);
但它抛出找不到 coredll。我们使用 uwp 和 C# 作为语言。
在 UWP 应用程序中使用 DllImport
调用 Win32 API 是一种 hack。
我找到了
首先,您只能调用一组选定的API。 SetSystemTime
不在 list 中。设置系统时间是一个受限制的权限,我的猜测是系统没有给应用程序这样的权限。
其次,根据链接的答案,DllImport API
的签名是从 api-ms-win-core-sysinfo-l1-2-0.dll
之类的东西导入的,很奇怪,对吧?
您无法在UWP 应用程序中设置系统时间,并且DateTimeSettings
API only available in IoT device. I found you want to import coredll.dll
static method. Unfortunately, it is not available in UWP . For setting system time within UWP app, there are many roundabout way. For example, you could launch system date setting 页面然后设置时间。
var uriDateSetting = new Uri(@"ms-settings:dateandtime");
// Set the option to show a warning
var promptOptions = new Windows.System.LauncherOptions();
promptOptions.TreatAsUntrusted = true;
// Launch the URI
var success = await Windows.System.Launcher.LaunchUriAsync(uriDateSetting, promptOptions);