Why we can create an ActiveX in IE to automate Outlook - javascript

Here is the JavaScript code:
function SendMail(to,body,sub)
{
var theApp
var theMailItem
var theApp = new ActiveXObject("Outlook.Application")
var theMailItem = theApp.CreateItem(0)
theMailItem.to = to
theMailItem.Subject = (subject);
theMailItem.Body = (msg);
//theMailItem.display()
theMailItem.send()
}
However, I would like to why we can create an ActiveX for the Outlook and what's the relationship between them.
If we can create an ActiveX to automate the Outlook, can we embed the Outlook in the web page?
Any explanation is appreciate.

Related

Opening an excel file using Protractor

Protractor Query: our application generate a excel file which contains aome formulas. Now until I don't open the excel, it won't readable by exceljs. Is there any way I can open the excel and close it like we do robot in selenium?
Please Note that if i Open the file and keep at specified location below code works fine, but when i download the same from application and try to read it it wont work.
function compareExcelFromScreen(VerificationSection, file, row, column, SheetName, callback) {
var wrkbook = new Excel.Workbook();
var valFromExcel = null;
var filteredExcelValue = null;
var filteredScreenvalue = null;
var temp = null;
wrkbook.xlsx.readFile(file.toString()).then(function () {
var worksheet = wrkbook.getWorksheet(SheetName);
valFromExcel = worksheet.getRow(parseInt(row)).getCell(parseInt(column)).value;
}
}

C# Selenium Headless Chrome Driver is not executing javascript from the website

I'm trying to scrape javascript generated html objects from a website. I've tried many different libraries and I found out that selenium has everything i need.
I've tried to run the driver without being in headless mode, and it WORKS,
but that's not what I need. I need a background task to keep the user interface as clean as possible.
var chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("--no-startup-window");
chromeOptions.AddArgument("--user-agent=" + Settings.globalUserAgent);
chromeOptions.AddArgument("--log-level=3");
ChromeDriverService service = ChromeDriverService.CreateDefaultService();
service.HideCommandPromptWindow = true;
service.SuppressInitialDiagnosticInformation = true;
using(var driver = new ChromeDriver(service, chromeOptions))
{
driver.Url = "https://example.com";
driver.Navigate().GoToUrl("https://example.com/otherpage");
var wait = new WebDriverWait(driver, new TimeSpan(0, 0, 30));
var element = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.Id("sub-conv-fu")));
string source = driver.PageSource;
if (source.Contains("some string:"))
{
File.WriteAllText("test.txt", source);
} else
{
File.WriteAllText("test.txt", source);
return "Error";
}
}
return "";
This line of code contains a variable which I want to get. It's loaded using javascript
var element = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.Id("sub-conv-fu")));
It is working if I remove the "--headless" tag.

What is the ways to verify levels of microphone input in electron?

I am trying to develop desktop app with electron.
I am doing the task that I have to check microphone input level and run the function when there's more than certain level of input.
I have found some Github repositories however most of them requires other audio software like alsa (Linux).
So right now, Web Audio API seems like the right way to go but I don't see any related document or examples about it.
If it is possible can anyone show me the example with Web Audio API?
or just ideas can be helpful too.
If there's other way than Web Audio API that would be great too.
I figured it out by using Web Audio API analyzer!
var constraints = {audio: true};
var stream = null;
navigator.mediaDevices.getUserMedia(constraints).then(function(mediaStream){
callbStream(mediaStream);
}).catch(function(err) { console.log(err.name + ": " + err.message); });
function callbStream(mediaStream){
stream = mediaStream;
}
function getStreamData() {
if(stream != null){
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
var source = audioCtx.createMediaStreamSource(stream);
var analyser = audioCtx.createAnalyser();
source.connect(analyser);
analyser.fftSize = 32;
var dataArray = new Uint8Array(analyser.fftSize);
setTimeout(function(){
analyser.getByteTimeDomainData(dataArray);
console.log('V:' + dataArray[0] / 128.0);
}, 1000);
}
}
var animClock = setInterval(getStreamData, 1000);

Missing attachment from Outlook JS Api

