Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to enable wmi services in firewall on remote host machines using vb.net for the command line using win32 class. i can't find out the error.

What I have tried:

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Try
            Dim strComputer = TxtPCname.Text
            Dim strcommand As String
            Dim intProcessID As UInt32

            strcommand = "cmd.exe /c netsh advfirewall firewall set rule group=""windows management instrumentation (wmi)"" new enable=yes"

            Dim objWMIService = GetObject("winmgmts:" _
                                                    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
            Dim objStartup = objWMIService.Get("Win32_ProcessStartup")
            Dim intreturn As Integer

            Dim objConfig = objStartup.SpawnInstance_
            objConfig.ShowWindow = 12

            Dim objProcess = objWMIService.Get("Win32_Process")
            intreturn = objProcess.Create(strcommand, NULL, objConfig, intProcessID)
            MsgBox(intreturn)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
Posted
Comments
Richard MacCutchan 9-Sep-22 6:23am    
"i can't find out the error."
Without much more information neither can anyone here. You need to explain what happens when you run the code. Also, does the netsh command work when run from a command window?
[no name] 10-Sep-22 11:25am    
Smells like a security violation.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900