ActiveXObject("Outlook.Application") Not working when Outlook is open - javascript

I have a javascript that works when Outlook is closed. However, if outlook is open I receive "Automation Server" error.
var outlookApp = new ActiveXObject('Outlook.Application');
var nameSpace = outlookApp.getNameSpace("MAPI");
mailFolder = nameSpace.getDefaultFolder(6);
email = mailFolder.Items.add('IPM.Note.FormA');
email.Subject="Quote: "+ quoteNum + ' | Part#: '+ partNum;
email.To = "lcarreiro#epectec.com"; //who will to be going to
email.HTMLBody = "Quote Attached " + quoteNum;
email.display(0);
Any suggestions besides changing IE setting as I have already done so....

Probably a little late to help you but hopefully it helps anyone else who ends up here.
I was having the same issue and stumbled across https://stackoverflow.com/a/3779945/1002621 which answered a similar question.
Basically the issue is because when you run Visual Studio as an Administrator and Outlook with normal privileges you are no longer allowed to get an instance to the existing Outlook application but as it is single instance it won't create a new one.
This is only an issue if you initiate debugging directly from Visual Studio just starting your own instance of IE makes the problem go away.

Related

How can I stop IE 11/Win7 from removing ".exe" from downloade files?

I have an application which I have created an installer for. I have signed the application with a certificate. With every browser/windows combination I have tried downloading the installer works fine, except Windows 7 IE 11.
This combination strips the .exe off of the file. If I add the .exe back, the installer works fine. The file resides on the web server and I cause the download using the following JS;
function processDownload(inInstalLink, ApplicationName)
{
if (confirm("Download "+ ApplicationName + " application?"))
{
var intRandom = Math.floor((Math.random() * 10000) + 1);
window.location = inInstalLink + "?tempID=" + intRandom; //Launch alternative, typically app download.
}
}
I call the javascript above as follows;
processDownload("MyInstaller.exe", "My Fun Application")
I have read about content disposition tags, but am at a loss on how to implement them here, and not sure if they would solve the problem. Any guidance is appreciated.
This seems to be a common problem in Windows 7 IE 11 with exe downloads without a content disposition.
One solution that others have tried and had success with is appending ‘.exe’ to the url.
window.location = inInstalLink + "?tempID=" + intRandom + ".exe"
With dealing with IE compatibility, sometimes solutions aren’t as intuitive or logical as we would like them to be.

Close Excel Workbook from VBA/JScript without crashing Excel