I'm creating an Outlook add-in and I would like to get each attachment from a mail using JavaScript.
So far, it worked fine with this:
var attch = Office.context.mailbox.item.attachments;
for(i = 0; i < attch.length; i++) {
// Logic here
}
But today, I found that an .msi file was missing from the attch variable. I think that's because this file is an executable and thus is considered as dangerous
As a workaround, I know that I can do an AJAX Request to my ASP.Net webserver and consume Exchange API to get the full attachment list :
var exService = new ExchangeService
{
Url = new Uri(data.EwsURL),
Credentials = new WebCredentials(data.Login, data.Password)
};
var message = EmailMessage.Bind(exService, new ItemId(data.mailId));
var propertySet = new PropertySet(ItemSchema.Attachments);
message.Load(propertySet);
if (message.Attachments.Count == 0 || data.Type == "text" || data.Type == "full") return;
foreach (var attch in message.Attachments.OfType<FileAttachment>().Select(attachment => attachment))
{
// Logic here: returns the attachments info to the webpage
}
Is there a better way to get the full attachments list, using the Office.JS API?

Getting special Folder path for a given user in Jscript

How to get the path of a shell folder like "Local Settings" or "Local Appdata" for a specific user other than the current user?
While there are methods for getting special folder paths in Windows Script Host — WshShell.SpecialFolders and Shell.NameSpace — they return paths for the current user only. Getting other users' special folder paths is a bit tricky.
The proper way to do this is to use the Windows API SHGetKnownFolderPath function (or SHGetFolderPath on Windows versions prior to Vista). But the problem is, Windows Script Host doesn't support calling WinAPI functions, so to make use of these functions in your script you'll have to expose them via a custom-written COM component.
Another possible but undocumented solution is to read the special folder paths from that user's registry hive, specifically, the HKEY_USERS\<user_SID>\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders key.
The paths in the User Shell Folders key are typically specified using the %USERPROFILE% environment variable; so to get fully-qualified paths you'll have to substitute this variable with the ProfileImagePath value from the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\<user_SID> key.
Also, the HKEY_USERS\<user_SID> key is only available when the corresponding user is currently logged on. For a general solution, you would have to load the user's hive (<UserProfile>\ntuser.dat) into a temporary registry key (say, HKEY_USERS\Temp) and read values from this key instead.
Below is sample JScript code that demonstrates how your task can be accomplished. On Windows 7 and Vista, you may need to run the script as Administrator depending on your UAC settings.
NOTE: This method is discouraged, as Raymond Chen explains in his article The long and sad story of the Shell Folders key. There's no guarantee it will keep working in future versions of Windows.
var strUser = "foo";
var strDomain = "bar";
// If the account is local, domain name = computer name:
// var strDomain = getComputerName();
var strSID = getSID(strUser, strDomain);
var strProfilePath = getProfilePath(strSID);
// Load the user's registry hive into the HKEY_USERS\Temp key
var strTempKey = "Temp";
loadHKUHive(strTempKey, strProfilePath + "\\ntuser.dat");
// Get unexpanded path, e.g. %USERPROFILE%\AppData\Roaming
//var strAppData = getAppData(strSID);
var strAppData = getAppData(strTempKey);
WScript.Echo(strAppData);
// Expand the previous value to a fully-qualified path, e.g. C:\Users\foo\AppData\Roaming
strAppData = strAppData.replace(/%USERPROFILE%/i, strProfilePath);
WScript.Echo(strAppData);
// Unload the user's registry hive
unloadHKUHive(strTempKey);
function getComputerName() {
var oShell = new ActiveXObject("WScript.Shell");
return oShell.ExpandEnvironmentStrings("%COMPUTERNAME%");
}
function getSID(strUser, strDomain) {
var oAccount = GetObject("winmgmts:root/cimv2:Win32_UserAccount.Name='" + strUser + "',Domain='" + strDomain + "'");
return oAccount.SID;
}
function getProfilePath(strSID) {
var oShell = new ActiveXObject("WScript.Shell");
var strValue = oShell.RegRead("HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\" + strSID + "\\ProfileImagePath");
return strValue;
}
function getAppData(strSID) {
var oShell = new ActiveXObject("WScript.Shell");
var strValue = oShell.RegRead("HKEY_USERS\\" + strSID + "\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\\AppData");
return strValue;
}
function loadHKUHive(strKeyName, strHiveFile) {
var oShell = new ActiveXObject("WScript.Shell");
oShell.Run("reg load HKU\\" + strKeyName + " " + strHiveFile, 0, true);
}
function unloadHKUHive(strKeyName) {
var oShell = new ActiveXObject("WScript.Shell");
oShell.Run("reg unload HKU\\" + strKeyName, 0, true);
}

Categories