最近在做windows驅動和服務的開發,遇到一個很奇怪的問題。
之前是服務單獨起,用命令列命令啟動,現在想要和驅動捆綁在一起,安裝驅動同時安裝服務,不經過命令列。
代碼相同的情況下
編譯出來的exe服務,用/service命令 CoResumeClassObjects函式執行正常。
而利用驅動直接起我撰寫的服務,CoResumeClassObjects回傳錯誤0x80004015。
有大神能解釋一下這兩種方式有什么不同嗎。
uj5u.com熱心網友回復:
搜“Session0穿透”?用除錯器(OD,WINDBG等)除錯服務程式
To debug the initialization code of a service application, the debugger must be attached when the service is started. This is accomplished by creating a registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\ProgramName
The ProgramName is the image file for the service application you are debugging. Do not specify a path. For example, the ProgramName might look like MyService.exe.
Under this key create a string data value called Debugger. The value of this string should be set to the full path of the debugger that will be used. For example,
c:\Debuggers\windbg.exe
In addition to setting this registry key, the service application must be marked as "interactive". This allows your service to interact with the desktop, and allows the debugger window to appear on your desktop.
This again requires modifying a registry key: you must bitwise-or the type entry for your service with 0x100 (this is the value for SERVICE_INTERACTIVE_PROCESS according to Winnt.h). The exact location and name of this registry entry varies. For example:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyServiceKey
Finally, you need to adjust the service application timeout. Otherwise, the service application will kill the debugger within 20 seconds after starting. Adjusting the timeout involves setting an entry in the following registry key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control
Under this key, create a DWORD data value called ServicesPipeTimeout. Set this entry to the amount of time in milliseconds that you want the service to wait before timing out. For example, 60,000 is one minute, while 86,400,000 is 24 hours.
設定ServicesPipeTimeout后需要重啟系統才生效
Now, when the service is started, the debugger will also start. When the debugger starts, it will stop at the initial process breakpoint, before the service has begun running. This allows you to set breakpoints or otherwise configure your debugging session to let you monitor the startup of your service. Another option is to place calls to the DebugBreak function in your service from the point at which you would like to break into the debugger. (For more information, see DebugBreak in the Platform SDK documentation.)
If your service is running with other services in a Service Host Process, you may need to isolate the service into its own Service Host Process.
uj5u.com熱心網友回復:
我重新描述下問題,我的服務是用atl寫的,exe服務,編譯之后用sc命令或者/service命令可以正常啟動,用inf檔案安裝服務之后啟動CoResumeClassObjects函式回傳錯誤0x80004015,我想知道是否可以用inf檔案單獨安裝服務,以及服務是否可以作為com用inf檔案來安裝,看起來這個錯誤好像是和權限有關系,注冊com物件已經成功,宣告com物件可用可用卻失敗了,如果不調這個函式,服務可以正常啟動,但是我的服務需要作為一個com來被另一個服務使用,所以必須要呼叫。
uj5u.com熱心網友回復:
您好,問題我已經定位到了,并且也做了對比,現在情況是相同的代碼,用命令列注冊一個服務并且把服務作為一個com組件使用可以成功,用inf檔案注冊服務,可以成功宣告為com卻失敗了。
uj5u.com熱心網友回復:
請嚴格區分32/64位環境。uj5u.com熱心網友回復:
現在我編譯的是32位程式,運行環境是64位,請問一下這樣會有什么問題?能否大概講解一下原理,謝謝了。
uj5u.com熱心網友回復:
在64位Windows下:64位exe和dll在目錄c:\windows\system32目錄下;
32位exe和dll在目錄c:\windows\syswow64目錄下;
所以要注意:
在win64位系統下注冊32位ocx或dll需要將32位ocx或dll拷貝到c:\windows\syswow64\目錄下。
且注冊要用c:\windows\syswow64\regsvr32 xxxxxxx.ocx或dll
在win64位系統下設定32位程式使用的資料庫別名要用c:\windows\syswow64\cliconfg.exe
在win64位系統下設定32位程式使用的系統DSN要用c:\windows\syswow64\odbcad32.exe
64 位 Windows 平臺注意點之檔案系統重定向 http://www.cnblogs.com/jiake/p/4981555.html
64 位 Windows 平臺注意點之注冊表重定向 http://www.cnblogs.com/jiake/p/4956218.html
uj5u.com熱心網友回復:
請問您對inf檔案了解嗎?通過inf檔案安裝驅動服務,現在我有一個驅動程式,和一個與該驅動程式無關的服務程式,可以通過一個inf檔案捆綁安裝嗎?
uj5u.com熱心網友回復:
百度搜“inf檔案格式詳解”轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/88166.html
