Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old September 4th, 2006, 08:01 AM
Registered User
Join Date: Aug 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help me i must convert Code vb to C#

Sub shutdown()
        Dim t As Single
        Dim objWMIService, objComputer As Object
        'Now get some privileges
        objWMIService = GetObject("Winmgmts:{impersonationLevel=impersonat e,(Debug,Shutdown)}")
        For Each objComputer In objWMIService.InstancesOf("Win32_OperatingSystem")

            t = objComputer.Win32Shutdown(8 + 4, 0)

            If t <> 0 Then
                'Error occurred!!!
                'Shutdown your system
            End If
    End Sub


Old September 4th, 2006, 10:45 AM
Wrox Author
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons

Come on, this is trivial, have you even TRIED to convert it yourself. (I am not in the business of doing peoples work for them, Advice is free though)

"The one language all programmers understand is profanity."
Old October 3rd, 2006, 04:43 AM
Authorized User
Join Date: Jul 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts

public void shutdown()
        float t = 0F;
        object objWMIService = null;
//INSTANT C# NOTE: Commented this declaration since looping variables in 'foreach' loops are declared in the 'foreach' header in C#
// object objComputer = null;
        //Now get some privileges
        objWMIService = Microsoft.VisualBasic.Interaction.GetObject("Winmg mts:{impersonationLevel=impersonate,(Debug,Shutdow n)}", null);
        foreach (object objComputer in objWMIService.InstancesOf("Win32_OperatingSystem") )

            t = objComputer.Win32Shutdown(8 + 4, 0);

            if (t != 0)
                //Error occurred!!!
                //Shutdown your system

I hope this helps

Old October 14th, 2006, 12:54 AM
Registered User
Join Date: Oct 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to shriji.1111

Use Convertor to generate c# code from vb

Brijesh Shah

Similar Threads
Thread Thread Starter Forum Replies Last Post
convert dsr file from vb to vb.net Shashi001 VB Components 1 September 22nd, 2006 12:24 PM
Help me convert C# to VB minhtri Pro VB.NET 2002/2003 1 June 8th, 2006 01:32 PM
convert vba code to vb tommy03 VB How-To 3 February 23rd, 2005 02:13 PM
Convert VB to C# code skdp VS.NET 2002/2003 2 March 1st, 2004 11:45 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.