小弟寫了一個服務程式,要外部呼叫一個EXE程式(該程式只是向桌面生成一個快捷方式!) ,正常在桌面運行一切正常! 但是由服務來呼叫就不能生效了!求可以解決這個問題的代碼!
查過百度后知道,好像很復雜!! 求一個簡單的例子以便于學習~~~我用的是 delphi 2010! 如果能解決掉! 我200分全送!
uj5u.com熱心網友回復:
求一個完整的DEMO。。。。。uj5u.com熱心網友回復:
網上找到的程序提示~~~The same code works for us on Vista as on XP, etc. The service is running as the Local System.
1. use WTSGetActiveConsoleSessionId to get the ID of the current active Windows session at the console (i.e. the machine keyboard and display, as opposed to WTS sessions).
2. use WTSQueryUserToken to get the token for that session.
3. use DuplicateTokenEx(hToken,MAXIMUM_ALLOWED,NULL,SecurityIdentification,TokenPrimary, &hTokenDup) to duplicate that token.
4. use CreateEnvironmentBlock to create an environment that you will be passing to the process.
5. use CreateProcessAsUser with the duplicated token and the created environment. Actually, we use CreateProcessAsUserW, since the A version had some sort of bug on some older systems.
6. Don't forget to CloseHandle on the various tokens, etc, and to DestroyEnvironmentBlock the environment.
uj5u.com熱心網友回復:
頂上去啊。~~~~uj5u.com熱心網友回復:
向桌面生成一個快捷方式 應該沒問題,只要權限足夠關鍵是哪一個用戶?服務是運行在 一個特別的會話
uj5u.com熱心網友回復:
用當前用戶運行啊,我直接運行和呼叫是正常的,但是用我自己的服務程式直接呼叫就不行了。。uj5u.com熱心網友回復:
如果是WIN7以上的系統,服務需要勾選 允許服務與桌面互動 選項。轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/110214.html
標籤:VCL組件開發及應用
上一篇:C語言:函式指標及函式指標陣列
