使用bat文件命令更改Java控制面板设置

时间:2015-08-12 11:48:50

标签: java batch-file

我需要自动编辑以下内容:

Java Control Panel --> Advanced Tab --> Advanced Security Settings

使用批处理文件,它是如何可行的?是否有Windows注册表编辑命令可用? 在分析中,我发现要执行此更改的deployment.properties文件是否要完成?

1 个答案:

答案 0 :(得分:1)

这是我用来打开Java CPL小程序的脚本,导航到“安全”选项卡并将网站添加到例外,然后导航到“高级”选项卡并切换&#34的复选框;使用SSL 2.0兼容的ClientHello格式"。它通过在Jscript中通过WshShell.SendKeys()广泛使用键盘导航来实现这一点。它非常适合我的应用程序,因此您需要修改它以适合您自己的恶意计划。 See this page表示字符列表及其SendKeys等价物。

@if (@CodeSection == @Batch) @then

:: Save this as a .bat file.
:: begin batch portion

@echo off
setlocal enabledelayedexpansion

:: find newest javacpl.cpl
<NUL set /P "=Searching for Java Control Panel applet... "
for /f "delims=" %%I in ('dir /s /b "%PROGRAMFILES(x86)%\java\*javacpl.cpl"') do (
    set "javacpl_test=%%I"
    for /f "tokens=2 delims=.=" %%a in ('wmic datafile where "name='!javacpl_test:\=\\!'" get CreationDate /format:list ^| find "="') do (
        set "created_test=%%a"
        set "created_test=!created_test:~0,-4!"
    )
    if not defined created (
        set "javacpl=!javacpl_test!"
        set "created=!created_test!"
    ) else if !created_test! gtr !created! (
        set "javacpl=!javacpl_test!"
        set "created=!created_test!"
    )
)

if not defined javacpl (
    echo Not found.  Is Java installed?
    goto :EOF
) else (
    setlocal disabledelayedexpansion
    echo Found.  Relax and enjoy the show!
    endlocal
)

:: relaunch self with JScript engine
cscript /nologo /e:JScript "%~f0" "%javacpl%" "%cmdcmdline%"

:: end batch portion
goto :EOF

@end // end batch / begin JScript chimera

// launch Java control panel applet
var oShell = WSH.CreateObject('wscript.shell'),
    cmd = oShell.Exec('cmd /c control "' + WSH.Arguments(0) + '"');

// function introduces a delay to slow down typing to 20 chars / sec
function kbd(arr) {
    for (var i=0; i<arr.length; i++) {
        oShell.SendKeys(arr[i]);
        WSH.Sleep(50);
    }
}

// wait for window to gain focus
while (!oShell.AppActivate('Java Control Panel')) { WSH.Sleep(500) }

// navigate to the fourth tab and activate "Edit Sites" button
kbd(['{RIGHT}','{RIGHT}','{RIGHT}','%s']);

// wait for exception list window to focus
while (!oShell.AppActivate('Exception Site List')) { WSH.Sleep(500) }

// activate "Add" button (has default focus -- exhibited weird behavior when trying to send Alt+a)
oShell.SendKeys(' ');

WSH.Sleep(500);

kbd('https://host.domain.tld/~'.split(''));

// Store added entry (Ctrl+Enter simulates OK button)
oShell.SendKeys('^~');

// wait for Java Control Panel to regain focus
while (!oShell.AppActivate('Java Control Panel')) { WSH.Sleep(500) }

// move focus within cpl window back to tab row
kbd(['{TAB}','{TAB}','{TAB}','{TAB}','{TAB}']);

// navigate to next tab, focus listbox, enter first few letters of "Advanced Security Settings"
// to scroll down, select the fourth check box and activate it, then Ctrl+Enter to save.
kbd(['{RIGHT}','{TAB}','a','d','v','{DOWN}','{DOWN}','{DOWN}','{DOWN}',' ','^~']);

// if double-clicked, delete self
if (!/^cmd \/c/i.test(WSH.Arguments(1))) {
    WSH.Echo("Done.  I guess everything went OK.  Who knows?  *shrug*");
} else {
    var FSO = new ActiveXObject('scripting.filesystemobject');
    // FSO.DeleteFile(WSH.ScriptFullName);
    WSH.Echo("Pretending to delete self... done.  That was fun.");
}