Script Works on Win 7, Not on Server 2003 - vbscript

I have a script that is rather simple, it boots up WinSCP and checks the directory for a file that starts with "TSA". If the file exists, it exits, if it does not exist, it transfers over a new file.
Its up and running on my Windows 7 machine, that is where i created it - but when i transfer it over to my server [windows server 2003] it never finds the file.
My script:
var FILEPATH = "../zfinance/TSA";
// Session to connect to
var SESSION = "someplace#somewhere.com";
// Path to winscp.com
var WINSCP = "c:\\program files\\winscp\\winscp.com";
var filesys = WScript.CreateObject("Scripting.FileSystemObject");
var shell = WScript.CreateObject("WScript.Shell");
var logfilepath = filesys.GetSpecialFolder(2) + "\\" + filesys.GetTempName() + ".xml";
var p = FILEPATH.lastIndexOf('/');
var path = FILEPATH.substring(0, p);
var filename = FILEPATH.substring(p + 1);
var exec;
// run winscp to check for file existence
exec = shell.Exec("\"" + WINSCP + "\" /log=\"" + logfilepath + "\"");
exec.StdIn.Write(
"option batch abort\n" +
"open \"" + SESSION + "\"\n" +
"ls \"" + path + "\"\n" +
"exit\n");
// wait until the script finishes
while (exec.Status == 0)
{
WScript.Sleep(100);
WScript.Echo(exec.StdOut.ReadAll());
}
if (exec.ExitCode != 0)
{
WScript.Echo("Error checking for file existence");
WScript.Quit(1);
}
// look for log file
var logfile = filesys.GetFile(logfilepath);
if (logfile == null)
{
WScript.Echo("Cannot find log file");
WScript.Quit(1);
}
// parse XML log file
var doc = new ActiveXObject("MSXML2.DOMDocument");
doc.async = false;
doc.load(logfilepath);
doc.setProperty("SelectionNamespaces",
"xmlns:w='http://winscp.net/schema/session/1.0'");
doc.setProperty("SelectionLanguage", "XPath");
var nodes = doc.selectNodes("//w:file/w:filename[starts-with(#value, '" + filename + "')]");
if (nodes.length > 0)
{
WScript.Echo("File found");
WScript.Quit(0);
}
else
{
WScript.Echo("File not found");
WScript.Quit(1);
}
After much investigation, i think i've found the piece of code that does not function properly:
// parse XML log file
var doc = new ActiveXObject("MSXML2.DOMDocument.6.0");
doc.async = false;
doc.load(logfilepath);
doc.setProperty("SelectionNamespaces",
"xmlns:w='http://winscp.net/schema/session/1.0'");
The only problem is, i have no idea why. The log file at this point should be written over with the xml code, but this does not happen.
Thanks in advance for any help.

And the answer is........... WinSCP on Windows Server 2003 was WAY out of date. So out of date that the log was completely different from one version to the next. Updated and VIOLA! Problem solved. Thanks for your help.

Maybe you need to install MSXML2.DOMDocument.6.0
http://msdn.microsoft.com/en-us/library/windows/desktop/cc507436%28v=vs.85%29.aspx
If you open up regedit and look for "MSXML2.DOMDocument.6.0" does it find it? If so maybe security settings for the script need to be set in order to be able to create an activeX object.
What can you see when you put some stuff in try catch?
try{
//stuff
}catch(e){
WScript.Echo(e.message);
}

Related

Split window java script for InDesign

Does anyone know of or can help me figure out how to create a script for InDesign to do the Split Screen command, this is found under menu selection Window > Arrange > Split Window. Thank you!
Basically this should work:
app.menuActions.item("$ID/Split Window").invoke()
But actually it sometimes works and sometimes doesn't. I can't tell why.
It works more or less stable as a toggle split/unsplit this way:
try {
app.menuActions.item("$ID/Split Window").invoke()
} catch(e) {
app.menuActions.item("$ID/Unsplit Window").invoke()
}
Probably there is some property, which you can read and run split command only if the window is not splitted already. I don't know.
Update
The list of 'menuActions' you can get with this script:
var list = "ID\tName\tArea\n";
var i = 0;
for (var i=0; i<app.menuActions.length; i++) {
var m = app.menuActions[i];
list += m.id + "\t" + m.name + "\t" + m.area + "\n";
}
f = File("menu_actions.txt");
f.encoding = "UTF-8";
f.open("w");
f.write(list);
f.close();
f.execute(); // to open the txt file immediately
\\ alert(i + " actions wese saved to " + f.fsName);
All credits to Kasyan Servetsky: http://kasyan.ho.ua/tips/indesign_script/all/open_menu_item.html

