Skip to main content
littlehorse3
Known Participant
December 27, 2017
Answered

Fast and invisible cmd call

  • December 27, 2017
  • 2 replies
  • 1762 views

I need to call cmd command to get HDD serial. I will do it often so I need fast and invisible (without popup console window) solution.

  1. app.system

This is perfect fast and invisible solution on MacOS. But user see popup console window on Windows

I will glad to know how to disable with popups windows. Do anybody know how?

  1. quiet VBs file creation and launching:

var command="ping google.com";

var vbsFile = File(Folder.temp + '/aps_call.vbs');

vbsFile.open('w');

//vbsFile.write("chcp 1251\r\n");

vbsFile.write("Dim objShell\r\n");

vbsFile.write('Set objShell = WScript.CreateObject( "WScript.Shell" )\r\n');

vbsFile.write('objShell.Run "' + command + ' > ""' + decodeURI(tempFile.fsName) + '""", 0, True\r\n');

vbsFile.write('Set objShell = Nothing\r\n');

vbsFile.close();

vbsFile.execute();

$.sleep (200);

This is invisible but very slow solution. I don't know why execute method takes 2-3 seconds on my pc. May be somebody knows how do it faster.. )

Thanks for your attention and answers!

This topic has been closed for replies.
Correct answer SuperMerlin

Yes it will be nice to use CreateProcess but sorry I'm still  don't see modified code of this library. For example code of systemCmd. Can you send me project that you complied or link of it?


The modified code....

#include "BasicExternalObject.h"

#include "SoSharedLibDefs.h"

#include <string>

#include <windows.h>

#include <stdio.h>

#include <iostream>

#if defined (_WINDOWS)

    #pragma warning(disable : 4996) // Turn off warning about deprecated strcpy on Win

#endif

/**

* \brief To allow string manipulation

*/

using namespace std;

/**

* \brief Utility function to handle strings and memory clean up

*

* \param s - The referenced string

*/

static char* getNewBuffer(string& s)

{

    // Dynamically allocate memory buffer to hold the string

    // to pass back to JavaScript

    char* buff = new char[1+s.length()];

   

    memset(buff, 0, s.length()+1);

    strcpy(buff, s.c_str());

    return buff;

}

extern "C" BASICEXTERNALOBJECT_API long systemCmd(TaggedData* argv, long argc, TaggedData* retval)

{

    // The returned value type

    retval->type = kTypeString;   

    // Accept 1 and only 1 argument

    if(argc != 1)

    {

        return kESErrBadArgumentList;

    }

    // The argument must be a string

    if(argv[0].type != kTypeString)

    {

        return kESErrBadArgumentList;

    }

char*  cmd = (argv[0].data.string);

    FILE* pipe = _popen(cmd, "r");

    if (!pipe) retval->data.string = "";

    char buffer[128];

    std::string result = "";

    while(!feof(pipe)) {

        if(fgets(buffer, 128, pipe) != NULL)

            result += buffer;

    }

    _pclose(pipe);

    retval->data.string = getNewBuffer(result);

    return kESErrOK;

}

extern "C" BASICEXTERNALOBJECT_API long getClipboard(TaggedData* argv, long argc, TaggedData* retval)

{

    // The returned value type

    retval->type = kTypeString;   

    HANDLE h;  

  if (!OpenClipboard(NULL)) return kESErrBadArgumentList; 

  h = GetClipboardData(CF_TEXT);

  CloseClipboard();

  if(h){

  string text;

    text = (char*)h;

    if(text.length() < 1) return kESErrBadArgumentList;

    retval->data.string = getNewBuffer(text);

  }else{

retval->data.string = "";

  }

    return kESErrOK;

}

extern "C" BASICEXTERNALOBJECT_API long clearClipboard(TaggedData* argv, long argc, TaggedData* retval)

{

    if (OpenClipboard(NULL)){

        EmptyClipboard();

        CloseClipboard();

    }

    return kESErrOK;

}

extern "C" BASICEXTERNALOBJECT_API long setClipboard(TaggedData* argv, long argc, TaggedData * retval)

{   

    // Accept 1 and only 1 argument

    if(argc != 1)

    {

        return kESErrBadArgumentList;

    }

    // The argument must be a string

    if(argv[0].type != kTypeString)

    {

        return kESErrBadArgumentList;

    }

string source = (argv[0].data.string);

int len = source.length() +1;

source = source.c_str();

if(OpenClipboard(NULL))

{

    HGLOBAL clipbuffer;

    char * buffer;

    EmptyClipboard();

    clipbuffer = GlobalAlloc(GMEM_DDESHARE, len);

    buffer = (char*)GlobalLock(clipbuffer);

    strcpy(buffer, LPCSTR(source.c_str()));

    GlobalUnlock(clipbuffer);

    SetClipboardData(CF_TEXT,clipbuffer);

    CloseClipboard();

}

    return kESErrOK;

}

/**

* \brief Free any string memory which has been returned as function result.

*

* \param *p Pointer to the string

*/

BASICEXTERNALOBJECT_API void ESFreeMem (void* p)

{

    delete(char*)(p);

}

/**

* \brief Returns the version number of the library

*

* ExtendScript publishes this number as the version property of the object

* created by new ExternalObject.

*/

BASICEXTERNALOBJECT_API long ESGetVersion()

{

    return 0x1;

}

/**

* \brief Initialize the library and return function signatures.

*

* These signatures have no effect on the arguments that can be passed to the functions.

* They are used by JavaScript to cast the arguments, and to populate the

* reflection interface.

*/

BASICEXTERNALOBJECT_API char* ESInitialize (const TaggedData ** argv, long argc)

{

    return "makeArray,getAverage,appendString_s,myScript_a,acceptBoolean_b";

}

/**

* \brief Terminate the library.

*

* Does any necessary clean up that is needed.

*/

BASICEXTERNALOBJECT_API void ESTerminate()

{

   

}

2 replies

Kukurykus
Legend
January 21, 2018

I used vbs and that didn't make 2 - 3 seconds delay: Re: UI: Remember last path entered

SuperMerlin
Inspiring
December 27, 2017

Windows 64bit only!

You could use Pauls modified External Lib example.

Files are here..

wikisend.com/download/806904

Place both files in the preset/ scripts folder.

The jsx gives a few basix examples, the system command will return data without opening a dos window.

littlehorse3
Known Participant
December 27, 2017

Where can I find documentation for this? Is this library free?

SuperMerlin
Inspiring
December 27, 2017

Thank you! But what about Winx86? I need support it too


Just compiled a 32bit version for you...

Wikisend: free file sharing service