another anoying vb.net problem

Discussion in 'Application Software' started by Stannieman, Feb 19, 2010.

  1. Stannieman

    Stannieman MDL Guru

    Sep 4, 2009
    2,232
    1,818
    90
    Hi,
    I'm making a program to bypass win7 activation, but I'm having problems with the installer.
    Of course the one who helps me out will see his name in the credits list if it's ever going to be released.
    The error appears when I run the app as admin, a nice jit (just in time debugger) window pops up.
    Some text in the jit error is in dutch, so I translated it to english.
    GraceExtender is a file with no extension.

    error:
    Why can't it acces the file, am I doing something wrong? It looks to me as if it wants to write to the file when the file isn't fully written to the disk yet.

    This error also appears in another app, the same there, it needs to write to a file that is created 1 line above in the vb code.

    Anyone knows what's wrong?
    Thanks
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. FreeStyler

    FreeStyler MDL Guru

    Jun 23, 2007
    3,557
    3,832
    120
    Stan,What are you running X64 / or X32 OS?
    If you run X64 as OS and you compile do not compile the app as x64 app it might be possible \System32\ gets redirected to \SysWow64\

    Have had this issue l while back, maybe it is related, maybe its not... but worth to try, isn't?
     
  3. Stannieman

    Stannieman MDL Guru

    Sep 4, 2009
    2,232
    1,818
    90
    No I'm running 32bit, and even on x64 the system32 folder contains the x64 files and the syswow64 folder contains the 32bit files.
    And that shouldn't make a difference anyway I think.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    #4 MasterDisaster, Feb 21, 2010
    Last edited by a moderator: Apr 20, 2017
    Just use this line

    Code:
    System.IO.File.WriteAllText(strSystem32 & "\GraceExtender", strInstallDirectory)
    It will create a new file and put all the text into the file and close it.

    The problem with your code is, when you use the line below

    Code:
    System.IO.File.Create(strSystem32 & "\GraceExtender")
    it creates a new handle for the file and does not close it, so the next line fails because the file is already in use.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. Hazar

    Hazar MDL Guru

    Jul 29, 2009
    2,507
    456
    90
    You'd be best off just making the text file and pack it as a resource and use

    System.IO.File.WriteAllBytes(path, resourcename)
     
  6. kdo2milger

    kdo2milger MDL Senior Member

    Jan 5, 2010
    371
    25
    10
    in for updates.
     
  7. Stannieman

    Stannieman MDL Guru

    Sep 4, 2009
    2,232
    1,818
    90
    But the file has to stay on the users hdd, when he runs the app another time I need to read it again, can dat be done with a recourse?

    And now I have this line only:
    System.IO.File.WriteAllText(strSystem32 & "\GraceExtender", strInstallDirectory)
    but it says "file not found", when I look at it however all is written correctly as it should be.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. Stannieman

    Stannieman MDL Guru

    Sep 4, 2009
    2,232
    1,818
    90
    You know, I'll just put the info in the registry instead of in a file, that's the easiest.
    But thanks though.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. Stannieman

    Stannieman MDL Guru

    Sep 4, 2009
    2,232
    1,818
    90
    #9 Stannieman, Feb 24, 2010
    Last edited: Feb 24, 2010
    (OP)
    Grrr, now I've another problem:
    How can I get a registryvalue into an integer?
    I think I should use dword then? I need to check if the value in the registry is higher or lower then an other value.

    And does anyone know how to see whether windows is in grace period or not?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  10. Stannieman

    Stannieman MDL Guru

    Sep 4, 2009
    2,232
    1,818
    90
    Please... someone?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    #11 MasterDisaster, Feb 27, 2010
    Last edited by a moderator: Apr 20, 2017
    Code for finding grace period.
    Code:
    Imports System
    Imports System.Management
    Imports System.Windows.Forms
    
    Namespace WMISample
    
        Public Class MyWMIQuery
    
            Public Overloads Shared Function Main() As Integer
    
                Try
                    Dim searcher As New ManagementObjectSearcher( _
                        "root\CIMV2", _
                        "SELECT * FROM SoftwareLicensingProduct") 
    
                    For Each queryObj As ManagementObject in searcher.Get()
    
                        Console.WriteLine("-----------------------------------")
                        Console.WriteLine("SoftwareLicensingProduct instance")
                        Console.WriteLine("-----------------------------------")
                        Console.WriteLine("GracePeriodRemaining: {0}", queryObj("GracePeriodRemaining"))
                    Next
                Catch err As ManagementException
                    MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
                End Try
            End Function
        End Class
    End Namespace
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  12. Stannieman

    Stannieman MDL Guru

    Sep 4, 2009
    2,232
    1,818
    90
    #12 Stannieman, Feb 27, 2010
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Sorry but I can't get this working, I'm a newbe in programming :eek:
    It gives lot's of errors, but you can just give all the code (every word you can see in visual studio)? Maybe in the form of a console app that just pops up a msgbox that says in grace or not in grace, that would really help me out.

    And how can you see whether windows is activated or showing nagscreens in case the graceperiod is expired?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  13. kdo2milger

    kdo2milger MDL Senior Member

    Jan 5, 2010
    371
    25
    10
    #13 kdo2milger, Feb 27, 2010
    Last edited: Feb 27, 2010
    i cant help you with the integer part but these codes typed into cmd prompt will show you info on the os whether its activated or grace period.

    slmgr -dli
    slmgr -xpr
    slmgr -dlv
     
  14. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    #15 MasterDisaster, Feb 27, 2010
    Last edited by a moderator: Apr 20, 2017
    First you need to understand how WMI query woks.
    Add reference to System.Management for your project.
    Code:
    Dim searcher As New ManagementObjectSearcher("root\CIMV2", "SELECT * FROM SoftwareLicensingProduct WHERE LicenseStatus > 1") 
    This line queries the SoftwareLicensingProduct class and return an array of ManagementObject which have LicenseStatus greater than 1. Below is the list of values for License Status.
    Code:
    LicenseStatus
    Data type: uint32
    Access type: Read-only
    
    Specifies the license status of this product application. The following values are possible.
    
    ValueDescription
    0Unlicensed
    1Licensed
    2OOBGrace
    3OOTGrace
    4NonGenuineGrace
    5Notification
    6ExtendedGrace
    Code:
     For Each queryObj As ManagementObject in searcher.Get()
        Console.WriteLine("GracePeriodRemaining: {0}", queryObj("GracePeriodRemaining"))
    This line displays the GracePeroidRemaining in minutes.

    You only need to add these three lines to your code and don't forget to add the reference to your project.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  15. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    For getting the registry value, just typecast it into an integer.
    example:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  16. Stannieman

    Stannieman MDL Guru

    Sep 4, 2009
    2,232
    1,818
    90
    OK I understand how it works, but it gives 2 errors:
    type ManagementObjectSearcher is not defined
    type ManagementObjectSearcher is not defined

    I did add these 3 lines, they are above the public class 'myform'
    Imports System
    Imports System.Management
    Imports System.Windows.Forms
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  17. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    #18 MasterDisaster, Feb 28, 2010
    Last edited by a moderator: Apr 20, 2017
    Goto Project -> Add Reference, select System.Management.
    This is what i have in my source,
    Code:
    Imports System.Management
    Module Module1
        Sub Main()
            Dim searcher As New ManagementObjectSearcher("root\CIMV2", "SELECT * FROM SoftwareLicensingProduct WHERE LicenseStatus > 1")
            For Each queryObj As ManagementObject In searcher.Get()
                Console.WriteLine("GracePeriodRemaining: {0}", queryObj("GracePeriodRemaining"))
            Next queryObj
        End Sub
    End Module
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  18. Stannieman

    Stannieman MDL Guru

    Sep 4, 2009
    2,232
    1,818
    90
    OK thanks a lot!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  19. Stannieman

    Stannieman MDL Guru

    Sep 4, 2009
    2,232
    1,818
    90
    #20 Stannieman, Mar 1, 2010
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...