Create ActiveXObject from GUID - javascript

I have the following line in my code:
var ScreenRecorder = new ActiveXObject('CCScreenRecorder.ScreenRecorder');
The problem is that I have 2 entries of this
(one for each version, don't ask me why - this is a fact I need to deal with),
So I want to create the ActiveXObject from the GUID.
I tried to do:
document.createElement('<OBJ' + 'ECT ID="ScreenRecorderWrapper" CLA' + 'SSID="CL' + 'SID:37CCF998-3BB7-' + '4F8A-9D9F-EF391543E94A"></OB' + 'JECT>');
var ScreenRecorder = ScreenRecorderWrapper;
but the problem is that ScreenRecorderWrapper will be defined only after SetTimeout or some other manipulation.
Can I get the ActiveXObject from it's GUID and not from it's name?
Something like:
var ScreenRecorder = new ActiveXObject('37CCF668-3BB7-4F8A-9D9F-EF391543E94A');

ActiveXObject requires a ProgID, however, you can use a version-dependent ProgID rather than a version-independent ProgID.
Version-dependent ProgIDs typically have a version number appended to the version-independent ProgID.
In this case, the version-independent ProgID is 'CCScreenRecorder.ScreenRecorder', and the version-dependent ProgID would be something like 'CCScreenRecorder.ScreenRecorder.1' or 'CCScreenRecorder.ScreenRecorder.2'.
Note that using a version-dependent ProgID can fail if the wrong version is installed. You might want to try the version-dependent ProgID first, and fall back to the version-independent ProgID.

Use the registry for obtaining the ProgId from the CLSID.
Reading the registry in JS is possible through the "Shell" ActiveX
var shellObj = new ActiveXObject("WScript.Shell");
var clsid = "37CCF668-3BB7-4F8A-9D9F-EF391543E94A";
var progid = shellObj.RegRead("HKEY_CLASSES_ROOT\\CLSID\\{"+clsid+"}\\ProgID\\");
var ScreenRecorder = new ActiveXObject( progid );

Related

Java and Javascript - Lastmodified on Linux

I wrote a script on the Jmeter Web Driver in javascript and Java .
On a Windows system , the script is running perfectly . But on a Linux System , i have a weird problem . The lastmodifed then i obtain is not good. front_end.jtl has been modified yesterday , but the script say today at 10:00 in milliseconds timestamp .
Please help me.
// Importing packages (and all classes in package) from Java into Javascript var pkg = JavaImporter(org.openqa.selenium)
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait)
// We don't use wait in this very simple test, but here is way to access for more realistic testing
var wait=new support_ui.WebDriverWait(WDS.browser, 5)
// Start recording the time for this request
WDS.sampleResult.sampleStart();
// Let's get a page
var baseUrl = "cnyw${FE}.mycore.core-cloud.net"
WDS.browser.get("https://"+ baseUrl)
var frontjtl = new java.io.File('/home/mycore/front_end.jtl')
var frontlog = new java.io.File('/home/mycore/jmeter_front_end.log')
var lastmodifjtl = frontjtl.lastModified()
var lastmodiflog = frontlog.lastModified()
if ( lastmodifjtl = lastmodiflog ) {
var screenshot = WDS.browser.getScreenshotAs(pkg.OutputType.FILE)
screenshot.renameTo(new java.io.File('/home/mycore/screenshots/tools/screenshot_cnyw${FE}.png'))
}
// Record the time of the request
WDS.sampleResult.sampleEnd();
I would recommend using Files.getLastModifiedTime() instead, something like:
var lastmodifjtl = java.nio.file.Files.getLastModifiedTime(java.nio.file.Paths.get(frontjtl.toURI()))
should do the trick for you.
Just in case see The WebDriver Sampler: Your Top 10 Questions Answered article for more information
I found an explanation : https://bugs.openjdk.java.net/browse/JDK-8177809
It's a confirmed bug ...
i have rewrite the script in Java directly. All is okay now.

MarkLogic JavaScript scheduled task

