VMware虛擬機服務的vmware-hostd自動啟動和停止


安裝了虛擬機 任務管理器會出現vmware-hostd.exe  占用了80端口,導致xampp打不開,所以就想關閉vmware,解決方案如下:
開始——運行——services.msc,找到VM打頭的服務,改為手動,並停止服務。
以下內容轉自:
http://bbs.cfanclub.net/thread-497122-1-1.html
其中 要用VM虛擬機的時候  VMware Authorization Service是必須開啟的 VMware DHCP Service、VMware NAT Service是跟網絡有關的。不開啟虛擬機用不了網絡。VMware Agent Service和VMware USB Arbitration Service設置為手動就可以,用虛擬機的時候一般也不用啟動。還有2個網絡連接 VMware Network Adapter VMnet1、VMware Network Adapter VMnet8
這兩個要是不用虛擬機的話也用不到。一會就和那些服務一起開啟和禁止。
下面說語句
啟動停止服務的語句 net start/stop \"服務名稱\" (ps:填寫的是服務名稱 不是顯示名稱這個別搞錯了)
開啟禁止網絡連接的語句 netsh interface set interface \"網絡連接名\" enable/disable
(\"\"這個引號最好帶上,為了避免不必要的麻煩。)
也就是說 簡單的 代碼就是
啟動的
  1. @echo off
  2. echo 正在啟用服務...
  3. net start \"VMAuthdService\"
  4. net start \"VMnetDHCP\"
  5. net start \"VMware NAT Service\"
  6. echo 正在啟用網絡連接...
  7. netsh interface set interface \"VMware Network Adapter VMnet1\" enable
  8. netsh interface set interface \"VMware Network Adapter VMnet8\" enable
  9. echo 網絡連接VMware Network Adapter VMnet1、VMware Network Adapter VMnet8啟動成功...
  10. pause
復制代碼
禁止的
  1. @echo off
  2. echo 正在禁用服務服務...
  3. net stop \"VMAuthdService\"
  4. net stop \"VMnetDHCP\"
  5. net stop \"VMware NAT Service\"
  6. echo 正在禁用網絡連接...
  7. netsh interface set interface \"VMware Network Adapter VMnet1\" disable
  8. netsh interface set interface \"VMware Network Adapter VMnet8\" disable
  9. echo 網絡連接VMware Network Adapter VMnet1、VMware Network Adapter VMnet8禁用成功...
  10. pause
復制代碼
echo 后面加的是你想說的話。。。這些就隨便了。
總之代碼簡單來說就是這樣了。
這樣兩個簡單的批處理文件,就解決這些問題了。
(PS:如果Win7系統下運行請右鍵選擇 以管理員身份運行 否則將會出現錯誤5!)
如果還麻煩可以把這兩個合成一個。
下面是我現在用的
  1. @echo off
  2. for /f \"skip=3 tokens=4\" %%i in ('sc query \"VMAuthdService\"') do set \"zt=%%i\" &goto :next
  3. :next
  4. if /i \"%zt%\"==\"RUNNING\" (
  5. echo 服務VMware Authorization Service正在運行
  6. ) else (
  7. echo 服務VMware Authorization Service已停止
  8. )
  9. for /f \"skip=3 tokens=4\" %%i in ('sc query \"VMnetDHCP\"') do set \"zt=%%i\" &goto :next
  10. :next
  11. if /i \"%zt%\"==\"RUNNING\" (
  12. echo 服務VMware DHCP Service正在運行
  13. ) else (
  14. echo 服務VMware DHCP Service已停止
  15. )
  16. for /f \"skip=3 tokens=4\" %%i in ('sc query \"VMware NAT Service\"') do set \"zt=%%i\" &goto :next
  17. :next
  18. if /i \"%zt%\"==\"RUNNING\" (
  19. echo 服務VMware NAT Service正在運行
  20. ) else (
  21. echo 服務VMware NAT Service已停止
  22. )
  23. pause
  24. echo 1:啟用VM虛擬機服務(VMware Authorization Service、VMware DHCP Service、VMware NAT Service)及網絡連接(VMware Network
  25. Adapter VMnet1、VMware Network Adapter VMnet8)
  26. echo 2:禁用VM虛擬機服務(VMware Authorization Service、VMware DHCP Service、VMware NAT Service)及網絡連接(VMware Network
  27. Adapter VMnet1、VMware Network Adapter VMnet8)
  28. choice /c:12 /m \"根據選項請選擇...\"
  29. if errorlevel 2 goto two
  30. if errorlevel 1 goto one
  31. :one
  32. echo 正在啟用服務...
  33. net start \"VMAuthdService\"
  34. net start \"VMnetDHCP\"
  35. net start \"VMware NAT Service\"
  36. echo 正在啟用網絡連接...
  37. netsh interface set interface \"VMware Network Adapter VMnet1\" enable
  38. netsh interface set interface \"VMware Network Adapter VMnet8\" enable
  39. echo 網絡連接VMware Network Adapter VMnet1、VMware Network Adapter VMnet8啟動成功...
  40. echo 按任意鍵退出...
  41. pause>nul
  42. exit
  43. :two
  44. echo 正在禁用服務服務...
  45. net stop \"VMAuthdService\"
  46. net stop \"VMnetDHCP\"
  47. net stop \"VMware NAT Service\"
  48. echo 正在禁用網絡連接...
  49. netsh interface set interface \"VMware Network Adapter VMnet1\" disable
  50. netsh interface set interface \"VMware Network Adapter VMnet8\" disable
  51. echo 網絡連接VMware Network Adapter VMnet1、VMware Network Adapter VMnet8禁用成功...
  52. echo 按任意鍵退出...
  53. pause>nul
  54. exit
