Error in webautomation using vb6 in windows 10 - vb6

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?

Related

How to solve VB6 forms crashing with Unload Me in Windows 10?

I am trying to install a VB6 application in Windows 10 computers, but when I load a child form and then unload it, the program crashes. If I start the application as Administrator from the shortcut, I can load and unload everything without issues. Have you experienced this before?
So far I've tried the following:
Started the .exe directly as Administrator. Not working.
Checked the Run As Administrator checkbox in the contextual menu (Properties / Compatibility) of the .exe. No good.
Created a .reg file to affect the HLKM\ ... \AppCompatFlags\Layers keys. Nada.
Tried affecting both the HKLM AND HKCU keys. Thank you, next.
Checked if some Recordset or variable was filled or active. Everything empty.
Tried Unload [name of the form] instead of Unload Me for one of the forms. Same result.
Part of the Unload code for one of the forms is as follows:
Private Sub cmdSalir_Click()
On Error GoTo ErrHandler
Dim frm As Form 'Identifica las formas a cerrar
For Each frm In Forms
If Not frm Is frmPoliza And Not frm Is MDIPrincipal Then
If Not frm Is frmAsegNoReclam And Not frm Is frmEndosoMedico Then _
Unload frm
End If
Next frm
gsPlan = ""
gmstrInstPagoInd = ""
gmstrCondEnv = ""
If IsFormLoaded("frmCotiza") = False Then
'gbInicio = True
End If
Unload Me
ErrHandler: 'APM 2019-01-31: Captura el error que se provoca al descargar la forma
If Err.Number <> 0 Then
MsgBox "Ocurrió un error al cerrar: " & Err.Number & " - " & Err.Description, vbOKOnly
End If
End Sub
It is important to say that WinXP's installations are working correctly, but in 2 Win10's computers the error was replicated, so I'm guessing either Win10's security policies or the way the installation package is made has something to do with this.
If you can help me with this issue, I will appreciate it greatly.
Thank you,
Tony.
If the issue is that you need to run with elevated rights, then I suggest you declare that in you application manifest such that the user is prompted grant that. You can either create a separate manifest file or embed it. See here for details:
How do I create a manifest file in Visual Basic 6.0?
So I told the client about this issue, and decided to have the program virtualized in XP better than adapted to x64. Not the closing I wanted, but a closing after all.
Thank you all for your efforts.
Not sure if this will fix the specific problem but have found that running the application in Windows 8 Compatibility Mode on Windows 10 helps with issues like this. Worth a try.

Automate UFT Remote Agent Settings

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:

Using ADOX via VBScript

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

VB6 code to find windows OS version

I am using OSVERSIONINFO to check the OS in my vb6 application. But i am not able differentiate between windows 7 and windows server 2008 R2 because they have same version number,dwMajorVersion and dwMinorVersion. So how to differentiate between these. I think it can be done in vb.net using some other method. But how it can be done in vb6?
As Xearinox noted in the above comment, OSVERSIONINFOEX returns more information.
In particular, you can examine wProductType to determine whether VER_NT_WORKSTATION (0x0000001) is set or not. If it is, the machine is running a client OS, otherwise, server.
The chart in the remarks section of the OSVERSIONINFO MSDN entry even has a column which points out detecting the various OS's using that struct item.
Right Click On Tool Bar > Components And Add > Microsoft SysControl 6.0.
Double Click The SysInfo Button to Add on Form and use this code
Private Sub Form_Load()
Dim HancyRockz as string
HancyRockz = "OsVersion :- " & SysInfo1.OSVersion & " / Built " & SysInfo1.OSBuild
Text1.Text=HancyRockz
End Sub

Alternative to inet & webbrowser control to retrieve HTML only?

I would like to download only the HTML code in my VB6 program.
Webbrowser control is good but it hangs and also it has issues such as needing to disable the JavaScript, pic, etc in order to get just the HTML
The Inet control is better, but it is "buggy"
Is there any other control ?
If you only want to download the HTML of a page, you can easily use Winsock control.
Private Sub Form_Load()
Winsock1.Connect "stackoverflow.com", 80
End Sub
Private Sub Winsock1_Close()
Winsock1.Close
End Sub
Private Sub Winsock1_Connect()
Winsock1.SendData "GET /questions/8624871/vb6-alternative-to-inet-webbrowser-control HTTP/1.1" & vbCrLf & "Host: stackoverflow.com" & vbCrLf & vbCrLf
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim s As String
Winsock1.GetData s, vbString
RichTextBox1.Text = RichTextBox1.Text & s
End Sub
My suggestion is to host WebKit.NET in your VB 6 application just like you would any other .NET control.
Although it is a .NET control, which means that it won't work natively out-of-the-box with VB 6, it is possible to use controls developed in .NET with a VB 6 application. Microsoft provides the Interop Forms Toolkit as an interoperability mechanism between the two languages.
Essentially, you'll use one of the .NET languages (it doesn't have to be VB.NET; you could also use C#) to create an ActiveX DLL containing your UserControl and register it for COM interop. Then, you can add this ActiveX control to your VB 6 project and hook up to handle the events it raises.
You can find a more complete sample on how to do this here on CodeProject, or here on CodeGuru.
Indeed this approach is not going to be trivial to implement. But I suspect that it's your only alternative to the bundled WebBrowser control, considering that IE was pretty much dominating the browser market back when VB 6 was popular and no one is developing new controls for VB 6 anymore.
You don't need API calls, you don't need WinSock, you don't need Inet, you don't need WebKit interop. Just do it the easy way, using native VB6 code. Here's an excellent article by Karl Peterson with sample code.
This is good code, and it works even in ASP, VBScript.
Function GetHTMLCode(strURL) As String
Dim strReturn ' As String
Dim objHTTP ' As MSXML.XMLHTTPRequest
If Len(strURL)=0 Then EXIT FUNCTION
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
objHTTP.open "GET", strURL,False
objHTTP.send 'Get it.
strReturn =objHTTP.responseText
Set objHTTP = Nothing
GetHTMLCode = strReturn
End Function
Now call this function like this (always write with protocol):
Msgbox GetHTMLCode("http://www.stackoverflow.com")

Resources