Adding multiple CC recipients in VBScript; Recipient.Type not working

I am working on a jsx (extendscript project) in which I am calling a VBS snippet with app.doScript. I cannot get the email_cc and email_cc2 recipients to show up as cc; they are stuck in the main "To" sending. I will not know in advance whether they exist in the users' address book, so I am adding them as recipients than trying to set their Type.
var vbs = 'Dim objOutl\r';
vbs += 'Set objOutl = CreateObject("Outlook.Application")\r';
vbs += 'Set objMailItem = objOutl.CreateItem(olMailItem)\r';
vbs += 'objMailItem.Display\r';
vbs += 'strEmailAddress = "' + email_address + '"\r';
vbs += 'objMailItem.Recipients.Add strEmailAddress\r';
vbs += 'strSubject = "' + the_subject + '"\r';
vbs += 'objMailItem.Subject = strSubject\r';
vbs += 'objMailItem.Body = "' + the_bodytext + '"\r';
if (email_cc && email_cc != "") {
vbs += 'Set cc1Recipient = objMailItem.Recipients.Add ("' + email_cc + '")\r';
if (email_cc2 && email_cc2 != "") {
vbs += 'Set cc2Recipient = objMailItem.Recipients.Add ("' + email_cc2 + '")\r';
vbs += 'cc1Recipient.Type = olCC\r';
vbs += 'cc2Recipient.Type = olCC\r';
}
else {
vbs += 'cc1Recipient.Type = olCC\r';
}
}
if (has_attachment) {
vbs += 'objMailItem.Attachments.Add "' + pdf_file + '"\r';
}
Check out the following points:
Try to use the fully qualified name in the code with the enum name, for example:
OlMailRecipientType.olCC
Use the Resolve method which attempts to resolve a recipient object against the address book. It returns true if the recipient was resolved.
Call the Save method to apply changes made through the OOM. Sometimes it makes sense to close the item, switch to another Outlook item, and then come back to check out results. Outlook caches changes and doesn't propagate changes made using the OOM immediately.
Read more about these methods and properties in the How To: Fill TO,CC and BCC fields in Outlook programmatically article.

Check if folder exists

my structure is as follows
MyRootFolder
└──subfolder1
└──subfolder2
.
.
.
└──subfolder n
I have a requirement where-in I need to check if a sub-folder exists within a root folder and if not create it. I can't find a direct API to check for the sub-folder existence. Instead, I see an API like
folder.get_SubFolders();
which would give me a list of all the sub-folders and then iterate to check if sub-folder exists or not. The problem here is that I might end up having to iterate many folders which I don't want to do. Is there a different way to achieve this? I'm using Filenet 5.2.1
ok, this is the closest option that I could find.
Search in FileNet for the subfolder using below query.
SELECT FolderName FROM Folder WHERE FolderName='subfolder1' and Parent=OBJECT({parent-folder-guid})
If the above search returns a result, the subfolder is present if not create one.
Another approach could be - you try to create a folder you want, if already exists dont create it else create it. To achieve it you dont have to iterate through the existing folders. I had the same requirement for one of my project where I had to move the content from shared drive to FileNet P8 and assigning properties to them while maintaining the same folder paths. Following snippet might help someone:
public static Folder createFolderStructure() {
Connection conn = Factory.Connection.getConnection(ConfigInfo.CE_URI);
Domain dom = Factory.Domain.getInstance(conn, null);
ObjectStore os = Factory.ObjectStore.getInstance(dom,
ConfigInfo.OBJECT_STORE_NAME);
Folder folder = null;
// pass your desired folder string here, excluding the starting root "/"
String folderpath = "APITest/some/folder/2014/12/2";
System.out.println("\nGiven input folder path is :: " + folderpath + "\n");
String[] myarray = folderpath.split("/");
for (int x = 0; x < myarray.length; x++) {
try {
if (x == 0) {
folder = Factory.Folder.createInstance(os, null);
Folder rootFolder = Factory.Folder.getInstance(os, null, "/");
folder.set_Parent(rootFolder);
folder.set_FolderName(myarray[x]);
System.out.println("Creating main (first) folder.. \t" + myarray[x]);
folder.save(RefreshMode.NO_REFRESH);
} else {
String currentfolder = myarray[x];
String parentfolder = "";
for (int i = 0; i < x; i++) {
folder = Factory.Folder.createInstance(os, null);
parentfolder = parentfolder + "/" + myarray[i];
Folder nxtrootFolder = Factory.Folder.getInstance(os, null, parentfolder);
folder.set_Parent(nxtrootFolder);
folder.set_FolderName(currentfolder);
}
System.out
.println("Trying to create " + currentfolder + " in " + parentfolder);
folder.save(RefreshMode.NO_REFRESH);
}
} catch (EngineRuntimeException ere) {
ExceptionCode code = ere.getExceptionCode();
if (code != ExceptionCode.E_NOT_UNIQUE) {
throw ere;
}
System.out.println("Above folder already exists...skipping...");
}
}
return folder;
}
This is copied from my own blog.

