Results 1 to 2 of 2

Thread: VB.NET: How to restart computer after installation process

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2003
    Location
    Sunnyvale CA
    Posts
    15

    VB.NET: How to restart computer after installation process

    Hi, I have a question with VB.NET.

    I've developed an application using VB.NET and now I'm trying to make a setup file for its distribution process. I am using the built-in program (MSI) to do the task.

    How do I make this setup project restart computer when the main application is installed?

    Thanks in advance!
    Eric.
    What is finite, but boundaryless?

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Since a class for restarting the computer has not been included in the .Net framework yet... you simply need to call Win32 API's from your .Net applicaton....

    do a Google search for Restart Computer in VB6 to get the right API's.... I believe its ExitWindowsEx..... (bear in mind, for XP and 2000, you also need to pass a security parameter, but most of the code I've seen around handles that)...

    Then, you need to call the API from your .Net application..just like you would with VB6, just remember Longs in Vb6 are now Integers in VB.Net... so you need to replace any Long returned by a Win32API with Integer...
    VB Code:
    1. [u]vb6:[/u]
    2.  
    3. Private Declare Auto Function MBox Lib "user32.dll" _
    4. Alias "MessageBox" (ByVal hWnd As [b]Long[/b], _
    5.    ByVal txt As String, ByVal caption As String, _
    6.    ByVal Typ As [b]Long[/b]) As [b]Long[/b]
    7.  
    8. [u]vb.Net:[/u]
    9.  
    10. Private Declare Auto Function MBox Lib "user32.dll" _
    11. Alias "MessageBox" (ByVal hWnd As [b]Integer[/b], _
    12.    ByVal txt As String, ByVal caption As String, _
    13.    ByVal Typ As [b]Integer[/b]) As [b]Integer[/b]

    There are also other ways to call Win32API's but the above is the simplest.... for other ways you may refer to this MSDN walkthrough:
    http://msdn.microsoft.com/library/de...indowsAPIs.asp

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width