復制代碼
加了個 檢測服務是否開啟 都是一些簡單的語句。
如果不愛自己寫的 可以把 代碼直接復制到記事本里 把 文件名改為 VMware虛擬機服務、網絡連接.bat 就OK。
=======================================================================================
 
現在用VMware虛擬機的可能多數還是使用的NAT網絡方式,這個方式需要啟動兩個服務:vmnat和vmdhcp。如果讓它們作為自動服務,開機就啟動個人比較不喜歡。所以想辦法讓服務在用虛擬機的時候啟動,退出的時候停止。
Windows的net start/stop命令可以啟動停止服務。所以就寫了個bat腳本來做這個事情:
vmstart.bat:
------------------
net start "VMware DHCP Service"
net start "VMware NAT Service"

vmplayer

net stop "VMware DHCP Service"
net stop "VMware NAT Service"
-------------------
**記得把那兩個服務(vmnat和vmdhcp)改成手動,可以把vmauth這個禁用掉。**
**我用的VMplayer,你用VMware Station就改成vmware。 **
這樣子,執行這個bat就啟動服務,運行虛擬機,然后會等虛擬機退出,之后停止服務。代價是背后有個cmd.exe在等待虛擬機退出,看不見,不影響什么。
但是在執行bat時會出現一下cmd的黑框框,想不讓出現,所以我寫了個幾行的Win32程序調用ShellExecute()執行bat,並傳SW_HIDE參數,就可以不顯示黑框了。后來在網上發現別人用VBScript實現更簡單:
runbat.vbs:
----------------------
dim wsh
if WScript.Arguments.Count <> 1 then
MsgBox "沒有指定要執行的bat!"
WScript.Quit(-1)
end if
set wsh=WScript.CreateObject("WScript.Shell")
wsh.Run WScript.Arguments(0), SW_HIDE, FALSE
----------------------
好了,把這兩個文件放到VMPlayer/VMware Station的目錄下面,創建個快捷方式,寫上:
runbat.vbs vmstart.bat
這就可以了,不過還可以把快捷方式的圖標改成虛擬機的圖標。
以后啟動虛擬機打開這個快捷方式就行了。雖然麻煩了一下,但一勞永逸的事情何樂而不為 :)
 
P.S. 也可以把這個啟動服務的方法用到其他軟件上。
P.S. 使用VMPlayer是免費的,不需要注冊碼,但VMPlayer不能創建和修改虛擬機。
P.S. 新的VMPlayer 2和VMware Station v6體積大了不少,發現主要是里面的linux.iso大了很多,是linux guest的vmware-tools。之前用vmware v5的時候發現debian和ubuntu好像裝vmware-tools編譯會出錯,提示版本不匹配什么的。用這個版本的好了。而且用vmware v5.x時我的XP在登錄時經常要等好久,用這些新版本好像沒問題了。
P.S. vmware-tools:安裝與uname -r版本一致的linux-headers,我是先dist-upgrade了一下才有匹配的。似乎還要make include/linux/version.h生成這個文件。
P.S. 把vmware station v6的vmware.exe拷到VMPlayer的目錄里去,就可以運行vmware.exe建立和修改虛擬機了,但不能運行,反正我們平時用VMPlayer運行。
P.S. again... 我經常開了虛擬機然后用putty登錄虛擬機,因為我沒裝X window。(設置UTF-8編碼,putty還可以控制台顯示和輸入漢字。推薦用fixed sys字體。)我因此想把虛擬機隱藏到托盤,據說VMware Station v6有這個功能,但VMPlayer沒有 :( 。可以考慮下PowerMenu這個小軟件。但又多了一個累贅...


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM