Help with late binding!
Help with late binding!
Help with late binding!
Help with late binding!
Help with late binding!
Help with late binding! Help with late binding! Help with late binding! Help with late binding! Help with late binding! Help with late binding! Help with late binding! Help with late binding!
Help with late binding! Help with late binding!
Help with late binding!
Go Back  Xtreme Visual Basic Talk > > > Help with late binding!


Reply
 
Thread Tools Display Modes
  #1  
Old 05-24-2007, 09:34 AM
Abaillie's Avatar
Abaillie Abaillie is offline
Regular
 
Join Date: Jun 2003
Location: Scotland
Posts: 92
Default Help with late binding!


Hi all,

I got the script below from the Microsoft site to get all installed applications from the reg.

It works fine running it as a .VBS file, but i wanted to dump it in an .NET application!

In doing so, I have hit a problem with late binding! I have read up on the error but i am still stuck.

I have had a look about the forums for an equilivent vb.net solution but nothing like below.

Can anyone help or even point me in the right direction. (Microsoft's explaination just looks like random words they have stuck together!

Any help would be greatly appreciated.

Regards



Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
strComputer = "."
strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
strEntry1a = "DisplayName"
strEntry1b = "QuietDisplayName"
strEntry2 = "InstallDate"
strEntry3 = "VersionMajor"
strEntry4 = "VersionMinor"
strEntry5 = "EstimatedSize"

Set objReg = GetObject("winmgmts://" & strComputer & "/root/default:StdRegProv")
objReg.EnumKey HKLM, strKey, arrSubkeys
listbox1.items.add "Installed Applications" & VbCrLf
For Each strSubkey In arrSubkeys
intRet1 = objReg.GetStringValue(HKLM, strKey & strSubkey, strEntry1a, strValue1)
If intRet1 <> 0 Then
objReg.GetStringValue HKLM, strKey & strSubkey, strEntry1b, strValue1
End If
If strValue1 <> "" Then
listbox1.items.add (VbCrLf & "Display Name: " & strValue1)
End If
objReg.GetStringValue HKLM, strKey & strSubkey, strEntry2, strValue2
If strValue2 <> "" Then
listbox1.items.add ("Install Date: " & strValue2)
End If
objReg.GetDWORDValue HKLM, strKey & strSubkey, strEntry3, intValue3
objReg.GetDWORDValue HKLM, strKey & strSubkey, strEntry4, intValue4
If intValue3 <> "" Then
listbox1.items.add ("Version: " & intValue3 & "." & intValue4)
End If
objReg.GetDWORDValue HKLM, strKey & strSubkey, strEntry5, intValue5
If intValue5 <> "" Then
listbox1.items.add ("Estimated Size: " & Round(intValue5/1024, 3) & " megabytes")
End If
Next
__________________
A Baillie

<Developers and Support will never see eye to eye, until Support learn that without Developers, they would have nothing to Support.>
Reply With Quote
  #2  
Old 05-24-2007, 06:46 PM
MKoslof's Avatar
MKoslofHelp with late binding! MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

You can do exactly the same thing, through the WMI COM library. Or basically there is a managed wrapper for the Windows Management classes you need to use. Look up WMI at MSDN or through Google for tons of examples of how to intergate with .Net.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #3  
Old 05-28-2007, 01:26 AM
W_Garabrandt W_Garabrandt is offline
Centurion
 
Join Date: Mar 2004
Location: Altoona, PA USA
Posts: 139
Default

For those who may stumble on this in the future, Late VS Early binding refers to the method for which one creates an object in an object oriented programming language. If the object is declared OUTSIDE of any sub, function, class, or is otherwise intended to be dealth with at compile time (as opposed to run-time), then it is considered Early binding (the kind most people are familiar with). In LATE Binding, what you are basically trying to do is establish a connection to an API call, DLL, or create a new object at runtime, outside of any debugger's control. Doing this is somewhat dangerous, because sometimes the garbage collector won't be able to bail you out if something goes wrong, and the object could remain instantiated in memory after your program is halted. If you EARLY bind to something, the program will check for it's existance upon running the program BEFORE any of your code gets run, and if it's not there, you get a nasty "Missing file" message. In LATE binding, you MUST check for it yourself (to avoid a nasty runtime error), and if it's not there, you can opt-out of it, or at least let the user know how to fix it.

In the example, your best bet for a solution is to add the control to the project at design time (Early bind), and use it that way (lots safer), or at least attach your program to it properly at run time (Late bind) (which by the way, is why you are getting an error here to begin with). In VBS code, objects are ALWAYS attached late bind, therefore declarations can sometimes be omitted as they are assumed anyway. But in VB.NET, expecially with Option Explicit on, you MUST declare them properly.

To test this out, turn OFF Option Explicit, and Option Strict, and see what happens.
__________________

I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image. - Stephen Hawking
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Help with late binding!
Help with late binding!
Help with late binding! Help with late binding!
Help with late binding!
Help with late binding!
Help with late binding! Help with late binding! Help with late binding! Help with late binding! Help with late binding! Help with late binding! Help with late binding!
Help with late binding!
Help with late binding!
 
Help with late binding!
Help with late binding!
 
-->