A
AM_WJ
Unregistered / Unconfirmed
GUEST, unregistred user!
这是我在VC知识库里找到的一段C++关机程序,我用DP改写<br>TOKEN_PRIVILEGES tkp;<br>HANDLE hToken;<br> if (!OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) <br> {<br> MessageBox("OpenProcessToken failed!");<br> }<br> LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,&tkp.Privileges[0].Luid); //获得本地机唯一的标识<br> tkp.PrivilegeCount = 1; <br> tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; <br> AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,(PTOKEN_PRIVILEGES) NULL, 0); //调整获得的权限<br> if (GetLastError() != ERROR_SUCCESS) <br> {<br> MessageBox("AdjustTokenPrivileges enable failed!");<br> }<br> fResult =InitiateSystemShutdown( <br> NULL, // 要关的计算机用户名,可在局域网网中关掉对方的机器,NULL表示关本机<br> "由于系统不稳定,WINDOWS将在上面的时间内关机,请做好保存工作!", // 显示的消息<br> 10, // 关机所需的时间<br> TRUE, <br> TRUE); //设为TRUE为重起,设为FALSE为关机<br> if(!fResult) <br> { <br> MessageBox("InitiateSystemShutdown failed."); <br> } <br> tkp.Privileges[0].Attributes = 0; <br> AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,(PTOKEN_PRIVILEGES) NULL, 0); <br> if (GetLastError() != ERROR_SUCCESS) <br> {<br> MessageBox("AdjustTokenPrivileges disable failed."); <br> }<br> ExitWindowsEx(EWX_SHUTDOWN,0); //开始关机<br><br>改成dp版时<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> tkp: _TOKEN_PRIVILEGES;<br> hToken: Cardinal;<br>begin<br> if not OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,hToken) then //创建一个进程<br> MessageDlg('OpenProcessToken failed!',mtError,[mbOK],0);<br> LookupPrivilegeValue(nil,'SE_SECURITY_NAME',tkp.Privileges[0].Luid); //获得本地机唯一的标识<br> tkp.PrivilegeCount:= 1;<br> tkp.Privileges[0].Attributes:= SE_PRIVILEGE_ENABLED;<br> AdjustTokenPrivileges(hToken, false, tkp, 0, (_TOKEN_PRIVILEGES)nil, 0);<br>end;<br>AdjustTokenPrivileges这个函数的PreviousState这个参数我(_TOKEN_PRIVILEGES)nil写不行应该怎么写呢?看API帮助说这里是<br>为null的,我直接写nil也不行.<br>那位大哥能把这段代码完整的翻成DP的吗?<br>