I couldn't find any answer on this topic that specifically relates to me, or any good answers that actually work.
I keep getting an error saying "Object does not support this property or method 'document'" on my code below:
Dim objShell
Set objShell = CreateObject("Shell.Application")
iURL = "www.wizard101.com"
Call objShell.ShellExecute("C:\Program Files\Google\Chrome\Application\chrome.exe", iURL, "", "", 1)
objShell.document.all.item("loginUserName").value = "username"
objShell.document.all.item("loginPassword").value = "password"
wscript.sleep(2000)
objShell.document.all.item("submit").click
wscript.sleep(2000)
To be honest, I'm pretty sure I know what the issue is, I'm trying to edit objShell when objShell is defined as a Web Browser directory. But what I'm asking is how to fix this. How would I still be able to edit web elements while also finding Google Chrome and bringing the user to a specific website? Thanks.
Related
I'm trying to write a VB script that will log into a secure website and download a series of reports.
The following gets me into the website, but after login the whole site is written in javascript.
Dim oIE
Set oIE = CreateObject("InternetExplorer.Application")
With oIE
.Visible = True
.Navigate SecureWebsite
Do While .Busy Or Not .readyState = 4: WScript.Sleep 100: Loop
Do Until .document.readyState = "complete": WScript.Sleep 100: Loop
Do While TypeName(.document.getElementById("username")) = "Null": WScript.Sleep 100: Loop
End With
Set Helem = oIE.document.getElementByID("username")
Helem.Value = "myusername"
Set Helem = oIE.document.getElementByID("password")
Helem.Value = "mypassword"
Call oIE.Document.all.loginForm.submit
I've found a link that I can use with parameters to search for the reports I need. When I follow the link, Internet Explorer returns a JSON file that I can open/download. The JSON file contains a Report ID that I can use as a parameter in another link to download the file that I need.
Is there any way using the InternetExplorer object to read the text contents of the JSON file into a variable so that I can parse the Report ID out of it? All the examples I've found use the MSXML2.XMLHTTP object, but that disconnects it from the sign-on I've achieved in the InternetExplorer object.
I ended up doing this in C#. The website had redirects and SSO so I couldn't get a direct WebClient Get/Post, but I compromised by logging in using a WebBrowser object and then passing the cookies to a HttpWebRequest object, per this excellent guide:
https://www.codeproject.com/Tips/659004/Download-of-file-with-open-save-dialog-box
I am trying to use the WinSCP COM library on a old VB6 project I have (it's a legacy application that generates an OCX file, I think we have to use VB6 for it but not 100% sure).
Anyway we want to implement SFTP, and WinSCP can do that readily.
I registered the COM object, and can see the WinSCPNet type library when I go to add the reference. However I can't see the properties/methods of the classes when I look at the library in the object browser. Further, this code fails, it does not get to the 3rd MsgBox ("In SendWinSCP4"), it returns from the function at that point, I think because the property UserName is not exposed.
MsgBox ("in SendWinSCP")
Dim session As WinSCPnet.session
Dim sessionOptions As WinSCPnet.sessionOptions
Dim transferOptions As WinSCPnet.transferOptions
Set session = New WinSCPnet.session
Set sessionOptions = New WinSCPnet.sessionOptions
Set transferOptions = New WinSCPnet.transferOptions
MsgBox ("in SendWinSCP3")
sessionOptions.Protocol = Protocol_Sftp
sessionOptions.HostName = "example.com"
sessionOptions.UserName = "user"
sessionOptions.Password = "example.com"
sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
MsgBox ("in SendWinSCP4 " & sessionOptions.HostName & "!")
See above, using On Error Resume Next got me past the error.
I am trying to list QC11 project and domain name in combo box on form load() but I am getting error object required,code I am using:
Dim tdc As New TDAPIOLELib.TDConnection
Dim projectList As Customization
Dim Project As Customization
Dim Domain As Customization
Set tdc = CreateObject("TDApiOle80.TDConnection")
tdc.InitConnectionEx "https://xyz/omu"
For Each Domain In TheTDConnection.DomainsList
Set projectList = tdc.GetAllVisibleProjectDescriptors
For Each Project In projectList
ComboBox1.AddItem (Project.Name)
ComboBox2.AddItem (Project.DomainName)
Next Project
Next Domain
If that's really the code you are using, then for a start this line is probably generating an error:
For Each Domain In TheTDConnection.DomainsList
Based on the rest of your code "TheTDConnection" should be "tdc":
For Each Domain In tdc.DomainsList
Oh, and to be doing this you should almost certainly be logged in first by calling tdc.Login... rather than just connected to the server.
On a related note, the DomainsList property is deprecated. I think you can just loop through the List of ProjectDescriptor objects returned by GetAllVisibleProjectDescriptors since that covers all projects under all domains that the current logged on user has access to.
Edit: this is a complete solution based on the original question. Here's working tested code that will cycle through the domains/projects that the provided user has access to. This assumes you have the QC/ALM Connectivity add-in installed (required).
If you are running this piece of VBScript on a 64 bit machine you need to run it using the 32bit version of wscript.exe: C:\Windows\SysWOW64\wscript.exe "c:\somewhere\myscript.vbs"
msgbox "Creating connection object"
Dim tdc
Set tdc = CreateObject("TDApiOle80.TDConnection")
msgbox "Connecting to QC/ALM"
tdc.InitConnectionEx "http://<yourServer>/qcbin/"
msgbox "Logging in"
tdc.Login "<username>", "<password>"
Dim projDesc
msgbox "Getting project descriptors"
Set projectDescriptors = tdc.GetAllVisibleProjectDescriptors
For Each desc In projectDescriptors
msgbox desc.DomainName & "\" & desc.Name
Next
msgbox "Logging out"
tdc.Logout
msgbox "Disconnecting"
tdc.Disconnect
msgbox "Releasing connection"
tdc.ReleaseConnection
Edit 2:
If you want to parse the resulting XML from sa.GetAllDomains into a list of ALL domain\project items on the server you can do this (This is VBScript since the original question & tag still mention it, and has been tested):
Set objDoc = CreateObject("MSXML.DOMDocument")
objDoc.Load "C:\yourXmlFile.xml"
Set objRoot = objDoc.documentElement
For Each domain in objRoot.selectNodes("TDXItem")
For Each project in domain.selectNodes("PROJECTS_LIST/TDXItem")
msgbox domain.selectSingleNode("DOMAIN_NAME").text & "\" & project.selectSingleNode("PROJECT_NAME").text
Next
Next
I've been looking for a way to get Active Directory's LDAP server url from code running as domain user. The code needs to work correctly in situation with disjoint namespace, if possible. It's unmanaged code so any .NET solutions are not an option unfortunately.
For some reason serverless binding doesn't seem to be working in this case with ADO query returning unhelpful One or more errors occurred during processing of command error when using LDAP://DC=mycompany,DC=local (that's the value of the defaultNamingContext attribute of rootDSE object).
Using the LOGONSERVER and USERDNSDOMAIN environment variables doesn't appear to be an option either because the code also needs to be able to run under the SYSTEM account and there are no such variables there.
Any ideas or hints or specific RTFM advice will be much appreciated.
Update: The DNSHostName attribute of rootDSE seems to be what I need.
I use this Visual Basic Script (VBS). Save the code as .vbs file and use ANSI charset. This script is old, but this can guide you to a better solution.
Set cn = CreateObject("ADODB.Connection")
Set cmd= CreateObject("ADODB.Command")
cn.Provider = "ADsDSOObject;"
cn.open
cmd.ActiveConnection = cn
' Root DSE required to get the default configuration naming context to
' be used as the root of the seach
set objRootDSE = getobject("LDAP://RootDSE")
' Construct the LDAP query that will find all the domain controllers
' in the domain
ldapQuery = "<LDAP://" & objRootDSE.Get("ConfigurationNamingContext") & _
">;((objectClass=nTDSDSA));ADsPath;subtree"
cmd.CommandText = ldapQuery
cmd.Properties("Page Size") = 1000
Set rs = cmd.Execute
do while rs.EOF <> True and rs.BOF <> True
' Bind to the domain controller computer object
' (This is the parent object of the result from the query)
set objDC = getobject(getobject(rs(0)).Parent)
wscript.echo objDC.dNSHostName
rs.MoveNext
Loop
cn.close
The DNSHostName attribute of rootDSE seems to be what I need.
I really don't know much about VB script, and I could use some help with this little problem.
I'm trying send an email once a certain script is run every morning (a scheduled task). Now, our email server is configured to prevent sending automated emails - a feature I generally appreciate - and so I need to simulate a keystroke to acknowledge a warning box and actually send the email.
Here's the script I have so far:
Sub SendEmail_Outlook()
Set WshShell = WScript.CreateObject("WScript.Shell")
Set ol=CreateObject("Outlook.Application")
Set Mail=ol.CreateItem(0)
Mail.to= "X#xyz.com"
Mail.Subject = "Subject"
Mail.HTMLBody = "Body"
Mail.Display
WScript.Sleep 1000
WshShell.SendKeys "%s"
Set Mail = Nothing
Set ol = Nothing
End Sub
SendEmail_Outlook
The script works like a charm, but only if I'm logged in. If I'm not logged in, the email draft is prepared, the window is activated, but the email is not actually sent. I'm assuming it's because the simulated keystroke does not work if no one's logged in?
So, the question is: is there a way to "tweak" this script to make it run even when no one's logged in?
Many thanks, help would be appreciated!
Philipp
Did you check the vbscript [info] section? It explains how cscript.exe can execute vbscript while the user is not logged on.
"Note: Scheduled VBScript tasks succeed under Cscript.exe due to running the script as a console application rather than a windows application. Computer/Domain policies limit activation of windows applications while no user is logged on."
Edit:
Activate the sending of email over the .Send property rather than using the sendkeys method.
Sub SendEmail_Outlook()
Set WshShell = WScript.CreateObject("WScript.Shell")
Set ol=CreateObject("Outlook.Application")
Set Mail=ol.CreateItem(0)
Mail.to= "X#xyz.com"
Mail.Subject = "Subject"
Mail.HTMLBody = "Body"
Mail.Display
WScript.Sleep 1000
'-----------
Mail.Send
'-----------
Set Mail = Nothing
Set ol = Nothing
End Sub
SendEmail_Outlook
Further information on automating emails directly too the outlook application can be referenced here: Link
With the help of a colleague, I think I found the answer - at least it's an option I've implemented and it seems to run successfully so far. As this may be of interest to others as well, there's what we have done:
Download and install "Outlook Redemption" here: http://www.dimastr.com/redemption/home.htm. No admin rights required.
Use the following script:
Sub SendEmail_Outlook()
Set WshShell = WScript.CreateObject("WScript.Shell")
Set oApp=CreateObject("Outlook.Application")
Set NS = oApp.GetNamespace("MAPI")
NS.Logon
Set SafeItem = CreateObject("Redemption.SafeMailItem")
Set oMailItem = oApp.CreateItem(0)
SafeItem.Item = oMailItem
SafeItem.To = "x#yz.com"
SafeItem.Subject = "Subject"
SafeItem.BodyFormat = 2
SafeItem.HTMLBody = "Body"
SafeItem.Send
SafeItem = Nothing
Set oMailItem = Nothing
Set NS = Nothing
Set oApp = Nothing
End Sub
SendEmail_Outlook
As indicated, the script has been running smoothly, despite getting an error at the end, saying that:
VBScript runtime error: Object variable not set: 'SafeItem'
But, the email arrives, so the error doesn't really bother me... ;-)