Getting below error while running ruby script

I am running a test suite in Soap UI where I am trying to call one ruby script from groovy script. The step is getting executed successfully but still the script is not able to move on to the next step as it gives this error after running.
Have searched in google about this error, but found no proper resolution. Moreover the error itself is not very explanatory.
Will appreciate any kind of help.
Below is the groovy script which is calling "ap-v4-batch_DEV_QA.rb" ruby script.
This ruby script opens a browser and performs the task successfully and closes the browser. We expect the step to be marked as Passed so that it can move on to the next step, but it gives the error mentioned at the bottom.
Groovy Script:
String script = "webdriver/v4/ap-v4-batch_DEV_QA.rb";
String argv0 = com.eviware.soapui.SoapUI.globalProperties.getPropertyValue("GLOB_DefaultIP");
String argv1 = "com.wupay.batch.process.tasks.PaymentFileParsingTask_RunOnce";
String argv2 = "";
String argv3 = "";
String argv4 = "";
/* Nothing needs to be modified below */
String commandLine = "ruby " + com.eviware.soapui.SoapUI.globalProperties.getPropertyValue("GLOB_ScriptLocation") + "/" + script + " " + argv0 + " " + argv1 + " " + argv2 + " " + argv3 + " " + argv4;
log.info("Running command line: " + commandLine);
java.lang.Runtime runtime = java.lang.Runtime.getRuntime();
java.lang.Process p = runtime.exec(commandLine);
def propertyStep = testRunner.testCase.getTestStepByName("Properties");
java.io.BufferedReader stdInput =
new java.io.BufferedReader(new java.io.InputStreamReader(p.getInputStream()));
java.io.BufferedReader stdError =
new java.io.BufferedReader(new java.io.InputStreamReader(p.getErrorStream()));
String s = null;
String e = null;
StringBuffer eb = new StringBuffer();
while ((e = stdError.readLine()) != null) {
eb.append(e);
log.error("Ruby: " + e);
}
while ((s = stdInput.readLine()) != null) {
log.info("Ruby: " + s);
if(s.startsWith("#prop")) {
String[] propSplit = s.split(":", 3);
testRunner.testCase.setPropertyValue(propSplit[1], propSplit[2]);
}
}
p.waitFor();
log.info("Ruby: exit value " + p.exitValue());
if(eb.length() > 0) {
throw new Exception(eb.toString());
}
Error:
java.lang.Exception: C:/Ruby23/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:133:in require':require "watir-webdriver"is deprecated. Please, userequire "watir". java.lang.Exception: C:/Ruby23/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:133:inrequire': require "watir-webdriver" is deprecated. Please, use require "watir". error at line: 57
I have finally resolved the issue.
The issue was that ruby script was not accepting require "watir-webdriver".
I installed watir and replaced require "watir-webdriver" with require "watir".
now I am not getting the above mentioned error.
Thanks anyways!
Regards,
Faraz

Using JScript for uninstall script

I am building an installer in VS2010 and want a script to run after uninstall (to remove license files). I have found JScript as a scripting language for Windows 7 and have implemented a simple script to delete a directory (which works fine):
var wshShell = WScript.CreateObject("WScript.Shell");
var result = wshShell.Popup("Remove license?", 0, "Remove license?", 4);
if (result == 6) {
var license_dir = wshShell.ExpandEnvironmentStrings("%ProgramData%");
license_dir += "\\<my product>";
var fso;
fso = new ActiveXObject("Scripting.FileSystemObject");
if (fso.FolderExists(license_dir)) {
fso.DeleteFolder(license_dir, true);
} else {
WScript.Echo(license_dir + " didn't exist. Nothing removed.");
}
}
My question is, is this a valid and (more importantly) portable way of doing this?

Resources