Results 1 to 19 of 19

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

  1. #1

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

    VB.NET: How to restart computer after installation process [SOLVED]

    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.
    Last edited by aspade; Apr 20th, 2003 at 07:59 PM.
    What is finite, but boundaryless?

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

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

    Originally posted by aspade
    Hi, I have a question with VB.NET.
    Then post it in the .Net Forum

  3. #3
    Junior Member
    Join Date
    Mar 2003
    Posts
    30
    use sendkeys to send ctrl-alt-del twice. J/K BTW

  4. #4
    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
    Last edited by nemaroller; Apr 17th, 2003 at 10:46 PM.

  5. #5

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

    But...

    But I'm trying to implement this "restarting capability" from the setup. Is there any way to do this using the Setup project?
    What is finite, but boundaryless?

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Yes , using any of those 3rd party tools that pack your proj (I can't remember right now) .There's an option there to force restarting the machine .

  7. #7
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: But...

    Originally posted by aspade
    But I'm trying to implement this "restarting capability" from the setup. Is there any way to do this using the Setup project?
    installshield should have this option... you know, if you can "find" it somewhere it's not that expensive
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  8. #8

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

    Re: Re: But...

    Originally posted by MrPolite
    installshield should have this option... you know, if you can "find" it somewhere it's not that expensive
    Well, the problem is that the licensing fee for the InstallShield is somewhere around 2000 bucks!

    Hmm.. Would implementing a windows service then sending a "command" to it work? Would that be easier to restart the computer without calling API?

    Desperate.
    What is finite, but boundaryless?

  9. #9
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Why are you wanting it to restart? Most of the time .Net apps don't require it. I am just wondering why yours does.

  10. #10
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Re: Re: Re: But...

    What's the the deal if you used APIs in this case ? It's only 3 to 5 lines of code to restart the machine .

  11. #11
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Maybe he's writing some values to the registry

  12. #12

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

    B/C

    Originally posted by hellswraith
    Why are you wanting it to restart? Most of the time .Net apps don't require it. I am just wondering why yours does.
    Because I'm writing a software that needs to be started right away when it's installed. Unless I restart the computer, I don't see how I can achieve this.

    Even with the windows service, how do I start it right away after the installation?

    If I can somehow start it, then the need to restart the computer is no longer a problem.

    Help?
    What is finite, but boundaryless?

  13. #13

  14. #14
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Best bet in this case is to write in the reg startup key your app name to start after restarting . (in some package maker you can write script and the installer itself will write that in the reg ) .

  15. #15

    Thread Starter
    New Member
    Join Date
    Mar 2003
    Location
    Sunnyvale CA
    Posts
    15
    Yeah, that's exactly what I did. I wrote it on the Registry so that it starts automatically when the computer is rebooted. But that's not enough. If I don't find a way to force restart, then it's useless. I'm working in an environment where rebooting occurs once every while.. Maybe once a month, if I'm lucky. I need to restart the comp..
    What is finite, but boundaryless?

  16. #16
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by aspade
    Yeah, that's exactly what I did. I wrote it on the Registry so that it starts automatically when the computer is rebooted. But that's not enough. If I don't find a way to force restart, then it's useless. I'm working in an environment where rebooting occurs once every while.. Maybe once a month, if I'm lucky. I need to restart the comp..
    I can't think of any other options right now . Just try out any of the above links ,to see if they help !

  17. #17
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    Because I'm writing a software that needs to be started right away when it's installed. Unless I restart the computer, I don't see how I can achieve this.

    Even with the windows service, how do I start it right away after the installation?
    Actually it seems to me that if you just want to start an app (especially a service) then restarting the computer is not a great way to get it done. If you want to start an installed service, check out the ServiceController component:
    ms-help://MS.VSCC/MS.MSDNVS/vbcon/html/vbconintroductiontoservicecontrollercomponent.htm
    ms-help://MS.VSCC/MS.MSDNVS/vbcon/html/vbtskperformingadministrativetasksonservices.htm

    If you want to start an executable in interactive mode, you might use the Shell function:
    ms-help://MS.VSCC/MS.MSDNVS/vblr7/html/vafctShell.htm

    Restarting the computer just because you want to start an app seems like a backwards way to do it?

  18. #18
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Umm why not just let whoever installed it start it? Why does the installation package need to start it? Makes no sense.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  19. #19

    Thread Starter
    New Member
    Join Date
    Mar 2003
    Location
    Sunnyvale CA
    Posts
    15
    Thanks to everyone who tried to help me. But I found a way around the problem.

    I wrote a short project that makes an instance of a service controller for my service which then calls my service to launch. Then this little .exe file is added to the setup project's custom actions and set it to laucnh when the installation is completed.

    So this is it. The service starts as soon as the installation is done.

    Thanks all!
    What is finite, but boundaryless?

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