in VBA, I have a global script control variable in JScript language (Javascript ES3). I have the var "ThisWorkbook" set as
var ThisWorkbook = GetObject('', 'Excel.Application').Workbooks('" + ThisWorkbook.Name + "')
Then I can close the workbook by saying
ThisWorkbook.Close(false)
Full VBA code for completion:
Sub Test
Dim ScriptC as Object
Set ScriptC = CreateObject("ScriptControl"): ScriptC.Language = "JScript"
ScriptC.Eval "var ThisWorkbook = GetObject('', 'Excel.Application').Workbooks('" + ThisWorkbook.Name + "')"
ScriptC.Eval "ThisWorkbook.Close(false)"
End Sub
However, this crashes my Excel and all open workbooks (Excel 2016) - what would be a good way to avoid this? I have to do this from JScript/Javascript, but could for example do it through a WScript variable (as long as it's called from within JScript). The reason for this is that it's triggered by an event that's evaluated in JScript and not in VBA (VBA is just the wrapper in this case).
I've tried "ThisWorkbook.Application.Quit' (as per https://learn.microsoft.com/en-us/office/vba/api/excel.application.quit ), but that doesn't work either.
Thanks!
This bug only occurs when running the command from the immediate window - if run from within a subroutine it does NOT crash.
I had tested in immediate a bunch of times before realizing this.
Non-issue, apologies.

Acrobat's "This file is already open" message

This is a really strange one. Our company has has an InDesign script that, near the end, calls Acrobat (by way of Applescript) to open a PDF file, replace a page in it, then save the file and close it. We've been using this script for over a year and a half now with no issues on 8 of the 9 computers we have. That last one, however, is giving me an odd message when it tries to open and save the file.
To be clear, all 9 computers are Macs, all running OS X 10.9.5 Mavericks. The script is on a central server, so they're all using the same file:
var unlockCover2014 = app.trustedFunction(function (fName, fPrefix)
{
app.beginPriv();
var folderPrefix = fName.match(/^.*?(?=JOBS)/);
console.println("fName is " + fName);
console.println("folderPrefix is " + folderPrefix);
var myDoc = app.openDoc(folderPrefix + "Product Templates/ProofCoverNew/proof_cover_2014.pdf");
myDoc.replacePages(0, fName, 0, 0);
myDoc.saveAs(fName);
myDoc.closeDoc(true);
app.endPriv();
});
This file is stored in the correct folder to be a Folder-level script. 8 of the computers work through this without any trouble whatsoever. The 9th, however, puts this into Acrobat's Javascript console:
fName is /ArtDept/ArtDept/JOBS/425000-425999/425000 Folder/425000_cover.pdf
folderPrefix is /ArtDept/ArtDept/
RaiseError: This file is already open.
Doc.saveAs:9:
===> This file is already open.
I do not understand why this computer, alone, thinks that the PDF files are open already. The problem that arises from this is that, when the main InDesign script is done running, two documents are still open in Acrobat, and the one it's supposed to save does not get saved.
Any ideas about what's going on here?
I did finally discover what the problem was. I feel a bit silly about how (almost) obvious it is, but perhaps it might help others in my situation.
I disabled the line in the main InDesign script that was calling Acrobat, figuring I'd come back to that problem later after I dealt with some other issues. When I did so and ran the main script again, I discovered that Acrobat does, in fact, already open up a copy of that cover sheet PDF sometime during the execution of the main script! I was shocked, at first, but then I did a headdesk when I quickly realized the cause:
InDesign on this computer is set, by default, to automatically open a PDF after exporting it.
So, I just added a short line to the part of my code that sets the PDF Export Preferences to turn that feature off:
with (app.pdfExportPreferences)
{
pageRange = proofRange;
if (multiColor) pageRange = colorTable.toString();
useSecurity = true;
disallowChanging = true;
disallowCopying = false;
disallowDocumentAssembly = true;
disallowExtractionForAccessibility = false;
disallowFormFillIn = true;
disallowHiResPrinting = false;
disallowNotes = true;
disallowPlaintextMetadata = true;
disallowPrinting = false;
changeSecurityPassword = "(NOPE)";
viewPDF = false;
}
It's the viewPDF line at the end. (Sorry, I don't think I can highlight it with markdown.) I do feel silly that I overlooked such a semi-obvious cause, but I hope this might help someone else who is experiencing a similar issue. Thanks for trying to help anyway, #Loic.
Is it possible that the Acrobat script is ran while InDesign has not totally ended writing the PDF File if this is what we are talking about ? Or maybe there are some network latencies that make the file not reachable for the moment.
I would advice using a delay to (in)validate that theory.
delay 3
On another end, why do you need to replace file. I mean can't this be thought in InDesign Scripting Scope only ? Just curious.

Open Sharepoint folder with windows explorer from CRM 2011

I've been struggling with this issue for a while now,
and hope maybe someone in the community can provide a resolution.
I have a requirement which is to put a button on the a CRM account form which will have the same logic as the Open With Explorer button in a Sharepoint document library. The logic is required as the users have to do several click in order to get to this button, and open the required account's folder in windows explorer, which are:
Click Documents in navigation of the form, to open SP integration
Click documents in the SP view
Click library
Click the Open With Explorer button
The CRM is integrated with Sharepoint, and when the folder is opened in windows explorer it has the following sample link
http://{sharepoint}/CRM/7F9F72A1-4591-E011-AC6C-00155D773703/Documents/
Where the GUID 7F9F72A1-4591-E011-AC6C-00155D773703, is the account id in CRM.
From my research i have found that the javascript function that achieves this is
NavigateHttpFolder from the sp.js in Sharepoint.
From this function, and this link About Web Folder Behaviors
I've completed the following function.
var httpFolderDiv = document.createElement("SPAN");
function NavigateToFolder() {
document.body.appendChild(httpFolderDiv);
httpFolderDiv.onreadystatechange = NavigateToFolder;
httpFolderDiv.id = "navDiv";
httpFolderDiv.addBehavior("#default#httpFolder");
if (httpFolderDiv.readyState == "complete") {
httpFolderDiv.onreadystatechange = null;
var link = "";
var account = "";
var accountid = "";
var id = Xrm.Page.data.entity.getId().replace("{", "").replace("}", "");
link = "http://{sharepoint}/CRM/" + id + "/Documents/";
try {
httpFolderDiv.navigateFrame(link, "_blank");
} catch (c) {
alert(c.toString());
}
}
}
This function opens up the folder from Sharepoint in windows explorer, but with limitation if only that folder was previously opened directly from Sharepoint.
I believe that the logic I am missing in the code, is that I don't do mapping of the folder, the way sharepoint does.
I am aware that this folder can be mapped manually as a network drive, Connecting WebDAV Server Using Web folders, but this will not do the trick for me as this will have to be done on every client.
How can I achieve this by grabbing the complete logic from SP, or maybe running a console command from javascript to map the folder prior to opening it with the above function.
I know it's been a while, since this has been posted, but I stumbled upon it while searching for the exact same problem.
Here's what worked for me in SharePoint 2013:
<a href='#' onClick="javascript:CoreInvoke('NavigateHttpFolder', '[path to site]/[library name]/', '_blank');">
Click to open in Explorer
</a>
It's essentially the same function used by SharePoints own functionality.

How to use Javascript to check active directory to see if a user is in a memberof a particular group?

I have at my disposal Javascript and Classic ASP. Using these two how can I check to see if a user is a member of a particular active directory group? I know VBSCRIPT has memberof function but I can only use javascript. Any help is appreciated
You'll need to ensure that your web server is set to use Windows Authentication. Then you can use Request.ServerVariables("LOGON_USER") to get the current user's domain\username.
You'll then query Active Directory using ADSI to get group membership.
Here's a link to msdn's ADSI pages. http://msdn.microsoft.com/en-us/library/aa772170%28v=vs.85%29.aspx
This page has some sample scripts (in vbscript)
As far as I know there is no possibility to access activeDirectory by using Javascript. Javascript runs within the browser - and may not access anything out of this sandbox.
In case I misunderstood your question und you ment server-side checking - use ASP functions to check for.
You might also try using Javascript to instantialte a WScript.Network object
var WshNetwork = new ActiveXObject("WScript.Network");
From there, you can get
var netWorkUserName = WshNetwork.UserName;
var netWorkDomain = WshNetwork.UserDomain;
A word of warning: I'm pretty sure this is IE only and requires security changes in IE.
You'll need AJAX and a connection to the AD using ADODB.Connection with the "ADsDSOObject" provider.
EDIT: I saw your comment above. Here's a start:
ldapCommand.CommandText = "select sn from '" & _
"LDAP://example.com/DC=example,DC=com" & _
"' WHERE samAccountName=" & "'" & username & "'"
Set ldapRecordSet = ldapCommand.Execute
ldapCommand is an ADODB.Command, and if Execute throws an error, then the user is not in the domain.

Categories

Resources