Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. convert WMI script

convert WMI script

Scheduled Pinned Locked Moved Visual Basic
questioncsharptools
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sentmemail
    wrote on last edited by
    #1

    Hi, how can i convert the below vbscript into .net ? thanks Computer = InputBox("Enter the computer name","Terminate Process", "localhost") PName = InputBox("Enter the name of the process","Terminate Process") Set Processes = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2").ExecQuery("select * from Win32_Process where Name = '" & PName & "'") For each Process in Processes Process.Terminate Next

    D 1 Reply Last reply
    0
    • S sentmemail

      Hi, how can i convert the below vbscript into .net ? thanks Computer = InputBox("Enter the computer name","Terminate Process", "localhost") PName = InputBox("Enter the name of the process","Terminate Process") Set Processes = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2").ExecQuery("select * from Win32_Process where Name = '" & PName & "'") For each Process in Processes Process.Terminate Next

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      The System.Management namesapce has everything you'll need to do this. I wish it was a bit simpler to use though...

      Import System.Management
      .
      .
      .
      ' SELECT * FROM Win32_Process WHERE Name='processName'
      Dim query As New SelectQuery("Win32_Process", String.Format("Name='{0}'", processName) )
       
      ' Initialize an object searcher with this query
      Dim searcher As New ManagementObjectSearcher(query)
       
      ' Define arguments for our WMI method call on each object returned, in our
      ' case, Nothing (null)
      Dim methodArgs() As Object = {Nothing}
       
      ' Get the resulting collection or Process objects and loop through it
      For Each ManagementObject foundProcess In searcher.Get()
      Debug.WriteLine( String.Format("Killing process: {0}", foundProcess.Properties("Name") ) )
      foundProcess.InvokeMethod("Terminate", Nothing)
      Next

      RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      S 1 Reply Last reply
      0
      • D Dave Kreskowiak

        The System.Management namesapce has everything you'll need to do this. I wish it was a bit simpler to use though...

        Import System.Management
        .
        .
        .
        ' SELECT * FROM Win32_Process WHERE Name='processName'
        Dim query As New SelectQuery("Win32_Process", String.Format("Name='{0}'", processName) )
         
        ' Initialize an object searcher with this query
        Dim searcher As New ManagementObjectSearcher(query)
         
        ' Define arguments for our WMI method call on each object returned, in our
        ' case, Nothing (null)
        Dim methodArgs() As Object = {Nothing}
         
        ' Get the resulting collection or Process objects and loop through it
        For Each ManagementObject foundProcess In searcher.Get()
        Debug.WriteLine( String.Format("Killing process: {0}", foundProcess.Properties("Name") ) )
        foundProcess.InvokeMethod("Terminate", Nothing)
        Next

        RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        S Offline
        S Offline
        sentmemail
        wrote on last edited by
        #3

        Wao! seems like i need to rewrite my vbscripts !! is there anyway to import them into VB?

        D 1 Reply Last reply
        0
        • S sentmemail

          Wao! seems like i need to rewrite my vbscripts !! is there anyway to import them into VB?

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          No. There is no conversion tool to go from VBScript to VB.NET. You'll have to rewrite them by hand. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups