2009年7月17日 星期五

How to improve your hard disk speed without upgrading the higher hardware


說明:
如何不透過硬體升級的方式(包括購買新的主機版、CPU、顯示卡或 SATA 硬碟)來改善你的電腦硬碟速率?這個主旨在許多網路資源受到相當廣泛的討論,詳見參考網址(僅供參考),但如何以現今的軟體技術一次性全盤了解有什麼樣的方法可以增進硬碟的速率(意指讀取和寫入速度)?當然,影響硬碟的速率的因素很多,例如:硬碟轉速、溫度、電腦匯流排速度等,本篇將焦點關注在如何使用軟體的方式(意指安裝軟體在電腦作業系統裡面)來改善電腦硬碟速率。

先決條件:電腦實體記憶體要夠大,如果是 Windows XP 至少要 2GB 以上,Windows Vista 至少要 3GB 以上。

解決方式:
同時考慮使用虛擬硬碟、虛擬硬碟快取和虛擬系統快取。

虛擬硬碟是使用軟體的方式透過緩衝技術讓實體記憶體的部份在作業系統裡面以硬碟的形式(虛擬裝置)呈現,故在作業系統層級中,虛擬硬碟就是一顆一般的硬碟裝置,通常以一個硬碟分割區的方式加入,但其傳輸速度卻比實際一般硬碟快上數十倍,可先行參閱「SuperSpeed RamDisk虛擬硬碟,加快電腦操作速度!」參考網址;對於使用者層級中,虛擬硬碟分割區與一般實體硬碟分割區並無不同,故可將諸如暫存檔案或目錄的位址指向此分割區硬碟,像是虛擬記憶體檔案 pagefile.sys、使用者暫存目錄 %SystemDrive%\\Documents and Settings\%UserName%\Local Settings\Temp、Internet Explorer 暫存目錄 %SystemDrive%\\Documents and Settings\%UserName%\Local Settings\Temporary Internet Files 等,此時當在執行程式或瀏覽網頁時,由於虛擬硬碟的讀寫使用了實體記憶體,就會發現在執行和瀏覽的時候明顯感覺更順暢、更有效率。

虛擬硬碟快取是使用軟體的方式透過快取緩衝技術讓實體記憶體的部份作為硬碟快取的部份形式,可先行參閱「SuperSpeed SuperCache v3.0.2.0設定探索與使用盲點」參考網址;一般硬碟快取通常為 1MB ~ 8MB 不等,理論上硬體快取記憶體愈大時,使用者需要存取的檔案就愈有可能存在快取記憶體裡面,此時就如同虛擬硬碟的讀取方式以原本一般硬碟快上數十倍的時間快速回應使用者,此時當執行程式或玩遊戲需要在短時間內快速存取多個檔案時,就會明顯感覺更順暢、更有效率。

虛擬系統快取是使用軟體的方式透過緩衝技術讓實體記憶體的部份預先載入欲執行的應用程式(.exe)或動態連結函式庫(.dll)等相關檔案,可先行參閱「EBoostr & SuperCache & RAMDISK - EBoostr」參考網址;一般作業系統在開啟執行一個程序時,通常會先將程序所需要的應用程式和相關的函式庫載入到實體記憶體中。理論上使用者開啟執行預先已載入至虛擬系統快取的程序時,此時即可直接透過記憶體的速度執行該程序,而不需要透過讀取一般硬碟,當許多共用的函式庫已預先載入至虛擬系統快取時,在開啟程序時就會感覺到更順暢、更有效率。

參考網址:

虛擬硬碟:
SuperSpeed RamDisk虛擬硬碟,加快電腦操作速度!
[心得]有2G以上RAM的可以參考

虛擬硬碟快取:
SuperCache II 讓你的硬碟效能爆增十倍以上
SuperSpeed SuperCache v3.0.2.0設定探索與使用盲點
SuperSpeed SuperCache II v1.1.16.0
Tommy 碎碎念 : 如何避免安裝 SuperCache II 之後, 無法正常開機的問題

虛擬系統快取:
EBoostr & SuperCache & RAMDISK - EBoostr

2009年3月27日 星期五

VMware Workstation 無法叫出 SoftICE 畫面


問題描述:
在做用 VMware Workstation 時,正常安裝 DriverStudio ,手動啟動 SoftICE 成功後,按下 Ctrl+D 無法叫出 SoftICE 的畫面。

解決方式:
原因可能是螢幕沒有重新整理,因為 SoftICE 是以全螢幕方式調用,所以編輯 .vmx 檔案加入下面兩行:
vmmouse.present = "FALSE"
svga.maxFullscreenRefreshTick = "5"

