[DllImport("user32")]
        public static extern bool LockWorkStation();    //系统锁定    
        /// <summary>
        /// 系统锁定 — 注销到Windows登陆
         /// </summary>
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            LockWorkStation();   
        }

 

1.自己写gina.dll
2.虚拟一个windows的运行桌面

创建一个桌面,屏蔽掉ALT+CTRL+DEL键,
显示一个对话框。
开锁后切换回默认桌面。

参考API

CreateDesktop
SwicthDesktop

 

封锁功能键

// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main() 
{
if(!NativeWIN32.isExists("LockWindowsASDC"))
{
NativeWIN32.hideSysKey(true);

Application.Run(new Form1());

NativeWIN32.hideSysKey(false);
}

}

private void Form1_Load(object sender, System.EventArgs e)
{
}

private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{

if(e.KeyValue==13)
{
if(Book_MCS.GlobalInfo.LockPassword.ToUpper()==this.strPwd || this.strPwd=="ASDCLOCK")
{
this.strPwd="";
this.b_CanExit=true;
this.Close();
}
else
{
this.strPwd="";
}

}
else
{
char c_key;
c_key=(char)e.KeyValue;
this.strPwd=this.strPwd+c_key;
}

}

private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if(!this.b_CanExit)
{
e.Cancel=true;
}
}

private void timer1_Tick(object sender, System.EventArgs e)
{
this.timer1.Enabled=false;
try
{

bool b=NativeWIN32.CloseTheWindows("Windows 任务管理器");
}
catch(Exception err)
{

}
finally
{
this.timer1.Interval=300;
this.timer1.Enabled=true;
}

}

private void menuItem15_Click(object sender, System.EventArgs e)
{
FormPWD formPwd=new FormPWD();
formPwd.ShowDialog(this);
}

可以遇到taskmgr.exe就把它结束掉
有个StopProcess9x函数
设立一个定时器
每隔100毫秒就StopProcess9x("taskmgr.exe");  ^_^

BOOL CExample2Dlg::StopProcess9x   (char*   WillStopName) 
  {     
          HANDLE                   hProcessSnap   =   NULL;     
          BOOL                       bRet             =   FALSE;     
          PROCESSENTRY32   pe32             =   {0};     
          hProcessSnap   =   CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,   0);     
    
          if   (hProcessSnap   ==   INVALID_HANDLE_VALUE)     
                  return   (FALSE);     
      
          pe32.dwSize   =   sizeof(PROCESSENTRY32);     
     if   (Process32First(hProcessSnap,   &pe32))     
          {     
                  BOOL  bGotModule   =   FALSE;     
                  MODULEENTRY32   me32  =   {0};     
                  do     
                  {     
                          HANDLE   hProcess;     
                          hProcess   =   OpenProcess   (PROCESS_ALL_ACCESS,     
                                                                          FALSE,   pe32.th32ProcessID);     
                          strupr(pe32.szExeFile);   
                          char   ProcessName[100];   
                          strcpy(ProcessName,WillStopName);   
                          strupr(ProcessName);   
                          if(strcmp(pe32.szExeFile,ProcessName)==0)   
                          {   
                                  DWORD   result=TerminateProcess(   hProcess,   0   );   
                                  if(result!=0)   
                                        return   TRUE;   
                          }   
                          CloseHandle   (hProcess);     
                  }     
                  while   (Process32Next(hProcessSnap,   &pe32));     
          }     
          else     
                  bRet   =   FALSE;             
          CloseHandle   (hProcessSnap);     
          return   (bRet);     
  } 

 

using System.Diagnostics;//首先导入这个命名空间
Process p = new Process();//实例化一个独立进程
p.StartInfo.FileName = "cmd.exe";//进程打开的文件为Cmd
p.StartInfo.UseShellExecute = false;//是否启动系统外壳选否
p.StartInfo.RedirectStandardInput = true;//这是是否从StandardInput输入
p.StartInfo.CreateNoWindow = true;//这里是启动程序是否显示窗体
p.Start();//启动
p.StandardInput.WriteLine("shutdown -s -t 10");//运行关机命令shutdown (-s)是关机 (-t)是延迟的时间 这里用秒计算 10就是10秒后关机
p.StandardInput.WriteLine("exit");//退出cmd 此非原创,来源于网络,希望您满意,谢谢!