Help! Restart WinXP from VB.Net? 
Author Message
 Help! Restart WinXP from VB.Net?

The code I used in VB6 doesn't work in .NET.

Help!



Sun, 30 Jan 2005 12:29:17 GMT  
 Help! Restart WinXP from VB.Net?
Hi,
Try this out. In win2k, winxp I had to use WMI to get the system to
reboot. The call to ExitWindowsEx only seemed to work for a logoff and
not a reboot.
Shawn

Option Strict Off
Option Explicit On
Module Logoff
        '********************************************
        '*  Shawn Shelton
        '*  07DEC2001
        '*  These is needed to logoff or restart windows
        '********************************************
        'code needed to reboot windows
        Public Const EWX_LOGOFF As Short = 0
        Public Const EWX_SHUTDOWN As Short = 1
        Public Const EWX_REBOOT As Short = 2
        Public Const EWX_FORCE As Short = 4

        Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Integer,
ByVal dwReserved As Integer) As Integer

        Public LoginSucceeded As Boolean

        Public Sub LogoffWindows()
                ExitWindowsEx(EWX_LOGOFF, &HFFFFs)
        End Sub

        Public Sub RebootWindows()
                Dim OpSysSet As Object
                Dim OpSys As Object
                'use WMI because the call to ExitWindowsEx to reboot windows 2000
                'does not work
                OpSysSet =
GetObject("winmgmts:{impersonationLevel=impersonate,(ShutDown)}").InstancesOf("Win32_OperatingSystem")
                For Each OpSys In OpSysSet
                        OpSys.Reboot()
                Next OpSys
        End Sub
End Module

Quote:

> The code I used in VB6 doesn't work in .NET.

> Help!

--
-----------------------
Shawn Shelton
IT Programmer Analyst
Academic User Services
Idaho State University
-----------------------


Mon, 31 Jan 2005 00:34:11 GMT  
 Help! Restart WinXP from VB.Net?
Doesn't work in VB.NET.

I can use this in VB6, but not .NET.

Can ANYBODY do this? There was tons of code to do this in VB6, but no one
can do it (or has offered) to do it in .NET.



Quote:
> Hi,
> Try this out. In win2k, winxp I had to use WMI to get the system to
> reboot. The call to ExitWindowsEx only seemed to work for a logoff and
> not a reboot.
> Shawn

> Option Strict Off
> Option Explicit On
> Module Logoff
> '********************************************
> '*  Shawn Shelton
> '*  07DEC2001
> '*  These is needed to logoff or restart windows
> '********************************************
> 'code needed to reboot windows
> Public Const EWX_LOGOFF As Short = 0
> Public Const EWX_SHUTDOWN As Short = 1
> Public Const EWX_REBOOT As Short = 2
> Public Const EWX_FORCE As Short = 4

> Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Integer,
> ByVal dwReserved As Integer) As Integer

> Public LoginSucceeded As Boolean

> Public Sub LogoffWindows()
> ExitWindowsEx(EWX_LOGOFF, &HFFFFs)
> End Sub

> Public Sub RebootWindows()
> Dim OpSysSet As Object
> Dim OpSys As Object
> 'use WMI because the call to ExitWindowsEx to reboot windows 2000
> 'does not work
> OpSysSet =

GetObject("winmgmts:{impersonationLevel=impersonate,(ShutDown)}").InstancesO
f("Win32_OperatingSystem")

- Show quoted text -

Quote:
> For Each OpSys In OpSysSet
> OpSys.Reboot()
> Next OpSys
> End Sub
> End Module


> > The code I used in VB6 doesn't work in .NET.

> > Help!

> --
> -----------------------
> Shawn Shelton
> IT Programmer Analyst
> Academic User Services
> Idaho State University
> -----------------------



Mon, 31 Jan 2005 09:16:18 GMT  
 Help! Restart WinXP from VB.Net?
Well it works great in my VB.NET app on win2k and winxp so I can't tell
you what you are doing wrong. Sorry. So the WMI implementation just
doesn't do anything for you or you get errors or just what exactly?
Good Luck!

Quote:

> Doesn't work in VB.NET.

> I can use this in VB6, but not .NET.

> Can ANYBODY do this? There was tons of code to do this in VB6, but no one
> can do it (or has offered) to do it in .NET.



>>Hi,
>>Try this out. In win2k, winxp I had to use WMI to get the system to
>>reboot. The call to ExitWindowsEx only seemed to work for a logoff and
>>not a reboot.
>>Shawn

>>Option Strict Off
>>Option Explicit On
>>Module Logoff
>>'********************************************
>>'*  Shawn Shelton
>>'*  07DEC2001
>>'*  These is needed to logoff or restart windows
>>'********************************************
>>'code needed to reboot windows
>>Public Const EWX_LOGOFF As Short = 0
>>Public Const EWX_SHUTDOWN As Short = 1
>>Public Const EWX_REBOOT As Short = 2
>>Public Const EWX_FORCE As Short = 4

>>Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Integer,
>>ByVal dwReserved As Integer) As Integer

>>Public LoginSucceeded As Boolean

>>Public Sub LogoffWindows()
>>ExitWindowsEx(EWX_LOGOFF, &HFFFFs)
>>End Sub

>>Public Sub RebootWindows()
>>Dim OpSysSet As Object
>>Dim OpSys As Object
>>'use WMI because the call to ExitWindowsEx to reboot windows 2000
>>'does not work
>>OpSysSet =

> GetObject("winmgmts:{impersonationLevel=impersonate,(ShutDown)}").InstancesO
> f("Win32_OperatingSystem")

>>For Each OpSys In OpSysSet
>>OpSys.Reboot()
>>Next OpSys
>>End Sub
>>End Module


>>>The code I used in VB6 doesn't work in .NET.

>>>Help!

>>--
>>-----------------------
>>Shawn Shelton
>>IT Programmer Analyst
>>Academic User Services
>>Idaho State University
>>-----------------------

--
-----------------------
Shawn Shelton
IT Programmer Analyst
Academic User Services
Idaho State University
-----------------------


Wed, 02 Feb 2005 00:14:28 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. writing CDs in vb.net on WinXP

2. VB.NET app won't work after update to WinXP SP1

3. VB.NET on WinXP?

4. Can anybody send VB.net Code to shutdown or restart local computer for me

5. WinXP Home Edition. .NET Framework

6. Has anyone else installed VS.NET on WinXP?

7. WinXP-Visual Studio 6.0-Studio.Net compatibility

8. WinXP-Visual Studio 6.0-Studio.Net compatibility

9. Cant restart web services more than once with command: net start w3svc

10. .NET Configuration/ VB.NET app help

11. Help to learn VB.NET , ASP.NET

12. VB.Net and Ado.Net Help Please!!!!

 

 
Powered by phpBB® Forum Software