問題概述
- 一個關於8dot3命名更改的問題
- 最近做自動化測試的項目,使用Ranorex進行桌面程序控件選擇的時候,默認根據processname進行查找;但有些情況下,不能正確某些控件所在process的識別processname,因爲系統對這個名字進行了改寫,比如abcdefghi.exe變成了abc~1.exe
- 這還不是最重要的,重要的是, 當在不同的機器上使用Ranorex,或者重裝系統後,或者進行了某些windows更新後,對上述文件命的更改都會改變,比如有時候有改成了abc~2.exe/bdc~3.exe,無規律。
- 另,經驗證,這個名字的改動和顯示在任務管理器是一樣的。
解決方案有兩個:
1、不再使用processname作爲識別的標誌
可以使用pos/size的方法, 定義在桌面程序的某個區域內尋找合適的控件,如果桌面上沒有其他的控件和目標控件大小類似(實際上一般不會有這個問題,不會有兩個控件同時顯示並且完全重合),上述問題得到解決
2、禁掉8dot3功能
在dos系統中,文件命名方式爲8.3格式,即文件名不超過8個字符,擴展名不超過3個字符。形如:xxx.exe 。而現在Windows系統文件名長度最長可達255個字符了。
8dot3短文件格式是在dos系統繼承下來的, 在win7中仍然默認開啓。所以如果文件名過長,那麼系統會對其進行自動重命名。可以禁用這個功能,這樣每次識別的名稱都是原始名稱,就可以用上述processname的方法啦。
禁用8dot3 format步驟
Disable 8.3 filename support for the future files (modify registry)
- Click the Start orb and type REGEDIT in the Start Search area.
- Open the Registry Editor.
- Click the plus sign next to HKEY_LOCAL_MACHINE
then SYSTEM
then CurrentControlSet
then Control
then click FileSystem - On the right side, double-click on NtfsDisable8dot3NameCreation and give it a value of 1. Click OK.
- Close the Registry Editor.
Disable 8.3 filename support for current files(run in the Command Prompt)
- Press SHIFT+F10 to open a Command Prompt.
- Type:
fsutil.exe behavior set disable8dot3 1
and press ENTER.
restart
enjoy ^_^