VBScript: Assigning an array(2) via createobject - vb6

I'm having a problem converting this VB6 code to VBScript. I'm calling out to a COM object to create an array as EmailAddressType. Here is the working VB6 Code:
'Assign TO: addresses
Dim toAdresses(2) As New EmailAddressType
toAdresses(0).EmailAddress = "someone#whocares.com"
toAdresses(0).RoutingType = "SMTP"
toAdresses(1).EmailAddress = "someoneelse#whocares.com"
toAdresses(1).RoutingType = "SMTP"
email.ToRecipients = toAdresses
I can't seem to figure out how to convert this into VBScript. I've tried the following but just get a Type Mismatch error once I get to the email.ToRecipients = toAdresses
'Assign TO: addresses
dim toAdresses(2)
set toAdresses(0) = createobject("EWS.EWSWebSvc.EmailAddressType")
set toAdresses(1) = createobject("EWS.EWSWebSvc.EmailAddressType")
toAdresses(0).EmailAddress = "someone#whocares.com"
toAdresses(0).RoutingType = "SMTP"
toAdresses(1).EmailAddress = "someoneelse#whocares.com"
toAdresses(1).RoutingType = "SMTP"
email.ToRecipients = toAdresses
Btw this is a COM wrapper of the Exchange Web Services if that helps any.

I think the problem is that the .ToRecipients property wants an array of EmailAddressType while all you can easily get in VBScript is a Variant or array of Variants.
Looks like this API was just not built to be scriptable.
Oddly enough there is an implication it can be used from JScript though: MessageType.ToRecipients Property
I suspect they are rewriting history by gradually editing out any mention of VBScript on MSDN these days though.

Just a guess, try this
toAdresses.EmailAddress = "someone#whocares.com;someoneelse#whocares.com"
toAdresses.RoutingType = "SMTP"
email.ToRecipients = toAdresses
if it doesn't work with the ; try the ,

Related

How to update an repository object in uft?

I use UFT 11.53, Windows 8.1 Pro et vbscripts.
I've a question : Is it possible to add objects to an object repository automatically using VBScript?
My problem : I've an application in which I've to automate tests and qualifications. I would like to add an new object (using vbscript) to my repository object.
Below is my code which I tried:
Dim RepositoryFrom
Dim ParentObject
ObjectRepositoryPath="D:\repository.tsr"
'Creating Object Repository utility Object
Set RepositoryFrom = CreateObject("Mercury.ObjectRepositoryUtil")
'Load Object Repository
RepositoryFrom.Load ObjectRepositoryPath
Set oWebElement = WebElement(""&str) 'str = "PR1500073LRBA", it's an element of my table
Set ParentObject = Browser("fia").Page("fia_3")
RepositoryFrom.AddObject oWebElement, ParentObject, "reference"
RepositoryFrom.Save
Set RepositoryFrom = nothing
Set oWebElement = nothing
Set oParent = nothing
With this code, I've an message error :
'AddObject' - General error.
Line (63): "RepositoryFrom.AddObject oWebElement, ParentObject, "reference"".
Do you know why I've this message ?
Thanks :)

Classic ASP (VBScript), 2008 R2, error using AD to authenticate

