1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Very basic visual basic Win32_ScheduledJob help

Discussion in 'Windows 7' started by CplBricker, Aug 28, 2012.

Thread Status:
Not open for further replies.
  1. CplBricker

    CplBricker Thread Starter

    Joined:
    Dec 7, 2005
    Messages:
    3
    Hi everyone,

    I've been trying to get my feet wet in creating a .vbs file from notepad to do a basic function. I wanted to be able to run .reg files remotely but also interactively. This led me down the path of simply finding an example of a .vbs that would open anything remotely at all. Notepad is what came up with the most results and the Win32_ScheduledJob object appeared to be what was needed.

    I researched many different places but this is a decent walkthrough. http://msdn.microsoft.com/en-us/library/windows/desktop/aa394601(v=vs.85).aspx

    I grabbed the code below out of the website and changed the date parameters to run in a couple minutes from my current time. I could see the task in scheduled tasks but when the time had come and gone nothing would happen and this is just trying to get it to run locally so far.

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")
    JobID = "Test"
    Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
    errJobCreate = objNewJob.Create _
    ("Notepad.exe", "********143000.000000-420", _
    True , 1 OR 4 OR 16, ,True, JobId)
    If errJobCreate = 0 Then
    WScript.Echo "Job created successfully: " & VBNewLine _
    & "Notepad.exe scheduled to run repeately at 14.30 (2:30 P.M.) PST" & VBNewLine _
    & "on Mon, Wed, and Fri."
    Else
    WScript.Echo "Job not created. Error code = " & errJobCreate
    End If


    Now I actually did find something that worked locally but it is not using the Win32_ScheduledJob object which I believe is needed to run things remotely the way I need to. In any case the below will actually open notepad locally.
    strComputer = "."
    strCommand = "notepad.exe"

    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set objProcess = objWMIService.Get("Win32_Process")

    errReturn = objProcess.Create(strCommand, null, null, intProcessID)

    If errReturn = 0 Then
    Wscript.Echo "notepad.exe was started with a process ID: " & intProcessID
    Else
    Wscript.Echo "notepad.exe could not be started due to error: " & errReturn
    End If

    Can anyone help me out please
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1066841

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice