VB6 code to find windows OS version - windows

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

Related

How to list all Bluetooth devices in Visual Basic (vb.net) on WINDOWS

I am getting so mad at trying to find out a working example. YES, I am new to VB.Net. I was used with VB6, long way back. I just cannot get that thing to do what I want.
My project: I am totally tired of using Steam and other 3rd party apps that require pairing and very hard or long configurations to emulate an XBox controller from a non-Xinput controller. I baught a RegeMoudal Pro Controller and OF COURSE, Windows does NOT read any button entries and I need to use a third party app. The problem with the apps is that they require too much configuration. I just want to transfer the controller's input into a Windows detectable input, that's it.
So, since I cannot go in FASM to do such a complexe project without breaking my head everywhere, I chose to go with the easy way, old school. I spent 2 days just figuring out that I had to reference UWP and a bunch of other things. Now, I said to myself, if I only get AT LEAST the list of devices connected on Bluetooth, I'll be able to start somewhere but nope. No matter what I find, noone has any Visual Basic codes to use in a clean way asside from very complexe code I barely understand.
Can someone please help me AT LEAST find out HOW to list all devices on Bluetooth. I do not care if they are connected or not, I just want to list the devices.
Here is what I got. A simple form with 1 single button and 1 single Label. I know, this just has a bunch of errors.
Imports Windows.Devices.Bluetooth
Imports Windows.Devices.Enumeration
Public Class FrmMain
Private Sub BouGetdev_Click(sender As Object, e As EventArgs) Handles BouGetDev.Click
Dim odevices = New DevicePicker
Dim odev As DeviceInformation
Dim sdevices As String
sdevices = ""
LabRes.Text = "Searching devices..."
For Each odev In odevices
sdevices = sdevices & Chr(13) & odev.GetType.Name
Next
End Sub
End Class
I just cannot figure out how to make this simple task so a gentle help would be nice.
I got discouraged because Windows does NOT capture any input of my controller detected as a Bluetooth Pro Controller but a simple webpage does capture every single input so I am annoyed because I was waiting for this controller since a long time because the XBOX ONE controller had serious joystick issues and made me rage quit games because the joystick would give small taps backwards when releasing it so those Xbox controllers are now on my blacklist because even when Microsoft sent it back to me, it had the exact same issue so I got a refund.
Now, I want to create my own version of Pro Controller to Xbox Controller input app. And I am insisting, Visual Basic code, not C++ or C#. And this is for WINDOWS, not android or any other systems. And refering to Microsoft's website to help does not either help because they give no samples in Visual Basic and I just don't understand the language they are using to explain everything, I'm just a simple person, oh, and the samples that can be taken need to be downloaded as project. I just want a sample code available neatly and easily without downloading anything.
So, after fideling so much with VB and trying to search. I finally found out how to list Bluetooth devices in Visual Basic (VB.Net).
FIRST of all, you NEED 32Feet.Net. I ran into the NuGet problem. I have absolutely NO clue what that is. After searching, I found out that nuGet packages can simply be unzipped using 7zip or other similar app. So here are the steps you need to do to prepare Visual Basic aka VB.Net to work with Bluetooth devices.
Go to 32Feet.Net's GitHub page here: https://github.com/inthehand/32feet
Download the "InTheHand.Net.Bluetooth - Bluetooth Classic" nuget package
Unzip the "nupkg" file in a folder of your choice
Open VB.Net
Navigate in the menus to "Project\Add a project reference..."
Click on the "Browse" button at the bottom of the project reference window
Browse in your newly downloaded and unziped nuget package folder under this path "runtimes\win\lib\netcoreapp#.#" and select the DLL "InTheHand.Net.Bluetooth.dll"
NOW you will be able to use the bluetooth functions. Next, we need to import the functions so they can be available when you code so you need to put this line at the very beginning of your project:
Imports InTheHand.Net.Sockets
Now that this is done, you can list you bluetooth devices. I will explain how I did my sample window. I put 1 button, 1 label and 1 timer object. When changing a label following the mentionned solution above with "Application.DoEvents()" My label still did not change text. So I used an old VB6 trick with a timer. I simply disable a timer object and when clicking on the button, I enable this timer which performs the actions I want. 1 VERY and excessively IMPORTANT thing, once you have started your timer actions, immediately disable your timer before performing any tasks inside this timer or else your function will repeat at the speed of your timer ticks.
So this is my complete code which lists the names of the Bluetooth devices on y computer in Visual Basic (VB.Net).
Imports InTheHand.Net.Sockets
Public Class FrmMain
Private Sub BouGetdev_Click(sender As Object, e As EventArgs) Handles BouGetDev.Click
LabRes.Text = "Searching devices..."
TmrBTScan.Enabled = True
BouGetDev.Enabled = False
End Sub
Private Sub TmrBTScan_Tick(sender As Object, e As EventArgs) Handles TmrBTScan.Tick
Dim bt_client As BluetoothClient = New BluetoothClient()
Dim odevices As BluetoothDeviceInfo() = bt_client.DiscoverDevices().ToArray()
Dim odev As BluetoothDeviceInfo
Dim sdevices As String = ""
Dim schr = ""
TmrBTScan.Enabled = False
For Each odev In odevices
sdevices = sdevices & schr & odev.DeviceName
schr = Chr(10) & Chr(13)
Next
LabRes.Text = sdevices
BouGetDev.Enabled = True
End Sub
End Class
This should list the names of all the Bluetooth devices. At least, it worked on my end and I hope this can help others that are looking for very clear steps in what to download, what to install, what to get, where to navigate, which files and what lines to code. It really is hard to get full complete instructions so I hope this helps.
Thanks for those that helped me here. I had to do some deep search, but at least I can get started on my project now.
First please fix this bug
The button_Click Event runs on the UI thread.
LabRes.Text = "Searching devices..."
the user will not see this text until the method finnished.
add this
LabRes.Text = "Searching devices..."
application.doevents()
It allows the UI to update while running code.
To get bluetooth devices in range
Private Sub SurroundingSub()
Dim client As BluetoothClient = New BluetoothClient()
Dim items As List(Of String) = New List(Of String)()
Dim devices As BluetoothDeviceInfo() = client.DiscoverDevicesInRange()
For Each d As BluetoothDeviceInfo In devices
items.Add(d.DeviceName)
Next
End Sub

