2012年12月7日 星期五

新增Windows Service相依性

設定Service相依性可以確保某一個Service只能在某個Service啟動後才能夠執行。

開始->執行regedit進入登錄編輯程式
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\選擇所要設定的Service

新增多字串值->DependOnService
資料則填入欲相依的Service名稱(DisplayName)

重新啟動相依的Service,看是否設定的Service會先被終止再啟動。如果沒有生效,可以重開機試試。

2012年12月1日 星期六

C/C++計算檔案大小

常常不記得取得檔案長度該怎麼寫,所以先筆記下來。

C++
ifstream is; is.open ("test.txt", ios::binary)
is.seekg (0, ios::end);
length = is.tellg();
is.seekg (0, ios::beg);

C
FILE *fp = fopen(file, "r");
fseek(fp, 0, SEEK_END);
int size = ftell(fp);
fseek(fp, 0, SEEK_SET);