Skip to main content
Known Participant
May 22, 2023
Answered

How do I hide this blinking window

  • May 22, 2023
  • 2 replies
  • 634 views

system('start /min reg add "HKEY_CURRENT_USER\\Software\\abcdefg" /f')

 

When this code runs, the window flashes

This topic has been closed for replies.
Correct answer r-bin
var ret  = run_cmd('reg add "HKEY_CURRENT_USER\\Software\\abcdefg" /f', false, false);

alert(ret);

/////////////////////////////////////////////////
function run_cmd(cmd, visible, wait)
    {
    try {
        var tmp_name = "tmp.js";

        var file = new File(Folder.temp.fsName + "\\" + tmp_name);
        file.open("w");
        file.encoding = "UNICODE-1-1-UTF-8";

        if (file.error) throw(file.error);

        file.writeln("WScript.CreateObject(\"WScript.Shell\").Run(" + cmd.toSource() + "," + (visible?"1":"0") + "," + (wait?"true":"false") + ");");

        file.writeln("with(new ActiveXObject(\"Scripting.FileSystemObject\")) GetFile(GetSpecialFolder(2).Path+\"\\\\\"+\"" + tmp_name + "\").Delete();");  

        if (file.error) throw(file.error);

        file.close();
        file.execute();

        var ok = false;
    
        try {
            while (1)
                {
                if (!file.exists) { ok = true; break; }

                set_performance("stepByStep");
                }   
            }
        catch(e) { }

        set_performance("accelerated");

        return ok;
        }
    catch(e) { alert(e); }
    }

/////////////////////////////////////////////////
function set_performance(mode)
    {
    try {
        var d = new ActionDescriptor();
        var r = new ActionReference();
        r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("playbackOptions"));
        r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        d.putReference(stringIDToTypeID("null"), r);
        var d1 = new ActionDescriptor();
        d1.putEnumerated(stringIDToTypeID("performance"), stringIDToTypeID("performance"), stringIDToTypeID(mode));
        d.putObject(stringIDToTypeID("to"), stringIDToTypeID("playbackOptions"), d1);
        executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
        }
    catch (e) { throw(e); }
    }

2 replies

r-binCorrect answer
Legend
May 22, 2023
var ret  = run_cmd('reg add "HKEY_CURRENT_USER\\Software\\abcdefg" /f', false, false);

alert(ret);

/////////////////////////////////////////////////
function run_cmd(cmd, visible, wait)
    {
    try {
        var tmp_name = "tmp.js";

        var file = new File(Folder.temp.fsName + "\\" + tmp_name);
        file.open("w");
        file.encoding = "UNICODE-1-1-UTF-8";

        if (file.error) throw(file.error);

        file.writeln("WScript.CreateObject(\"WScript.Shell\").Run(" + cmd.toSource() + "," + (visible?"1":"0") + "," + (wait?"true":"false") + ");");

        file.writeln("with(new ActiveXObject(\"Scripting.FileSystemObject\")) GetFile(GetSpecialFolder(2).Path+\"\\\\\"+\"" + tmp_name + "\").Delete();");  

        if (file.error) throw(file.error);

        file.close();
        file.execute();

        var ok = false;
    
        try {
            while (1)
                {
                if (!file.exists) { ok = true; break; }

                set_performance("stepByStep");
                }   
            }
        catch(e) { }

        set_performance("accelerated");

        return ok;
        }
    catch(e) { alert(e); }
    }

/////////////////////////////////////////////////
function set_performance(mode)
    {
    try {
        var d = new ActionDescriptor();
        var r = new ActionReference();
        r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("playbackOptions"));
        r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        d.putReference(stringIDToTypeID("null"), r);
        var d1 = new ActionDescriptor();
        d1.putEnumerated(stringIDToTypeID("performance"), stringIDToTypeID("performance"), stringIDToTypeID(mode));
        d.putObject(stringIDToTypeID("to"), stringIDToTypeID("playbackOptions"), d1);
        executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
        }
    catch (e) { throw(e); }
    }
kglad
Community Expert
Community Expert
May 22, 2023

what exactly are your trying to do?

meadXAuthor
Known Participant
May 22, 2023

I want to write to the registry and use this line of code to write to the registry when there is an error in the script 

system('start /min reg add "HKEY_CURRENT_USER\\Software\\abcdefg" /f')
kglad
Community Expert
Community Expert
May 22, 2023

what are you trying to write something to the registry?

 

why are you trying to write something to the registry?