I try to schedule a script using the 'Scheduled Tasks' in ML8. The documentation explains this a bit but only for xQuery.
Now I have a JavaScript file I'd like to schedule.
The error in the log file:
2015-06-23 19:11:00.416 Notice: TaskServer: XDMP-NOEXECUTE: Document is not of executable mimetype. URI: /scheduled/cleanData.js
2015-06-23 19:11:00.416 Notice: TaskServer: in /scheduled/cleanData.js [1.0-ml]
My script:
/* Scheduled script to delete old data */
var now = new Date();
var yearBack = now.setDate(now.getDate() - 65);
var date = new Date(yearBack);
var b = cts.jsonPropertyRangeQuery("Dtm", "<", date);
var c = fn.subsequence(cts.uris("", [], b), 1, 10);
while (true) {
var uri = c.next();
if (uri.done == true){
break;
}
xdmp.log(uri.value, "info"); // log for testing
}
Try the *.sjs extension (Server-side JavaScript).
The *.js extension can be used for static JavaScript resources to return to the client instead of executed on the server.
Hoping that helps,
I believe that ehennum found the issue for you (the extension - which is what the mime-type error is complaining about.
However, on the same subject, not all items in ML work quite as you would expect for Serverside Javascript. For example, using sjs as a target of a trigger is (or recently) did not work. So for things like that, it is also possible to wrap the sjs call inside of xqy using xdmp-invoke.

ActiveXObject FileSystemObject not releasing in Javascript

I have a Javascript function that saves JSON data locally, using an ActiveXObject in IE9. It links into FileSystemObject or FSO scripting for file access.
If this Javascript function is run more than once, I get an error in IE debugger: "SCRIPT70: Permission denied" pointing to ts = savefile.OpenAsTextStream(2);
Why will it run just fine the first time, but not after that? My best guess is that something's not being released properly, although I can find no information on MSDN (or here).
Here's the code:
function SaveMyJSON() {
var ts;
var fso = new ActiveXObject("Scripting.FileSystemObject");
var savefilepath = "C:\\MyFolder\\saveFile.json"
var savefile = fso.GetFile(savefilepath);
// open for writing only, value 2, overwriting the previous
// contents of the file
ts = savefile.OpenAsTextStream(2);
var myTestJson = {"id1" : "one", "id2" : "two"};
// copy to json
ts.WriteLine(myTestJson);
ts.Close;
}
The Close method needs empty parenthesis after it, like so:
ts.Close();
Ref here for more info.

How to save Excel workbook to current user desktop by using javascript?

I create workbook from web page by:
var thisTable = document.getElementById("mytable3").innerHTML;
window.clipboardData.setData("Text", thisTable);
var objExcel = new ActiveXObject ("Excel.Application");
objExcel.visible = true;
var objWorkbook = objExcel.Workbooks.Add();
var objWorksheet = objWorkbook.Worksheets(1);
objWorkbook.Worksheets(1).Activate;
objWorksheet.name = "test";
objWorksheet.Paste;
objWorksheet.columns.autofit;
window.clipboardData.setData("Text","");
objWorkbook.Worksheets(1).SaveAs("%USERPROFILE%\\Desktop\\xxx.xls");
But for objWorkbook.Worksheets(1).SaveAs("%USERPROFILE%\\Desktop\\xxx.xls"); — it doesn't save to desktop and gives this error:
SCRIPT1004: Microsoft Excel cannot access the file 'C:\Users\user\Documents\%USERPROFILE%\Desktop\B612F000'. There are several possible reasons:
• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as a currently open workbook.
From #PA. Answer
I finally got an answer by
//For Expand environment
var wshShell = new ActiveXObject("WScript.Shell");
var userProfile = wshShell.ExpandEnvironmentStrings("%USERPROFILE%\\Desktop\\test.xls");
//For Save
objWorkbook.Worksheets(1).SaveAs(userProfile);
Thak You #PA.
You assume that javascript expands environment variables inside an string. Unfortunately for you, it does not.
you'll need to expand it in your code. Use the Environment property of the wscript.shell object to access any environment variable.
first, access the wscript.shell object. In WSH, use
var wshell = WScript.CreateObject("wscript.shell");
or in the browser use
var wshell = new ActiveXObject("WScript.Shell");
and then
var userProfile = wshell.Environment("USERPROFILE");
or you can expand the variable inside your string by using ExpandEnvironmentStrings method
objWorkbook.Worksheets(1).SaveAs(
wshell.ExpandEnvironmentStrings("%USERPROFILE%\\Desktop\\xxx.xls")
);

WIX: Where and how should my CustomAction create and read a temporary file?

I have a script CustomAction (Yes, I know all about the opinions that say don't use script CustomActions. I have a different opinion.)
I'd like to run a command, and capture the output. I can do this using the WScript.Shell COM object, then invoking shell.Exec(). But, this flashes a visible console window for the executed command.
To avoid that, I understand I can use the shell.Run() call, and specify "hidden" for the window appearance. But .Run() doesn't give me access to the StdOut of the executed process, so that means I'd need to create a temporary file and redirect the exe output to the temp file, then later read that temp file in script.
Some questions:
is this gonna work?
How do I generate a name for the temporary file? In .NET I could use a static method in the System.IO namespace, but I am using script here. I need to insure that the use has RW access, and also that no anti-virus program is going to puke on this.
Better ideas? I am trying very hard to avoid C/C++.
I could avoid all this if there were a way to query websites in IIS7 from script, without resorting to the IIS6 Compatibility pack, without using .NET (Microsoft.Web.Administration.ServerManager), and without execing a process (appcmd list sites).
I already asked a separate question on that topic; any suggestions on that would also be appreciated.
Answering my own question...
yes, this is going to work.
Use the Scripting.FileSystemObject thing within Javascript. There's a GetTempName() method that produces a file name suitable for temporary use, and a GetSpecialFolder() method that gets the location of the temp folder. There's even a BuildPath() method to combine them.
so far I don't have any better ideas.
Here's the code I used:
function GetWebSites_IIS7_B()
{
var ParseOneLine = function(oneLine) {
...regex parsing of output...
};
LogMessage("GetWebSites_IIS7_B() ENTER");
var shell = new ActiveXObject("WScript.Shell");
var fso = new ActiveXObject("Scripting.FileSystemObject");
var tmpdir = fso.GetSpecialFolder(SpecialFolders.TemporaryFolder);
var tmpFileName = fso.BuildPath(tmpdir, fso.GetTempName());
var windir = fso.GetSpecialFolder(SpecialFolders.WindowsFolder);
var appcmd = fso.BuildPath(windir,"system32\\inetsrv\\appcmd.exe") + " list sites";
// use cmd.exe to redirect the output
var rc = shell.Run("%comspec% /c " + appcmd + "> " + tmpFileName, WindowStyle.Hidden, true);
// WindowStyle.Hidden == 0
var ts = fso.OpenTextFile(tmpFileName, OpenMode.ForReading);
var sites = [];
// Read from the file and parse the results.
while (!ts.AtEndOfStream) {
var oneLine = ts.ReadLine();
var line = ParseOneLine(oneLine);
LogMessage(" site: " + line.name);
sites.push(line);
}
ts.Close();
fso.DeleteFile(tmpFileName);
return sites;
}

Categories

Resources