Start Outlook 2016 (64 Bit) automatically minimised to Windows 10 (64 Bit) system tray - No active Explorer object found

I have an issue with an auto start of Outlook 2016 at boot/log on which is intended to start Outlook minimised to the Windows system tray, such that once invoked at Windows 10 launch mail will be collected by the mail account(s) (NB. All POP in this case.) whilst the program resides in the system tray remaining invisible until required by the user.
The .vbs script below does function as required but much of the time it introduces two unwelcome issues.
The Outlook icon in the System Tray displays a 'cog' overlay with the message "Another program is using Outlook. To disconnect programs and exit Outlook, click the Outlook icon and then click Exit Now".
Attempts to open Outlook from the 'Open Outlook' context menu (right click Outlook icon in the tray) item causes a dialogue box to appear reporting "No active explorer object found". Clicking the "OK" option in response launches Outlook (though issue 1 - cog overlay) remains.
Neither issue is present when Outlook is started normally from the desktop so it would appear that the .vbs script is in someway responsible. I have used this script successfully (see also below: https://superuser.com/questions/467809/start-outlook-automatically-in-tray) in the past both as a startup menu shortcut and a hkcu 'run' registry entry.
Can anyone suggest the cause or alternately a suitable code revision to achieve correct function? In case it is significant, Windows 10 is 64 bit Pro and the version of Office (including Outlook) installed is also 64 bit.
This is the code invoked by the .vbs script:
OPTION EXPLICIT
OPTION EXPLICIT
CONST PATH_TO_OUTLOOK = """C:\Program Files\Microsoft Office\Office16\OUTLOOK.EXE"""
CONST SHOW_MAXIMIZED = 3
CONST MINIMIZE = 1
DIM shell, outlook
SET shell = WScript.CreateObject("WScript.Shell")
' Open Outlook
shell.Run PATH_TO_OUTLOOK, SHOW_MAXIMIZED, FALSE
ON ERROR RESUME NEXT
' Grab a handle to the Outlook Application and minimize
SET outlook = WScript.CreateObject("Outlook.Application")
WScript.Sleep(100)
outlook.ActiveExplorer.WindowState = SHOW_MAXIMIZED
' Loop on error to account for slow startup in which case the
' process and/or the main Outlook window is not available
WHILE Err.Number <> 0
Err.Clear
WScript.Sleep(100)
SET outlook = NOTHING
SET outlook = WScript.CreateObject("Outlook.Application")
outlook.ActiveExplorer.WindowState = MINIMIZE
WEND
ON ERROR GOTO 0
SET outlook = NOTHING
SET shell = NOTHING
Having spent a number of hours on this issue over the weekend I thought that I had resolved the issues and got everything functioning as intended.
Working from similar samples of code I compiled a new script (see below) which I applied both as a shortcut in the Startup folder and also as an entry into the 'run' branch of the HKCU registry.
Now for the issue! Testing the script on two separate Windows 10 Pro (both 64 Bit architecture) systems both with Outlook 2016 64 Bit installed as part of a 64 Bit Office suite I found that whereas on one system the script runs flawlessly on the other I receive the following runtime error:
Script: D:\Neil's Files\Neil's Filing Cabinet\Neil's Emails\Start Outlook Minimised to Tray\Start Outlook 2016 Minimised To Tray.vbs
Line: 11
Char: 5
Error: ActiveX component can't create object: 'GetObject'
Code: 800A01AD
Source: Microsoft VBScript runtime error
This has me perplexed as the script file and it's related shortcut are both physical copies of each other given that the revised script below contains no path references (as these are handled directly by the code in respect of Outlook.exe) which are identified by the placement of either the shortcut or as the data element of the registry string whichever format is used.
The Systems do have some differences however and for comparative purposes I will summarise those I feel to be relevant here:
System 1: (The problem system) is an X58 Asus P6T7, Intel i720 mature PC with many programs installed and specifically the Outlook 2016 has the same 12 addins installed but in addition has two related programs which launch at boot, the enterprise editions of 4team's Sync2 for Microsoft Outlook and Safe PST Backup. The boot times are quite lengthy (but acceptable) as is the Outlook Startup with it's various addins.
System 2: Is a current generation Asus X99-Deluxe, i7 5930 new build pc with little installed as yet save MS Office, Adobe CC and some utilities.
In the case of System 1, Outlook auto-starts as intended however during it's loading splash screen (whilst it is loading up the addins) the runtime error is displayed although Outlook continues to open fully but fails to minimise.....
This suggests to me that the faulting code is the section which activates the window however the above error message refers to "ActiveX component can't create object: 'GetObject'" which suggests instead an issue with the code line "Set OLObj = GetObject("","Outlook.Application")"??
Hopefully somebody can test the code on a similar setup and report back? Or alternately, give me a pointer as to what is going on and how I might resolve it. I would of course also welcome any suggested improvements to the code!
** Quick Update ** Now tested on HP Elitebook 8440P Laptop - Windows 10 Pro 64 Bit with Office 64 Bit + same 12 Outlook Addons - Functions as intended.....
** Further Update ** Tested on a second HP Elitebook 8440P Laptop - Windows 10 Pro 64 Bit with Office 64 Bit + same 12 Outlook Addons - Above RunTime error experienced once again.......struggling to comprehend why these results are occurring?? Any thoughts anybody???
The code below is offered "as is" for the benefit of anyone else seeking the same Outlook auto start criteria. The testing with System 2 indicates that it works so I hope others enjoy similar success until the outstanding issues are sorted.
NB: To adjust the Outlook Launch Window Size (during its 10 second pause prior to automated minimising) to reflect personal preferences change the numeric value in the following line of code:
WshShell.Run "OUTLOOK.EXE" , 3, false
For a maximised window size change the value to 3 For a restored window size change the value to 2
OPTION EXPLICIT
Dim WshShell
Dim OLObj
Set WshShell = WScript. CreateObject ( "Wscript.Shell" )
'Open Outlook: Note that inspite of the launch options, it will open the program in a normal window.
'The file location path is not necessary as Windows 10 correctly identifies Outlook's location.
WshShell.Run "OUTLOOK.EXE" , 3, false
'This will mimimise it to the system tray after a 10 second pause to allow for mail collection on Outlook launch.
WScript.Sleep (10000)
Set OLObj = GetObject("","Outlook.Application")
'Activates the window
OLObj.ActiveExplorer.Activate
'Sends the command to minimise
OLObj.ActiveExplorer.WindowState = 1
'Outlook does not immediately minimise to the system tray so that 'Send/Receive' can initiate mail collection.
Thanks to jrv from Microsoft's "The Scripting Guys" forum who kindly offered a revised (simplified) code which is below. I can report that as with the original code it works flawlessly on the same 2 systems as before, whilst faulting once more on the other two......very much perplexed!!
The Runtime Error:
Script: D:\Neil's Files\Neil's Filing Cabinet\Neil's Emails\Start Outlook Minimised to Tray\Start Outlook 2016 Minimised To Tray.vbs
Line: 3
Char: 5
Error: ActiveX component can't create object: 'Outlook.Application'
Code: 800A01AD
Source: Microsoft VBScript runtime error
The revised code:
Set WshShell = CreateObject ( "Wscript.Shell" )
WshShell.Run "OUTLOOK.EXE" , 3, False
Set ol = CreateObject("Outlook.Application")
ol.ActiveExplorer.Activate
ol.ActiveExplorer.WindowState = 1
You can use like file *.reg:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
"Outlook"="C:\\Windows\\system32\\cmd.exe /c \"start \"\" /min \"C:\\Program Files\\Microsoft Office\\Office16\\OUTLOOK.EXE\"\""
[HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Preferences]
"MinToTray"=dword:00000001
I have an answer that works well with Office 2013 on Windows 7, and I hope it works for you too.
Essentially, this solution bypasses the issue with trying to force Outlook to minimize after loading. Instead, it relies on using a shortcut that's already configured to load the program in a minimized state.
Copy a shortcut to Outlook into the directory containing your script.
Right click the shortcut and open Properties.
In the Shortcut tab, change the Run mode to Minimized. Press OK.
Then, all you need to do in your VBScript file is to execute the shortcut like so:
Dim sh : Set sh = CreateObject("WScript.Shell")
sh.run "Outlook.lnk"
Note that because this solution uses a shortcut, you could potentially remove the VBScript part entirely by putting the shortcut into the All Users Startup folder.
It's me again! I have an answer that should bypass any issues with VBScript by using third-party software, DisplayFusion. I don't know how you'll feel about that, but I tested it and it works over here. I use this at home and at work to manage multiple monitors and various other things. It may even help solve problems with other programs you use and render various VBS hacks redundant.
In your case, there is a feature called 'Triggers'. Note that while there is a free version of DF, you'll have to activate a 30 day trial for the Pro version to use Triggers, and after that, it's up to you to decide if it's worth your while.
Firstly, after installing DF, you'll want to open up its settings window (right-click desktop and go to DisplayFusion > Settings).
Go to the Triggers tab and click Add.
Set up the trigger for when a window is created. Tell the trigger to activate only once per process ID so it won't also try to minimize subsequent windows, such as when composing a new email. Find the path to your outlook.exe. Then, add an action on the right-hand side to minimize the window.
Click OK twice and then see if it works by loading Outlook. For me, the splash screen appears as normal, then the main window is minimized as soon as it appears.
DF runs as a system service with admin privileges and has been tested with tonnes of software packages, so if this method also fails for you, it could indicate bigger issues with your system/Office configuration.

How can I programatically tell what Outlook addins are installed, and if they are enabled or not?

How do I determine what Outlook COM or PIA addins are installed, and if they are enabled or not.
How can I get this information, and hopefully the file version as well?
(1) If you want to access this information from inside another Outlook Add-in, you may use the the Application.ComAddins object (e.g. it's Count property gives you the number of add-ins installed). You can loop through this collection and check the LoadBehaviour property of the single COMAddin object to now if they're loading or if they're disabled.
(2) If you wand to access the information from outside of Outlook, you may consider to read the appropriate registry entries under the Software\Microsoft\Office\Outlook\Addins key.
(3) Please be aware that you cannot trust this information at all, because Office add-ins can be installed either for a single user or for all users. So you cannot access the installed add-ins absolutely, but only for the current user running your app /your procedure, by reading the abovementioned key (a) under HKLM and (b) under HKCU. The Application.COMAddins object shows you both information blended in one.
(4) I don't recall that a version number is available either in the COMAddin object or in the registry. To access that, you'll have to read the registry to find the file or assembly of the add-in, and access the file version. Please note that "old" COM Add-ins written in Visual Basic 6 or another language have other registry entries than VSTO add-ins or add-ins based on the Add-in Express tool.
To determine which installed add-ins are active (enabled/loaded):
'Loop through all installed add-ins and show whether they are active or not.
Dim app As New Outlook.Application
Dim name As String
Dim loaded As Boolean
For i = 1 To app.COMAddIns.Count
name = app.COMAddIns.Item(i).Description
loaded = app.COMAddIns.Item(i).Connect 'Returns True for active, False for inactive
MsgBox(name & ": " & loaded)
Next
To check the status of a specific add-in by name:
Dim app As New Outlook.Application
Dim addinName As String = "ADD-IN NAME"
Dim loaded As Boolean = app.COMAddIns.Item(addinName).Connect
MsgBox(addinName & ": " & loaded)
You can access that information even from outside of outlook.
Dim count As Integer
Dim app As New Outlook.Application
count = app.COMAddIns.Count
For i = 1 To count
MsgBox(app.COMAddIns.Item(0).Description)
Next

Is there any serial communication software for VB 6.0,?

I am compiling a VB 6 code which requires serial communication from ports. For performing serial communication, I need some software tool like SAX Commstudio Active X or MSComm.ocx. But the problem is I have downloaded Sax Commstudio Active X from the commstudio official website, but that was a trial version for 1 day only. then i tried to download the same software from
http://visualstudiogallery.msdn.microsoft.com/en-us/
But the link is unavailable.
Now I am really in a fix how to get any of the serial communication software which is compatiable with VB 6 code. It will be better if some one provide me the sax commstudio download link or nay serial communication software downalod link!
Regards
Asad
Adding the VB6 MSComm Control to your Toolbar
In the VB6 IDE, select menu item Project, then select Components. The Components dialog box will appear. On this dialog, in the Controls tab, check the box next to the item 'Microsoft Comm Control 6.0' and then click the OK button on the dialog. This will add the component to your toolbar.
It's been a while since I've used this control but maybe this article will help you get started:
Visual Basic: MSComm Control
If you Google mscomm you'll find many more articles.
add the mscomm control in the components tab : Project - Components - Microsoft Comm Control 6.0
then add the control to your form and use the following code to configure and open it :
with mscomm1
.settings = "9600,N,8,1"
.commport = 1
.portopen = true
end with 'mscomm1
to send something :
mscomm1.output = "output to send"
use the oncomm event to receive data :
private sub mscomm1_oncomm()
dim strinput as string
select case mscomm1.commevent
case comevreceive
strinput = mscomm1.input
processdata strinput 'process the data here
end select
end sub
(code is unchecked, just typed in, but i think it should work :))

XP Look-and-feel for VB6 Outlook Property Page?

I am writing a PropertyPage for Outlook using VB6. This is implemented as a VB6 OCX.
When running in a newer version of Outlook (like 2007) on XP (or newer), my dialog looks weird because it doesn't have XP look and feel. Is there a way to do this?
Preferably without adding a manifest file for Outlook.exe.
I think you're right to avoid using a manifest. Unfortunately the standard well-known hacks to support XP themes from VB6 rely on manifests. This MSDN article on developer solutions for Outlook 2007 warns that providing your own manifest for Outlook 2007 might cause it to hang.
I don't think you can do it in VB6 ... those controls are going to look like what they look like. You can, however, create your property pages with Visual Studio .NET and Visual Basic .NET and get the XP, 2007 and Vista look and feel. It's a bit of a change from what you're doing, but you're really behind the times developing with VB6 anyway. More details on how to do that are here and the office developer center.
Not that I know of using VB6
If you can use .NET instead - one way is WPF. I saw earlier an example on code-project.
Here's the link
Edit: And another tool to assist here
This is what I do in all of my VB6 Apps, only ever tested in a standalone EXE so not sure if it will work as an OCX.
Private Type tagInitCommonControlsEx
lngSize As Long
lngICC As Long
End Type
Private Declare Function InitCommonControlsEx Lib "comctl32.dll" _
(iccex As tagInitCommonControlsEx) As Boolean
Private Const ICC_USEREX_CLASSES = &H200
Public Function InitCommonControlsVB() As Boolean
On Error Resume Next
Dim iccex As tagInitCommonControlsEx
' Ensure CC available:
With iccex
.lngSize = LenB(iccex)
.lngICC = ICC_USEREX_CLASSES
End With
InitCommonControlsEx iccex
InitCommonControlsVB = (Err.Number = 0)
On Error Goto 0
End Function
Public Sub Main()
InitCommonControlsVB
'
' Start your application here:
'
End Sub
Create a file similar to this: http://pastebin.com/f689388b2
Then you add the manifest file to your resource file as type RT_MANIFEST (24)
I can't quite remember if that's all you need to do as I always just use the same pre-made .res file now.
Source: http://www.vbaccelerator.com/home/vb/code/libraries/XP_Visual_Styles/Using_XP_Visual_Styles_in_VB/article.asp

Resources