參考網址:http://bbs.driverdevelop.com/read.php?tid=103413

移除 Dr.eye 8 Office Addin


問題描述:
在安裝 Dr.eye 8 後,通常會自動 Addin 所有已安裝的 Office 系列加入一個工具列方便 Dr.eye 使用,但是若不想要使用這個工具列時,將工具列關閉下次打開還是會顯示,造成打開 Office 系列時載入延遲和版面不美觀。

解決方式:
1. 刪除或變更目錄下 安裝硬碟機:\Program Files\Inventec\Dreye\DreyeMT 的檔案名稱:
DreyeWdAddin.dll - Microsoft Word
DreyeOutlkAddin.dll - Microsoft Outlook
DreyePptAddin.dll - Microsoft PowerPoint

注意事項:
如果還原刪除或變更的檔案名稱好像不會還原原來的工具列。

2009年2月17日 星期二

Unlocker .NET

下載 Unlocker.NET.dll

軟體名稱:Unlocker.NET.dll
版本:v 1.0
軟體作者:cuteofdragon
軟體授權:學術使用免費軟體
軟體類型:Library
軟體開發:Visual Studio .NET 2005 C#
發佈時間:2009/02/18

簡介
Unlocker .NET 是一個純粹採用 .NET C# 撰寫的 dll,目的為處理在 Windows 檔案系統下強制關閉正在被其它程序使用的檔案 Handle,使目前正在處理的程序可以對該檔案進行讀取或刪除等動作。

原理說明
Unlocker .NET 主要使用到 Microsoft 未公開文件的 ntdll.dll 裡面的函式,透過 .NET Interop 技術呼叫原生 Win32 函式,並揭露如何將 C-Style 函式指標轉換成 .NET C# delegate 型式。以下說明相關技術實作。

所使用到的 ntdll.dll 函式指標原型宣告如下:
typedef DWORD (WINAPI *PNtQueryObject)( HANDLE, DWORD, VOID*, DWORD, VOID* );
typedef DWORD (WINAPI *PNtQuerySystemInformation)( DWORD, VOID*, DWORD, ULONG* );
typedef DWORD (WINAPI *PNtQueryInformationFile)(HANDLE, PVOID, PVOID, DWORD, DWORD );

載入函式指標方法:
PNtQueryObject NtQueryObject;
PNtQuerySystemInformation NtQuerySystemInformation;
PNtQueryInformationFile NtQueryInformationFile;

NtQueryObject = (PNtQueryObject) GetProcAddress( GetModuleHandle( _T( "ntdll.dll" ) ), _T("NtQueryObject") );
NtQuerySystemInformation = (PNtQuerySystemInformation) GetProcAddress( GetModuleHandle( _T( "ntdll.dll" ) ), _T("NtQuerySystemInformation") );
NtQueryInformationFile = (PNtQueryInformationFile) GetProcAddress( GetModuleHandle( _T( "ntdll.dll" ) ), _T("NtQueryInformationFile") );

轉換後的 C# delegate 原型宣告如下:
delegate uint NtQueryObjectDelegate(IntPtr hHandle, uint dw1, [MarshalAs(UnmanagedType.LPArray)] byte[] buffer, uint bufferLength, ref uint needLength);
delegate uint NtQuerySystemInformationDelegate(uint dw1, IntPtr systemHandleInformation, uint bufferSize, ref uint needLength);
delegate uint NtQueryInformationFileDelegate(IntPtr hHandle, uint[] iob, IntPtr buffer, uint bufferSize, uint dw2);

delegate 取得 C-Style 函式指標方法:
IntPtr ntQueryObjectPtr = IntPtr.Zero;
IntPtr ntQuerySystemInformationPtr = IntPtr.Zero;
IntPtr ntQueryInformationFilePtr = IntPtr.Zero;

NtQueryObjectDelegate ntQueryObjectDelegate = null;
NtQuerySystemInformationDelegate ntQuerySystemInformationDelegate = null;
NtQueryInformationFileDelegate ntQueryInformationFileDelegate = null;

ntQueryObjectPtr = NativeMethod.GetProcAddress(NativeMethod.GetModuleHandle("ntdll.dll"), "NtQueryObject");
ntQuerySystemInformationPtr = NativeMethod.GetProcAddress(NativeMethod.GetModuleHandle("ntdll.dll"), "NtQuerySystemInformation");
ntQueryInformationFilePtr = NativeMethod.GetProcAddress(NativeMethod.GetModuleHandle("ntdll.dll"), "NtQueryInformationFile");

