Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Task on remote machine

Status
Not open for further replies.

sglab

Technical User
Jul 29, 2003
104
US
Hello everyone.

I have a question for you. I need to create a Sceduled Task to run a script on remote machine. Below is the code I use for training, so to speak. This code fails with Error 22. What might be the reason?

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

Set objNewJob = 
objWMIService.Get("Win32_ScheduledJob")

errJobCreated = objNewJob.Create _
    ("Notepad.exe", "********074500.000000-240", _
        True , , , , JobID) 
Wscript.Echo errJobCreated

I've been trying to execute this code on virtual machines running XP. I'm logged on as Administrator on all machines and the script fails even when executed locally as in this sample.

Thank you in advance.
 
[1]
>This code fails with Error 22.
ref: -quote-[tt]
return code: 22
description: The account that this service runs under is invalid or lacks the permissions to run the service.
[/tt]-unquote-
>I'm logged on as Administrator on all machines and the script fails even when executed locally as in this sample.
You should investigate into the correctness of statement. We don't argue about it.
>I've been trying to execute this code on virtual machines running XP.
That may be a reason.

[2]
>errJobCreated = objNewJob.Create _
("Notepad.exe", "********074500.000000-240", _
True , , , , JobID)

If you execute an application of nodepad.exe or alike, it is no good to put InteractWithDesktop to default (false). It will be open and hidden. You should instead at least make it interactive, good or bad.
[tt]
errJobCreated = objNewJob.Create _
("Notepad.exe", "********074500.000000-240", _
True , , , [red]True[/red], JobID)
[/tt]
 
Thank you, tsuji, for your response.
I'm not really very familiar with WMI and making first baby steps there. I have another script that changes system time on remote machines - also virtual - without any problem. So, I thought, I do have sufficient rights to create a task. Are there any restrictions to running scripts on virtual machines? One more thing, the script that changes system time, sets priviliges on remote machine
to do so. Could it be the same with tasks? I was trying to find information on that, but was unable to.

Thank you. Your help is greatly appreciated.
 
I am tempted to say add yourself to the local administrators group of the remote m/c, but, taken that you said you annot even do so on the local m/c, that's a contradition. No, I have nothing to add.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top