I have moved a web site from Win2003 x32 to Win2008R2 x64. It works fine on the old server. The web site uses active directory to authenticate. I get this error on 2008: -2147023584 : A specified logon session does not exist. It may already have been terminated. I have tried switching to classic mode, etc. with no change. It does execute VBScript code (otherwise I wouldn't get the error).
Here is the code:
Function AuthenticateUser(UserName, Password)
On Error Resume Next
Dim oADsNamespace, oADsObject
Dim strADsNamespace, strADsPath
strADsPath = "WinNT://ibcschools.edu"
strADsNamespace = left(strADsPath, instr(strADsPath, ":"))
Set oADsObject = GetObject(strADsPath)
Set oADsNamespace = GetObject(strADsNamespace)
Set oADsObject = oADsNamespace.OpenDSObject(strADsPath, UserName, Password, 0)
Response.Write(Err.Number & " : " & Err.Description & "<br />")
If Err.Number = 0 Then
Set oADsNamespace = Nothing
Set oADsObject = Nothing
Set strADsNamespace = Nothing
Set strADsPath = Nothing
AuthenticateUser = True
Else
Set oADsNamespace = Nothing
Set oADsObject = Nothing
Set strADsNamespace = Nothing
Set strADsPath = Nothing
AuthenticateUser = False
End If
End Function
Any help would be appreciated. Thanks.
Your problem seems to be related to using WinNT provider with OpenDSObject.
Things you could try:
Replace WinNT with LDAP provider.
Try running your standalone VBS file
under IIS/ApplicationPool user privileges.
Okay, so I got it working. Before it worked without the domain name, but now requires it. I think it has something to do with the app pool logging in on the old server versus this one. I am going to work on it a little more. I don't want to change all the sites.

Setting a VCProject property to default

I'm trying some VS2005 IDE macros to modify a large amount of projects (~80) within a solution. Some of the properties I wish to set do expose a programmatic interface to 'default', but many others do not. Is there a generic way to set such properties to their default? (eventually meaning erasing them from the .vcproj file)
Simplified example, setting some random properties:
Sub SetSomeProps()
Dim prj As VCProject
Dim cfg As VCConfiguration
Dim toolCompiler As VCCLCompilerTool
Dim toolLinker As VCLinkerTool
Dim EnvPrj As EnvDTE.Project
For Each EnvPrj In DTE.Solution.Projects
prj = EnvPrj.Object
cfg = prj.Configurations.Item(1)
toolLinker = cfg.Tools("VCLinkerTool")
If toolLinker IsNot Nothing Then
' Some tool props that expose a *default* interface'
toolLinker.EnableCOMDATFolding = optFoldingType.optFoldingDefault
toolLinker.OptimizeReferences = optRefType.optReferencesDefault
toolLinker.OptimizeForWindows98 = optWin98Type.optWin98Default
End If
toolCompiler = cfg.Tools("VCCLCompilerTool")
If toolCompiler IsNot Nothing Then
' How to set it to default? (*erase* the property from the .vcproj)'
toolCompiler.CallingConvention = callingConventionOption.callConventionCDecl
toolCompiler.WholeProgramOptimization = False
toolCompiler.Detect64BitPortabilityProblems = False
End If
Next
End Sub
Any advice would be appreciated.
For VS 2005, I believe you can use the ClearToolProperty method on VCConfiguration. The following code would accomplish this for CallingConvention (this is C#, but I'm sure something similar works for VB):
cfg.ClearToolProperty( toolCompiler, "CallingConvention" );
This would have the same effect as going into the GUI and choosing "<inherit from parent or project defaults>" for this option.
Unfortunately this seems to be deprecated in VS 2010, and I'm not sure what the new supported method is.

Why is WSH giving me the "expected ;" error?

Im trying to get my feet wet with some WSH. I thought it was going to be easy, but it's really a nightmare...
contents of registry.js >
Set shell = WScript.CreateObject('WScript.Shell');
strRegValue = 'HKLM/Software/Microsoft/Windows/CurrentVersion/ProductID';
strPID = shell.RegRead(strRegValue);
WScript.Echo strPID;
This is a code snippet to read a registry value. Maybe you can see what'
s wrong with it because I sure cant!
how about trying this way:
var shell = WScript.CreateObject('WScript.Shell');
// my version of windows does not have the regkey you initially specified
strRegValue = 'HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\CommonFilesDir';
strPID = shell.RegRead(strRegValue);
WScript.Echo(strPID);

How to connect to LDAP store with VB6

I’ve got a problem with Visual Basic (6) in combination with LDAP. When I try to connect to an LDAP store, I always get errors like ‘Bad Pathname’ or ‘Table does not exist’ (depending on what the code looks like).
This is the part of the code I wrote to connect:
path = "LDAP://xx.xxx.xxx.xxx:xxx/"
Logging.WriteToLogFile "Test1", logINFO
Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ADsDSOObject"
conn.Properties("User ID") = "USER_ID"
conn.Properties("Password") = "PASSWORD"
conn.Properties("Encrypt Password") = True
conn.Properties("ADSI Flag") = 34
Logging.WriteToLogFile "Test2", logINFO
conn.Open "Active Directory Provider"
Logging.WriteToLogFile "Test3", logINFO
Set rs = conn.Execute("<" & path & "ou=Some,ou=Kindof,o=Searchbase>;(objectclass=*);name;subtree")
Logging.WriteToLogFile "Test4", logINFO
The logfile shows “Test1” , “Test2”, “Test3” and then “Table does not exist”, so it’s the line “Set rs = conn.Execute(…)” where things go wrong (pretty obvious…).
In my code, I try to connect in a secure way. I found out it has nothing to do with SSL/certificates though, because it’s also not possible to establish an anonymous unsecured connection. Funny thing is: I wrote a small test app in .NET in five minutes. With that app I was able to connect (anonymously) and read results from the LDAP store, no problems at all.
Does anyone have any experience with the combination LDAP and VB6 and maybe know what could be the problem? I googled and saw some example code snippets, but unfortunately none of them worked (same error messages as result). Thanks in advance!
I'm not sure how much help this will be, but I use this code to access Active Directory objects.
Set oinfo = New ADSystemInfo
sDomain = Split(oinfo.DomainDNSName, ".")
'-- Get Datasets from the Active Directory
'-- Connect to Active Directory in logged in domain
con.Open "Provider=ADsDSOObject;Encrypt Password=False;Integrated Security=SSPI;Data Source=ADSDSOObject;Mode=Read;Bind Flags=0;ADSI Flag=-2147483648"
'-- Query all serviceConnectionPoints in the Active Directory
'-- that contain the keyword "urn://tavis.net/TM/Database"
'-- and return the full path to the object
Set rst = con.Execute("<LDAP://DC=" & sDomain(0) & ",DC=" & sDomain(1) & ">;(&(objectCategory=serviceConnectionPoint)(keywords=urn://tavis.net/TM/Database));Name, AdsPath;subTree")
2 things:
The Open() method call takes additional parameters, server/username/password
The LDAP query you passed to Execute() should be:
"<" & path & "ou=Some/ou=Kindof/o=Searchbase>;(objectclass=*);name;subtree"

Resources