How to open AS400 emulator using Vbscript - vbscript

I made a HTA app that needs to open As400 emulator but I can't make it work. This is my code.
Sub TestSub()
Dim sessName,sessNo,userName,pass,filePath,i,aw
sessName = document.getElementById("session").value
sessNo = document.getElementById("sessno").value
userName = document.getElementById("uname").value
pass = document.getElementById("psw").value
sessName = sessName&".WS"
filePath = "C:\Users\Public\Documents\IBM\Client Access\Emulator\Private\"&sessName&".ws"
'sessNo = sessNo*1
'For i = 0 to sessNo
Set autECLConnMgr = CreateObject("PCOMM.autECLConnMgr")
Set autECLConnList = CreateObject("PCOMM.autECLConnList")
Set autECLOIA = CreateObject("PCOMM.autECLOIA")
Set autECLPS = CreateObject("PCOMM.autECLPS")
Set autECLSession = CreateObject("PCOMM.autECLSession")
autECLConnList.Refresh()
autECLConnMgr.StartConnection("PROFILE=filePath CONNNAME=A WINSTATE=RESTORE")
autECLOIA.SetConnectionByName("A")
autECLPS.SetConnectionByName("A")
autECLOIA.WaitForAppAvailable()
autECLOIA.WaitForInputReady()
'Next
msgbox "Macro Finished!"
End Sub
I can't even open the emulator. Don't know what's wrong with my code since I'm just a beginner in making HTA apps. Thanks in advance!!
This is the error i get everytime I run it.

Related

How to switch to the new browser window which opens after clicking on parent browser, in UFT?

There is an application on which a link is present. Once clicked on the link, it opens up a new browser.
Can someone please help to guide how to select and activate the new window?
I am using UFT for Automation.
Using browser collection, we can achieve this. Hope this helps for.
Set objLastBrowser = GetLastBrowserInstance()
Public Function GetLastBrowserInstance()
Dim objBrowserDesc
Dim objBrowserCollection
Dim objLastOpenedBrowser : objLastOpenedBrowser = Null
Dim intCount
Dim lngHandle
Set objBrowserDesc = Description.Create
objBrowserDesc("micClass").Value = "Browser"
Set objBrowserCollection = Desktop.ChildObjects(objBrowserDesc)
intCount = objBrowserCollection.Count
If intCount > 0 Then
Set objLastOpenedBrowser = Browser("CreationTime:=" & intCount - 1)
objLastOpenedBrowser.Sync
lngHandle = objLastOpenedBrowser.GetROProperty("hwnd")
Window("hwnd:=" & lngHandle).Activate
End If
Set GetLastBrowserInstance = objLastOpenedBrowser
End Function

Error on merging ppt files using visual basic scripting

I am a newbie to visual basic scripting..
I was trying to combine multiple ppt files into a single ppt using the following .vbs code.
it was supposed to create a new ppt called merged.ppt from all the ppts stored in a subfolder called PPTmerge.
But on executing I get error on line:
Set out = Application.Presentations.Open(f)
Can someone help me please...!
Const PPTMERGE_FILE = "Merged.ppt"
Const PPTMERGE_FOLDER = ".\PPTmerge"
Dim Application
Set Application=CreateObject("PowerPoint.Application")
Application.Visible = True 'must do this for merge to work
Dim first 'to open power point only once
first = True
Dim fs
Set fs=CreateObject("Scripting.FileSystemObject")
Dim folder
Set folder = fs.GetFolder(PPTMERGE_FOLDER)
Dim out
Dim f
Dim ff
For Each ff in folder.Files
f = PPTMERGE_FOLDER + "\" + ff.Name
If first Then
Dim p
Set out = Application.Presentations.Open(f)
out.SaveAs PPTMERGE_FOLDER + "\..\" + PPTMERGE_FILE
first = False
Else
out.Slides.InsertFromFile f, out.Slides.Count
End If
Next
If Not first Then
out.Save
out.SlideShowSettings.Run
'out.Close
End If
Set folder = Nothing
Set out = Nothing
Set folder = Nothing
'Application.Quit
Set Application = Nothing
You haven't specified the full path name.
Try const pptmerge_folder = "full path name here"
The code on line 2.

vb script not working on windows 8