ntQueryObjectDelegate = (NtQueryObjectDelegate)Marshal.GetDelegateForFunctionPointer(ntQueryObjectPtr, typeof(NtQueryObjectDelegate));
ntQuerySystemInformationDelegate = (NtQuerySystemInformationDelegate)Marshal.GetDelegateForFunctionPointer(ntQuerySystemInformationPtr, typeof(NtQuerySystemInformationDelegate));
ntQueryInformationFileDelegate = (NtQueryInformationFileDelegate)Marshal.GetDelegateForFunctionPointer(ntQueryInformationFilePtr, typeof(NtQueryInformationFileDelegate));

以 .NET C# 方法進行呼叫 delegate
public uint NtQueryObject(IntPtr hHandle, uint dw1, byte[] buffer, uint bufferSize, ref uint needLength)
{
return ntQueryObjectDelegate.Invoke(hHandle, dw1, buffer, bufferSize, ref needLength);
}

public uint NtQuerySystemInformation(uint dw1, IntPtr systemHandleInformation, uint bufferSize, ref uint needLength)
{
return ntQuerySystemInformationDelegate.Invoke(dw1, systemHandleInformation, bufferSize, ref needLength);
}

public uint NtQueryInformationFile(IntPtr hHandle, uint[] iob, IntPtr buffer, uint bufferSize, uint dw2)
{
return ntQueryInformationFileDelegate.Invoke(hHandle, iob, buffer, bufferSize, dw2);
}

Unlocker .NET 如何取得鎖住檔案的程序 Handle
1. 透過 NtQuerySystemInformation 方法取得所有系統中使用的 Handle
2. 透過 NtQueryObject 方法可獲得系統的 Handle 是屬於那一類型,包括 Process、Thread、File 等
3. 透過 NtQueryObject 方法可取得任一 File Handle 被那一個程序使用中

Unlocker .NET 強制關閉 File Handle 原理
1. 首先要 Enable DEBUG privilege
2. 透過 OpenProcess Win32 API 取得鎖住檔案的程序 Handle
3. 透過 CreateRemoteThread Win32 API 呼叫 CloseHandle Win32 API

如何使用 Unlocker.NET.dll
下載並加入 Unlocker.NET.dll 參考

using Unlocker.NET;
class Program
{
static void Main(string[] args)
{
// C:\01.bmp 為被鎖住的檔案名稱
if (Unlocker.CloseFileHandle(@"C:\01.bmp"))
{
Console.WriteLine("成功關閉檔案");
}
else
{
Console.WriteLine("關閉檔案失敗");
}
Console.ReadLine();
}
}

參考網址:http://www.codeguru.com/Cpp/W-P/files/fileio/article.php/c1287/

2009年1月15日 星期四

How to pass the RegisterKey to RegOverridePredefKey function

說明:
RegisterKey 是一個 .NET managed物件,RegOverridePredefKey 是一個原生Win32的函式呼叫,該函數主要用途在允許將一個預定義的註冊表項映射到另一個註冊表項。RegOverridePredefKey 的使用時機請連結參考網址。本文主旨在說明如何不使用原生自訂的Win32的函式庫而使用.NET managed達到如參考網址相同功能。

RegOverridePredefKey 原始宣告:
LONG RegOverridePredefKey(HKEY hKey, HKEY hNewHKey);

RegOverridePredefKey .NET P/Invoke 宣告:
[DllImport("advapi32.dll")]
public static extern long RegOverridePredefKey(IntPtr key, IntPtr newKey);

解決方法:
定義一個轉換方法 ;fieldInfo.GetValue 在 .NET 2.0 無法直接轉型成 IntPtr,其在取得 hkey 屬性時的型別為 Microsoft.Win32.SafeHandles.RegistrySafeHandle,繼承自System.Runtime.InteropServices.SafeHandle。
public static IntPtr GetRegistryHandle(RegistryKey registryKey)
{
Type type = registryKey.GetType();
FieldInfo fieldInfo = type.GetField("hkey", BindingFlags.Instance BindingFlags.NonPublic);
return ((SafeHandle)fieldInfo.GetValue(registryKey)).DangerousGetHandle();
}

附註:
RegOverridePredefKey 的使用時機之一是在OpenFileDialog自定義左邊PlacesBar,在.NET 2.0 sp1之後,OpenFileDialog已支援 CustomPlaces的集合屬性。

參考網址:http://msdn.microsoft.com/zh-cn/library/aa663661.aspx