我必须使用C#或C ++禁用笔记本电脑或上网本的LID。我找到了有关如何获取电源信息的信息。
这可能吗?使用Command LIne可以更改此设置,嗯,我需要将其转换为c#。谢谢。
首先写一个批处理文件:
call powercfg –q >poweroptions.txt
在管理员权限下。第二个将批处理文件作为模板:
call Powercfg –SETACVALUEINDEX [powerschemeGUID] [putsubgroupGUID] [putpowersettingGUID] 000
最后,使用上面的关键字重写模板,以备将来使用。
public static void RunPowerCFGReport()
{
Process.Start(BUConfig.CurrentPath + @"\PowerCFG");
}
public static string GetSubGroupGuid(string AppPath)
{
string[] lines = File.ReadAllLines(AppPath);
string guid = lines.Where(s => s.Contains("Power buttons and lid")).First();
string[] loops = guid.Split(':') ;
string pr = loops[1].Replace(" (Power buttons and lid)", "");
return pr.Trim();
}
public static string GetPowerSchemeGuid(string AppPath)
{
string[] lines = File.ReadAllLines(AppPath);
string guid = lines.Where(s => s.Contains("Power Scheme GUID:")).First();
string[] loops = guid.Split(':');
string pr = loops[1].Replace(" (Balanced)", "");
return pr.Trim();
}
public static string GetPowerSettingGUID(string AppPath)
{
string[] lines = File.ReadAllLines(AppPath);
string guid = lines.Where(s => s.Contains(" (Lid close action)")).First();
string[] loops = guid.Split(':');
string pr = loops[1].Replace(" (Lid close action)", "");
return pr.Trim();
}
public static void SetPowerCFGValues(string _pathFile, string _currentPowerSchemeGuid, string _currentPowerSettingGuid, string _currentGroupGuid)
{
try
{
StreamWriter wr;
string currentCommand = File.ReadAllText(_pathFile);
currentCommand = currentCommand.Replace("[powerschemeGUID]", _currentPowerSchemeGuid);
currentCommand = currentCommand.Replace("[putsubgroupGUID]", _currentGroupGuid);
currentCommand = currentCommand.Replace("[putpowersettingGUID]", _currentPowerSettingGuid);
wr = new StreamWriter(_pathFile);
wr.WriteLine(currentCommand);
wr.Close();
}
catch(Exception ex)
{
}
}
public static void SetLIDAction(string _lidAction)
{
Process.Start(BUConfig.CurrentPath + @"\Test.Bat");
}
public static void ResetLIDFile()
{
string commandtmeplate = "call Powercfg –SETACVALUEINDEX [powerschemeGUID] [putsubgroupGUID] [putpowersettingGUID] 000";
StreamWriter wr = new StreamWriter(BUConfig.CurrentPath + @"\Test.Bat");
wr.WriteLine(commandtmeplate);
}
我尝试直接使用C#,但是Visual Studio返回错误“损坏的文件”。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句