|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Unbelieveable code, it produces one result in VB6 run and another if compiled in a exe file ???? Whacompiled in a exe file ???? What gives ??? Simply put this code in a single Form (i.e. Form1), make a text1 text box and run it (it is supposed to give a HDD serial number - I need to findout the HDD serial number in my software).... Option Explicit Private Sub Form_Load() Dim arrComputers() As String Dim strComputer As Variant Dim objWMIService As Object Dim colItems As Object Dim objItem As Object Const wbemFlagReturnImmediately = &H10 Const wbemFlagForwardOnly = &H20 Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2") Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PhysicalMedia", "WQL", _ wbemFlagReturnImmediately + wbemFlagForwardOnly) Text1.Text = "" For Each objItem In colItems Text1.Text = Text1.Text & vbCrLf & Trim(objItem.SerialNumber) Next End Sub Just ran the code in VB6 SP5 on WinXP Pro.
From IDE and also from the created EXE I get the exact same serial number. Robert Show quoteHide quote "viglen" <AlexandriaSupp***@gmail.com> wrote in message news:95dc2ff2-0222-4c71-8fc0-3ed24d106b7b@y38g2000prg.googlegroups.com... > Unbelieveable code, it produces one result in VB6 run and another if > compiled in a exe file ???? What gives ??? > > Simply put this code in a single Form (i.e. Form1), make a text1 text > box and run it (it is supposed to give a HDD serial number - I need to > findout the HDD serial number in my software).... > > Option Explicit > > Private Sub Form_Load() > > Dim arrComputers() As String > Dim strComputer As Variant > Dim objWMIService As Object > Dim colItems As Object > Dim objItem As Object > Const wbemFlagReturnImmediately = &H10 > Const wbemFlagForwardOnly = &H20 > > Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2") > Set colItems = objWMIService.ExecQuery("SELECT * FROM > Win32_PhysicalMedia", "WQL", _ > wbemFlagReturnImmediately + > wbemFlagForwardOnly) > Text1.Text = "" > > For Each objItem In colItems > Text1.Text = Text1.Text & vbCrLf & Trim(objItem.SerialNumber) > Next > > End Sub
Show quote
Hide quote
On Feb 14, 10:18 pm, "Robert" <rob***@nowhere.com> wrote: I dont get it, how come I don't.> Just ran the code in VB6 SP5 on WinXP Pro. > > From IDE and also from the created EXE > > I get the exact same serial number. > > Robert > > "viglen" <AlexandriaSupp***@gmail.com> wrote in message > > news:95dc2ff2-0222-4c71-8fc0-3ed24d106b7b@y38g2000prg.googlegroups.com... > > > > >Unbelieveable code, it produces one result in VB6 run and another if> compiled in a exe file???? What gives ??? > > > Simply put this code in a single Form (i.e. Form1), make a text1 text > > box and run it (it is supposed to give a HDD serial number - I need to > > findout the HDD serial number in my software).... > > > Option Explicit > > > Private Sub Form_Load() > > > Dim arrComputers() As String > > Dim strComputer As Variant > > Dim objWMIService As Object > > Dim colItems As Object > > Dim objItem As Object > > Const wbemFlagReturnImmediately = &H10 > > Const wbemFlagForwardOnly = &H20 > > > Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2") > > Set colItems = objWMIService.ExecQuery("SELECT * FROM > > Win32_PhysicalMedia", "WQL", _ > > wbemFlagReturnImmediately + > > wbemFlagForwardOnly) > > Text1.Text = "" > > > For Each objItem In colItems > > Text1.Text = Text1.Text & vbCrLf & Trim(objItem.SerialNumber) > > Next > > > End Sub- Hide quoted text - > > - Show quoted text - We'll here, let me add the obvious difference is that I run VB6 SP6 and Windows VISTA , could that be it ? But even if it is, why different results at VB runtime and EXE runtime of the same exact code ? Can anyone try this on VISTA (and maybe on VB6 SP6) ? Thank you guys for the attempts to help me. "viglen" <AlexandriaSupp***@gmail.com> wrote in message Can anyone try this on VISTA (and maybe on VB6 SP6) ?news:17d719ea-2013-4ae5-ac2e-b16d0fa775e2@o2g2000prl.googlegroups.com... Try this: strComputer = "." Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Str = "" Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk") For Each objItem In colItems Str = Str & objItem.Name & " SerialNumber: " & objItem.VolumeSerialNumber & vbCrLf & vbCrLf Next MsgBox Str
Show quote
Hide quote
On Feb 15, 1:00 am, "C Kevin Provance" <BillMIsADou***@yyz.net> wrote: Thanks Kevin, but I didn't want the ".VolumeSerialNumber" property,> "viglen" <AlexandriaSupp***@gmail.com> wrote in message > > news:17d719ea-2013-4ae5-ac2e-b16d0fa775e2@o2g2000prl.googlegroups.com... > Can anyone try this on VISTA (and maybe on VB6 SP6) ? > > Try this: > > strComputer = "." > Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" > & strComputer & "\root\cimv2") > Str = "" > Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk") > For Each objItem In colItems > Str = Str & objItem.Name & " SerialNumber: " & objItem.VolumeSerialNumber > & vbCrLf & vbCrLf > Next > MsgBox Str since the volume number, I've been told can be changed by the user, so I cannot use this to uniquely identify a user's PC. I need the .SerialNumber property, which is the HDD's serial number that cannot be changed by the user. Thank you for your suggestion, but I am still looking for someone to help me with the issue of my code giving me two different results in VB run time and in EXE run time. Thank you. Hi,
Sorry I didn't see this post sooner. I use this function in my ApplicationLicenseValidation component for creating 'seat' LicenseKeys for my VB6 apps and my VBA addins. It works reliably and consistent in IDE or runtime on any system from Windows2000 to Vista. (I haven't tried it on any others) It returns the serial number of the vBIOS as the MachineId. I chose this for the very reason you cite below: hard drives can be swapped out. The BIOS is built in to the PC so it persists through the lifetime of the machine. A change here would indicate a new machine (for all practical intents) and since replacing the motherboard is required then it is no longer the same machine (technically) regardless of whether it resides in the same case or not. Function To Get a PC's Serial Number Function GetPC_SerialNo(Optional RemotePcName As String) As String ' Gets the serial number of a PC's BIOS Dim sComputer As String, sImpersonation As String Dim oWMI As Variant Dim vSettings As Variant, vBIOS As Variant If RemotePcName = "" Then sComputer = "." sImpersonation = "impersonate" Else sComputer = RemotePcName 'for remote machine sImpersonation = "impersonate,authenticationLevel=Pkt" End If Set oWMI = GetObject("winmgmts:" _ & "{impersonationLevel=" & sImpersonation & "}!\\" _ & sComputer _ & "\root\cimv2") Set vSettings = oWMI.ExecQuery("Select * from Win32_BIOS") For Each vBIOS In vSettings MsgBox vBIOS.SerialNumber GetPC_SerialNo = vBIOS.SerialNumber Next End Function HTH Kind regards, Garry -- Show quoteHide quote> Thanks Kevin, but I didn't want the ".VolumeSerialNumber" property, > since the volume number, I've been told can be changed by the user, so > I cannot use this to uniquely identify a user's PC. > > I need the .SerialNumber property, which is the HDD's serial number > that cannot be changed by the user.
Pset and SetPixel Bug
How to get special Appdata folder VB6 runtime is supported on Windows 7 What am I doing wrong Use Proc with Static Variables Multiple Times OT MS Community Visibility Legacy vs Opp Vista behaves differently to WordBasic command even though same version of Word! Crash during compile Refresh form so 'not responding' does not appear |
|||||||||||||||||||||||