2017-07-08 67 views
0

我試圖做一個腳本來改變我在註冊表中的鼠標設置。當我運行腳本時,我發現已做出更改,但除非我註銷並重新登錄,否則這些更改不會生效,這是不可行的。如何在批處理腳本中更改鼠標設置?

:: MouseSensitivity      10 
:: MouseSpeed (Set Pointer Precision) 0 
:: MouseThreshold1      0 
:: MouseThreshold2      0 

@ECHO OFF 

REG ADD "HKEY_CURRENT_USER\Control Panel\Mouse" /v MouseSensitivity /t REG_SZ /d 10 /f 
REG ADD "HKEY_CURRENT_USER\Control Panel\Mouse" /v MouseSpeed /t REG_SZ /d 0 /f 
REG ADD "HKEY_CURRENT_USER\Control Panel\Mouse" /v MouseThreshold1 /t REG_SZ /d 0 /f 
REG ADD "HKEY_CURRENT_USER\Control Panel\Mouse" /v MouseThreshold2 /t REG_SZ /d 0 /f 

ECHO Execution logged on: %DATE% at %TIME% >> test.txt 

:: /* Tried this, doesn't work. 
:: RUNDLL32.EXE USER32.DLL, UpdatePerUserSystemParameters 
:: */ 

@EXIT /B 0 
+3

註冊表不是API。您需要從可以調用Win32 API的語言中調用SystemParametersInfo。 –

回答

0

Raymond Chen,你說得對。 下面是我用C++提出的解決方案。

#include <windows.h> 

int main() 
{ 
    int mouse_info[3]; 

    mouse_info[0] = 0; // MouseThreshold1 
    mouse_info[1] = 0; // MouseThreshold2 
    mouse_info[2] = 0; // Set Pointer Precision 

    // Set and update user settings. In effect immediately. 
    SystemParametersInfo(SPI_SETMOUSE, 
         0, 
         mouse_info, 
         SPIF_UPDATEINIFILE); 

    return 0; 
}