I have a script that I'm using to add watermarks to pdf and worked fine with windows vista and xp
With windows script I'm getting this error :
80070005
This is the script I'm using :
Option Explicit
Const Watermark = "watermark.pdf"
Const Watermark2 = "AAAWatermark.pdf"
Dim objArgs, fname, tfname, fso, pdf
Set objArgs = WScript.Arguments
fname = objArgs(0)
Set fso = CreateObject("Scripting.FileSystemObject")
tfname = fso.GetTempName
Set pdf = WScript.CreateObject("pdfforge.pdf.pdf")
pdf.StampPDFFileWithPDFFile fname, tfname, Watermark, 1, 9999, false, 1, 10
If fso.FileExists(tfname) Then
fso.DeleteFile(fname)
fso.MoveFile tfname, fname
Else
MsgBox "There was an error adding the Watermark!", vbCritical, AppTitle
End If
Set pdf = Nothing
Set fso = Nothing
Set objArgs = Nothing
Any ideal please?
Thank you
Although I'm a little rough with my Francais, it would appear that you do not have rights to save temporary files in that directory mentioned in the error box or the directory does not exist? You could right click the folder and go to le security tab and add the everyone object and assign write access (or something more secure if you have some other group, etc)
(Edit: The original post had a screenshot in French for added context here)

Starting an application with invisible console window

I have created a VB script which creates a shortcut to execute my test_application.exe. I want my application to run without a console. I am using following script to create the shortcut
Create_ShortCut "C:\Users\Me\bin\MyApplication.exe", "Desktop", "My-Test", "C:\Users\Me\bin" , 0, 1
Private Sub Create_ShortCut(TargetPath, ShortCutPath, ShortCutname, WorkPath, Window_Style, IconNum)
Dim VbsObj
Set VbsObj = CreateObject("WScript.Shell")
Dim MyShortcut
ShortCutPath = VbsObj.SpecialFolders(ShortCutPath)
Set MyShortcut = VbsObj.CreateShortcut(ShortCutPath & "\" & ShortCutname & ".lnk")
MyShortcut.TargetPath = TargetPath
MyShortcut.Arguments = "127.0.0.1 5000 -exec=C:\Users\Another\other_application.exe"
MyShortcut.WorkingDirectory = WorkPath
MyShortcut.WindowStyle = Hidden
MyShortcut.WindowStyle = 0
MyShortcut.IconLocation = TargetPath & "," & IconNum
MyShortcut.Save
End Sub
I would like to start my application in invisible window and the other application to start in a normal window. When I create a shortcut like this I am not able to run my application in invisible mode. Am I doing anything wrong ?
Don't target the console subsystem. If you do, expect to see a console. Instead target the GUI subsystem.

Opening Word from VBScript hangs, can't figure out why

I'm not really a programmer by trade, so forgive me if I'm not aware of any standard debugging tools.
I have what I thought was a very simple VBScript (just a txt file saved with a .vbs extension):
Const wdDoNotSaveChanges = 0
Const wdRevisionsViewFinal = 0
Const wdFormatPDF = 17
Dim arguments
Set arguments = WScript.Arguments
Function DOC2PDF(sDocFile)
Dim fso ' As FileSystemObject
Dim wdo ' As Word.Application
Dim wdoc ' As Word.Document
Dim wdocs ' As Word.Documents
Set fso = CreateObject("Scripting.FileSystemObject")
sDocFile = fso.GetAbsolutePathName(sDocFile)
sPdfFile = fso.GetParentFolderName(sDocFile) + "\" + fso.GetBaseName(sDocFile) + ".pdf"
Set wdo = CreateObject("Word.Application")
Set wdocs = wdo.Documents
Set wdoc = wdocs.Open(sDocFile)
if fso.FileExists(sPdfFile) Then
fso.DeleteFile sPdfFile, True
End If
Set wview = wdoc.ActiveWindow.View
wview.ShowRevisionsAndComments = False
wview.RevisionsView = wdRevisionsViewFinal
wdoc.SaveAs sPdfFile, wdFormatPDF
wdo.Quit wdDoNotSaveChanges
Set fso = Nothing
Set wdo = Nothing
End Function
however, the following line is causing huge grief:
Set wdoc = wdocs.Open(sDocFile)
Sometimes the Word ActiveX object just freezes at this step. I've verified this by some super-simple debugging by putting a WriteLine after each line and seeing where it stops.
Word just sits there consuming 100% CPU, and the script never gets past that step.
How can I go about debugging to find out what the hell is going on with the Word ActiveX object and why it's just hanging and never returning?
Word might be waiting for a prompt from you. I would make Word visible and see if you can visually see what the problem is:
Set wdo = CreateObject("Word.Application")
'if memory serves, this should make Word visible
wdo.Visible = true
Set wdocs = wdo.Documents

Resources