starting processes using wmic

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • niskin
    New Member
    • Apr 2007
    • 109

    starting processes using wmic

    Hi I'm trying to use wmic (the WMI command-line) to start notepad.exe.

    I know that I need to type "cscript //nologo CreateProcess.v bs TestPC %windir%\system 32\notepad.exe %temp%" into command prompt, but I'm stuck on what to put in the script file. I have an outline of what to put from a site:
    Code:
    Dim sComputer		.
    Dim sCmdLine		C:\Windows\notepad.exe
    Dim sCurDir		C:\Windows\notepad.exe
    Dim oProcess		'object representing the Win32_Process class
    Dim oMethod		'object representing the Create method
    
    Dim oInPar		'object representing input parameters of the method
    Dim oOutPar		'object representing output parameters of the method
    
    sComputer 		= WScript.Arguments(0)
    sCmdLine 		= WScript.Arguments(1)
    sCurDir 		= WScript.Arguments(2)
    
    Set oProcess 		= GetObject("winmgmts://" & sComputer & _
    			  "/root/cimv2:Win32_Process")
    Set oMethod 		= oProcess.Methods_("Create")
    Set oInPar 		= oMethod.inParameters.SpawnInstance_()
    oInPar.CommandLine 	= sCmdLine
    oInPar.CurrentDirectory = sCurDir
    Set oOutPar 		= oProcess.ExecMethod_("Create", oInPar)
    
    If oOutPar.ReturnValue 	= 0 Then
    	WScript.Echo "Create process method completed successfully"
    	WScript.Echo "New Process ID is " & oOutPar.ProcessId
    Else
    	WScript.Echo "Create process method failed"
    End If
    I have filled out the bits I think I know.

    Firstly, is this correct? And secondly, what should I be putting where to start notepad.exe?
    Last edited by bartonc; Jul 2 '07, 07:29 PM. Reason: Added [CODE][CODE] tags.
  • niskin
    New Member
    • Apr 2007
    • 109

    #2
    Don't worry I found out how from microsoft.com.

    Comment

    • bartonc
      Recognized Expert Expert
      • Sep 2006
      • 6478

      #3
      Originally posted by niskin
      Don't worry I found out how from microsoft.com.
      Sorry, buddy. I never saw your post. No hard feelings, I hope.

      Comment

      • niskin
        New Member
        • Apr 2007
        • 109

        #4
        I learnt more by finding out myself in the end so it's all good.

        Comment

        Working...