Shouldn't you be able to implement the ADOX library via VBScript? The code below runs perfect via Access 2010 on Windows 7, Office 2010 32-bit, but doesn't via a VBScript. Isn't ADOX just another COM Object like say FileSystemObject?
Dim objADOX
Set objADOX = CreateObject("ADOX.Catalog")
objADOX.ActiveConnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Zamdrist\Desktop\Work\Scripts\Shell.accdb"
MsgBox objADOX.Tables.Count
Sorry, I should point out, VBScript complains that the provider does not exist. Odd because I do in fact have Access 2010 installed.
This is not meant as an answer just simply as a tip that has helped me tremendously. I am constantly working with providers that only work with 32 bit so i always add the attached code to all of my scripts. This way it doesn't matter if the machine that is executing the code is 32 or 64 bit.
'Check for 64 bit and run as 32 bit if needed.
'On error resume next
Set oFso = CreateObject("Scripting.FileSystemObject")
Set oWs = CreateObject("WScript.Shell")
windowsdir = oWs.ExpandEnvironmentStrings("%windir%")
If InStr(LCase(WScript.FullName), windowsdir & "\system32\") And oFso.FolderExists(windowsdir & "\SysWow64") Then
oWs.Run windowsdir & "\SysWow64\WScript.exe """ & WScript.ScriptFullName & """"
WScript.Quit
End If
'code to run as 32 bit
Related
Issue: I need to change the UFT's Remote Agent Settings(image attached) programmatically on a machine before running my test set on that machine.
Method(s) tried so far:
I looked up on the internet and found that all the Remote Agent's Settings' values are placed inside the file mic.ini which is placed inside the bin folder in UFT's installation directory. I thought of opening the file as textstream using a filesystem object and make the required changes. But, it turns out, that I do not have admin rights on that bin folder due to which I am not able to save the changes made in mic.ini file(error: Access is Denied). Unfortunately, Getting the admin privileges is not an option for me.
Apart from this method, I could not find anything which would help me to accomplish this task.
Is there any other way I can change these settings programmatically? Is there an object model for the Remote Agent's Dialog which I can make use of?
Note: This might NOT be the answer you are looking for, but this is what I found and justify itself.
To start with option to uncheck Keep UFT open... option, here is the note directly from UFT help file:
Keep UFT open after a Test Lab run session ends:
By default, when ALM opens UFT on a remote computer during a test set
run (or when it runs selected tests or configurations from the Test
Lab module), it closes UFT at the end of that Test Lab run session.
This ensures that the UFT license is released at that point and made
available for other UFT users.
Selecting this option causes UFT to stay open on your computer (and to
continue using the UFT license) after a Test Lab run session ends.
Note: The behavior described above is relevant only when UFT is opened
from an ALM server that has the SUPPORT_TESTSET_END parameter set to
Y. (Y is the default setting). If UFT is opened from an earlier
version of ALM (or the above-mentioned parameter is set to N), this
option is ignored and UFT always remains open at the end of run
session.
For details on the SUPPORT_TESTEND_END parameter, see the section on
setting ALM configuration parameters in the Application Lifecycle
Management Administrator Guide.
So as mentioned, ALM will close UFT by default if the SUPPORT_TESTSET_END parameter set to Y. So I would check with ALM admin team on this.
Now for option to uncheck Run UFT in debug mode option, you can keep UFT application object's RunMode option to Fast.
Note: You really don't need to do this change as ALM will run UFT scripts in Fast mode by default.
Here is the sample script for understanding:
On Error Resume Next
Dim qtApp '~~> Declare the Application object variable
'~~> Create the UFT Application object
Set qtApp = CreateObject("QuickTest.Application")
'~~> If UFT is notopen then open it
If qtApp.launched <> True then
qtApp.Launch
End If
'~~> Make the QUFT visible
qtApp.Visible = FALSE
If Not qtApp.TDConnection.IsConnected Then
'~~> Make changes in a test on Quality Center with version control
qtApp.TDConnection.Connect "QC URL","DOMAIN Name","Project Name","User Name","Password",False
End If
'--------------------------------------------------------------------
Dim defaultRunMode, fastRunMode, normalRunMode
defaultRunMode = qtApp.Options.Run.RunMode
qtApp.Options.Run.RunMode = "Fast"
fastRunMode = qtApp.Options.Run.RunMode
qtApp.Options.Run.RunMode = "Normal"
normalRunMode = qtApp.Options.Run.RunMode
Msgbox "Different RunModes" & VbCrLf & _
VbTab & "DEFAULT RunMode : " & defaultRunMode & VbCrLf & _
VbTab & "After FAST RunMode : " & fastRunMode & VbCrLf & _
VbTab & "After NORMAL RunMode : " & normalRunMode
'--------------------------------------------------------------------
'~~> Script path and script name in ALM
qtApp.Open "[ALM] Subject\QCScriptPath\ScriptName", False
qtApp.Test.Run
qtApp.TDConnection.Disconnect
'~~> Close UFT
qtApp.quit
'~~> Release Object
Set qtApp = Nothing
'~~> Handle Error
If Err.Number <> 0 Then
Msgbox Err.Number & " : " & Err.Description
Err.Clear
End If
And here is the msgbox output:
For several years I have been running a compiled VB6 program on an church office computer. I had the vb6 program installed on my home computer (Win 7) This program ran without problems. The program opened Excel spreadsheets and allowed the user to manipulate the data on the spreadsheet.
My Windows 7 computer crashed. I have a Windows 8.1 computer and have loaded vb6 on this computer. The installation appears to be successful except when I run the same visual basic project I get a Runtime Error '-2147319779 Automation Error Library not registered.' A sample of my code is shown below:
Dim oExcel As Excel.Application
Set oExcel = Excel.Application
oExcel.Workbooks.Open ("C:\FPCE Financial\FY-2014\2014-01 Financials.xls")
Application.Visible = True
The error occurs on the "Set oExcel = Excel.Application" line.
Any help would be appreciated.
If you haven't set a reference to Excel you need to use "Late Binding" to create the Excel object. As #Noodles says - if you don't have Office installed, it won't work period.
Try changing this
Dim oExcel As Excel.Application
Set oExcel = Excel.Application
To this
Dim oExcel As Object
Set oExcel = CreateObject("Excel.Application")
I am automating a website to fill login details. I have developed that app in vb6 and that was working greatly in windows xp, 7 and 8. Now it is giving error in Windows 10.
In windows 10 when I run the exe directly, the login details are not filling.(I get "OnQuit fired" message). However, when I run the exe as Administrator it works properly.
This is the vb6 code,
Private Sub Form_Load()
Set Web = New SHDocVw.InternetExplorer
Web.Visible = True
Web.Navigate "https://mytestingsite/login.html ", 8
End Sub
Private Sub Web_DocumentComplete(ByVal pDisp As Object, URL As Variant)
On Error GoTo aaa
'MsgBox " URL: " & URL
If URL = "https://mytestingsite/login.html" Then
Web.Document.getElementById("Login_userName").Value = "abcd"
Web.Document.getElementById("Login_userName").onchange
Web.Document.getElementById("Login_password").Value = "123456789"
Web.Document.getElementById("dateField").Value = "15/09/1954"
End If
Exit Sub
aaa:
MsgBox Err.Description & " URL: " & URL
End Sub
Private Sub Web_OnQuit()
MsgBox "OnQuit fired"
End Sub
My question is why run as administrator is required for simple web automation ?
Is it not possible to run application in standard user in Windows 10 ?
How to solve this problem ?
Please don’t suggest me to rebuild application in .net ( It will take lot of time to convert my application to .net)
quick solution to your problem would be to publish a manifest along with your .exe
described here:
How do I create a manifest file in Visual Basic 6.0?
I have a macro runTest in a PowerPoint file test.pptm that I wish to call by using the following VB script. All works well when the script is called on a machine with Office 2010, but the script will only work with Office 2007 providing the PowerPoint application has been opened before calling the script. I'd be interested to hear whether anyone has experienced a similar problem, or to hear of any potential solutions.
Option Explicit
On Error Resume Next
RunProcess
Sub RunProcess()
Dim pptApp
Dim pptPresentation
Set pptApp = CreateObject("PowerPoint.Application")
Set pptPresentation = pptApp.Presentations.Open("C:\test.pptm", True)
pptApp.Run "test.pptm!runTest"
pptApp.Quit
Set pptPresentation = Nothing
Set pptApp = Nothing
End Sub
I resolved the problem by adding
pptApp.Visible = True
after creating pptApp and before opening the presentation.
In the event that it needs Powerpoint launched, I would just trigger the launch as part of the vbscript
Set WshShell = wscript.CreateObject("wscript.Shell")
WshShell.Run "C:\Program Files (x86)\Microsoft Office\Office12\POWERPNT.EXE"
You could build in some error handling to see which version is installed, and call the appropriate exe file
This code is in an ActiveX .dll. For a year this connection worked perfectly, now it doesn't. Here's the code:
Dim objConnection As ADODB.Connection
Dim objRs As ADODB.Recordset
Dim theConnectionStr As String
Dim SanMarDB As Databas
Dim SanMarRs As Recordse
.
.
.
Set objConnection = New ADODB.Connection
theConnectionStr = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & gProgramFilesPath & ";" & _
"Extended Properties='text;HDR=YES;FMT=Delimited;IMEX=1'"
objConnection.Open theConnectionStr
Here is my list of references in the .dll:
Visual Basic for Applications
Visual Basic runtime objects and procedures
Visual Basic objects and procedures
Microsoft Scripting Runtime
Microsoft Excel 14.0 Object Library
Microsoft DAO 3.6 Object Library
Microsoft ActiveX Data Objects 6.1 Library
Microsoft Data Formatting Object Library 6.0 (SP6)
Microsoft Shell Controls and Automation
I get one of two error messages. Here's the first
Invalid setting in Excel key of the Engines section of the Windows Registry.
Google pointed me to some reasons for this error message and I've checked the registry setting and it appears correct, CSVDelimited, no 5-char entries, etc.
The second error message is:
Object variable or With block variable not set
The thing that makes this particularly strange is that I have another dll that has exactly the same references and code and it works perfectly. (only some filenames are different).
Any thoughts? Thanks for helping me out with this.
-t
Something to at least try:
theConnectionStr = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source='" & gProgramFilesPath & "';" & _
"Extended Properties='text;HDR=YES;FMT=Delimited;IMEX=1'"
I.e. use quotes (apostrophes above) around the value for Data Source in case of characters that disrupt connection string parsing.
Also, isn't IMEX only used with the Excel IISAM and not the Text and HTML IISAMs?
Mixing ADO and DAO in one program is odd, but hopefully unrelated.