/// <summary>
/// 是否设置程序为开机启动界面
/// </summary>
/// <param name="appPath">程序启动路径</param>
/// <param name="nodelist">true为设置为启动桌面,false为重新设置为操作系统界面</param>
/// <returns>修改成功返回true</returns>
public bool IsSetDesktop(string appPath, bool isSetDesktop)
{
bool ret = false;
RegistryKey reg = null;
try
{
reg = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\System", false);
if (isSetDesktop)
{
if (null == reg)
{
reg = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\System");
}
reg.SetValue("Shell", appPath);
ret = true;
}
else
{
reg.SetValue("Shell", "explorer.exe");//explorer.exe为操作系统显示桌面的exe程序
}
}
catch (Exception e)
{
Log.Exception("Set System Desktop error:" + e.Message);
}
finally
{
if (null != reg)
{
reg.Close();
}
}
return ret;
}
/// 是否设置程序为开机启动界面
/// </summary>
/// <param name="appPath">程序启动路径</param>
/// <param name="nodelist">true为设置为启动桌面,false为重新设置为操作系统界面</param>
/// <returns>修改成功返回true</returns>
public bool IsSetDesktop(string appPath, bool isSetDesktop)
{
bool ret = false;
RegistryKey reg = null;
try
{
reg = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\System", false);
if (isSetDesktop)
{
if (null == reg)
{
reg = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\System");
}
reg.SetValue("Shell", appPath);
ret = true;
}
else
{
reg.SetValue("Shell", "explorer.exe");//explorer.exe为操作系统显示桌面的exe程序
}
}
catch (Exception e)
{
Log.Exception("Set System Desktop error:" + e.Message);
}
finally
{
if (null != reg)
{
reg.Close();
}
}
return ret;
}