# 不小心刪除服務[null]後,git bash出現錯誤,如何解決? # 錯誤描述:打開 git bash、msys2都會出現錯誤「bash: /dev/null: No such device or address」 # 問題定位: 1.使用搜索引擎搜索「bash: /dev/null: No ...
不小心刪除服務[null]後,git bash出現錯誤,如何解決?
錯誤描述:打開 git bash、msys2都會出現錯誤「bash: /dev/null: No such device or address」
問題定位:
1.使用搜索引擎搜索「bash: /dev/null: No such device or address」,一般答案是[null]服務出現問題,可能是缺少對應的文件「C:\Windows\System32\drivers\null.sys」,要從網上或者安裝鏡像里找到「null.sys」複製到這個位置,再啟動「null」服務。
2.到「C:\Windows\System32\drivers\」查看發現「null.sys」是存在的,而「null」服務確實被我刪除了。至此,問題暫時就確定了,是「null」服務不存在導致的問題。
解決方案:
在有管理員許可權的 CMD 命令行或 Power Shell 6 及以上版本 中運行【>】後面的命令
PS C:\Users\xxx> sc create null binpath=C:\Windows\System32\drivers\null.sys type=kernel start=auto error=normal
[SC] CreateService SUCCESS
PS C:\Users\xxx> sc start null
SERVICE_NAME: null
TYPE : 1 KERNEL_DRIVER
STATE : 4 RUNNING
(STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
PID : 0
FLAGS :
PS C:\Users\xxx>
解決過程:
1.嘗試安裝 null 服務,嘗試的方法如下:
1.1.使用 InstallUtil.exe 實用程式安裝服務
(操作時搞錯了,應該使用開始菜單中的「Developer Command Prompt for VS 2017」,即 Visual Studio 命令行的,我是在Administrator許可權的 CMD 中使用 InstallUtil.exe 工具的,所以安裝失敗了,這個地方粗心大意了。)
installutil <yourproject>.exe
註意:這樣安裝的服務是當前當戶的普通服務。
1.2.Power Shell 安裝服務,命令如下
PS C:\Users\xxx> New-Service -Name "null" -BinaryPathName C:\Windows\System32\drivers\null.sys
Status Name DisplayName
------ ---- -----------
Stopped null null
PS C:\Users\xxx> sc start null
[SC] StartService FAILED with error 129.
PS C:\Users\xxx> Remove-Service -Name "null"
安裝成功,啟動失敗,提示【[SC] StartService FAILED with error 129.】
2.確定啟動失敗的問題
使用搜索引擎搜索【[SC] StartService FAILED with error 129】,stackoverflow 上找到了可以試一試的答案,如下
頁面【Starting created service using sc.exe throws error: "[SC] StartService FAILED with error 129."】,鏈接https://stackoverflow.com/questions/48102667/starting-created-service-using-sc-exe-throws-error-sc-startservice-failed-wi。
內容:
Error code 129 is ERROR_CHILD_NOT_COMPLETE (i.e. the application cannot be run in Win32 mode). You created a user-mode service since the default is 'type= own' (i.e. SERVICE_WIN32_OWN_PROCESS when calling WinAPI CreateService). However, you're trying to run a kernel-mode driver, which should be 'type= kernel' (i.e. SERVICE_KERNEL_DRIVER).
answered Jan 4, 2018 at 21:40
Eryk Sun
即用戶模式的服務無法在內核模式下運行。
3.解決啟動失敗——創建內核模式的[null]服務
在 powershell 6 及以上版本中運行以下命令:
PS C:\Users\xxx> sc create null binpath=C:\Windows\System32\drivers\null.sys type=kernel start=auto error=normal
[SC] CreateService SUCCESS
PS C:\Users\xxx> sc start null
SERVICE_NAME: null
TYPE : 1 KERNEL_DRIVER
STATE : 4 RUNNING
(STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
PID : 0
FLAGS :
PS C:\Users\xxx>
參考文檔:
"Learn/.NET/.NET Framework/開發 Windows 服務應用程式/如何:安裝和卸載 Windows 服務 "
【最終解決問題參考的文檔】"Learn / Windows Server / sc.exe create"
鏈接https://learn.microsoft.com/zh-cn/windows-server/administration/windows-commands/sc-create
在註冊表和服務控制管理器資料庫中為服務創建子項和條目。
語法
sc.exe [
參數
參數 描述
type= {own | share | kernel | filesys | rec | interact type= {own | share}} 指定服務類型。 選項包括:
own - 指定在其自己的進程中運行的服務。 它不會與其他服務共用可執行文件。 這是預設值。
share - 指定作為共用進程運行的服務。 它會與其他服務共用可執行文件。
kernel - 指定驅動程式。
filesys - 指定文件系統驅動程式。
rec - 指定文件系統識別的驅動程式,用於標識電腦上使用的文件系統。
interact - 指定可與桌面交互、接收用戶輸入的服務。 互動式服務必須在 LocalSystem 帳戶下運行。 此類型必須與 type= own 或 type= shared(例如 type = interacttype= own)結合使用。 單獨使用 type= interact 將生成錯誤。
start= {boot | system | auto | demand | disabled | delayed-auto} 指定服務的啟動類型。 選項包括:
boot - 指定由啟動載入程式載入的設備驅動程式。
system - 指定在內核初始化期間啟動的設備驅動程式。
auto - 指定每次重啟電腦時自動啟動的服務,即使沒有人登錄到電腦,該服務也會運行。
demand - 指定必須手動啟動的服務。 如果沒有指定 start=,則此為預設值。
disabled - 指定無法啟動的服務。 要啟動已禁用的服務,請將啟動類型更改為其他某個值。
delayed-auto - 指定在其他自動服務啟動後短時間內自動啟動的服務。
error= {normal | severe | critical | ignore} 指定在電腦啟動時,服務無法啟動時出現的錯誤的嚴重性。 選項包括:
normal - 指定記錄錯誤並顯示消息框,通知用戶服務無法啟動。 啟動將繼續。 這是預設設置。
severe - 指定在可能的情況下記錄錯誤。 電腦嘗試使用上次已知的良好配置重啟。 結果是電腦能夠重啟,但服務可能仍無法運行。
critical - 指定在可能的情況下記錄錯誤。 電腦嘗試使用上次已知的良好配置重啟。 如果上次已知的良好配置失敗,則啟動也會失敗,啟動進程將停止並出現停止錯誤。
ignore - 指定記錄錯誤並繼續啟動。 除了在事件日誌中記錄錯誤之外,不會向用戶發出通知。
binpath=
group=
tag= {yes | no} 指定是否從 CreateService 調用獲取 TagID。 標記僅用於引導-啟動和系統-啟動驅動程式。
depend=
obj= {
displayname=
password=
/? 在命令提示符下顯示幫助。
註解
每個命令行選項(參數)都必須將等號包括為選項名稱的一部分。
選項與其值之間需要空格(例如 type= own。 如果省略空格,操作將失敗。
示例
若要為 NewService 服務創建和註冊新的二進位路徑,請鍵入:
sc.exe \\myserver create NewService binpath= c:\windows\system32\NewServ.exe
sc.exe create NewService binpath= c:\windows\system32\NewServ.exe type= share start= auto depend= +TDI NetBIOS
若要詳細瞭解 sc.exe 命令,請參閱 SC 命令
相關鏈接
(不推薦)"Learn / Windows / Windows 驅動程式 / 安裝 / 安裝 null 驅動程式"
鏈接https://learn.microsoft.com/zh-cn/windows-hardware/drivers/install/installing-a-null-driver。
對如何使用不是很清楚,在「drivers」文件夾嘗試使用安裝失敗了。
原文內容如下:
可以安裝一個“null 驅動程式” (即,如果設備未在電腦上使用且不應啟動或能夠在原始模式下執行,則設備不存在驅動程式) , (在DEVICE_CAPABILITIES結構中看到 RawDeviceOK) 。 若要在 INF 文件中指定 null 驅動程式,請使用如下所示的條目:
[MyModels]
%MyDeviceDescription% = MyNullInstallSection, ExampleHardwareId
[MyNullInstallSection]
; The install section is typically empty, but can contain entries that
; copy files or modify the registry.
[MyNullInstallSection.Services]
AddService = ,2 ; no value for the service name
“ 模型 ”部分中設備的硬體 ID 應使用子系統供應商 ID 和任何其他相關信息專門標識設備。
操作系統將為設備創建設備節點 (devnode) ,但如果設備無法在原始模式下執行,操作系統將無法啟動設備,因為尚未為其分配函數驅動程式。 但請註意,如果設備具有 啟動配置,則會保留這些資源。