如何检测OSX上的安全模式 [英] How to detect safe mode on OSX
本文介绍了如何检测OSX上的安全模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些code,我只希望如果用户没有在安全模式下启动运行。有没有使用的CoreFoundation或C标准API的方式,我可以检测到?
编辑:这里是我的code感谢我接受的答案:
的#include< SYS / sysctl.h>
...诠释SAFEBOOT;
INT mib_name [2] = {CTL_KERN,KERN_SAFEBOOT};
为size_t长度= sizeof的(SAFEBOOT);如果(sysctl的(mib_name,2,&安培;!SAFEBOOT,&安培;长度,NULL,0)){
如果(SAFEBOOT == 1){
//我们是在安全模式
}其他{
// 正常模式。继续…
}
}其他{
//找不到安全的引导信息
}
解决方案
您可以使用的sysctl
是这样的:
的sysctl -n kern.safeboot
它给 1
的时候安全启动
模式和 0 $ C $ ç在正常模式下>。
I have some code that I only want to run if the user didn't boot in safe mode. Is there a way using the CoreFoundation or C standard APIs that I can detect that?
EDIT: here is my code thanks to my accepted answer:
#include <sys/sysctl.h>
...
int safeBoot;
int mib_name[2] = { CTL_KERN, KERN_SAFEBOOT };
size_t length = sizeof(safeBoot);
if (!sysctl(mib_name, 2, &safeBoot, &length, NULL, 0)) {
if (safeBoot == 1) {
// We are in safe mode
} else {
// Normal mode. Continue…
}
} else {
// Couldn't find safe boot information
}
解决方案
You can use sysctl
like this:
sysctl -n kern.safeboot
It gives 1
when in safe boot
mode and 0
when in normal mode.
这篇关于如何检测OSX上的安全模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文