Why does one script work and the other doesn't?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
KWiz
Junior Coder
Posts: 30
Joined: Sat Oct 07, 2006 1:43 pm

Why does one script work and the other doesn't?

Post by KWiz » Fri Jan 16, 2009 12:23 pm

Why does the first script work, and the second one doesn't?
I'm using Windows XP. The only difference between these two scripts is the very last line of the script.

I'm unfamiliar with VBScript. I got the first script from an MJT representative a long time ago. I just tried "rewriting" the script to terminate another service, aawservice.exe, but I guess my rewriting didn't work. Why not?

Thanks,
KWiz

Script 1:

VBSTART
Sub killProcess(pgm)
set wmi = getobject("winmgmts:")
sQuery = "select * from win32_process " & "where name='" & pgm & "'"
set processes = wmi.execquery(sQuery)
for each process in processes
process.terminate
next
End Sub
VBEND

VBRun>KillProcess,AcroRd32.exe





Script 2:

VBSTART
Sub killProcess(pgm)
set wmi = getobject("winmgmts:")
sQuery = "select * from win32_process " & "where name='" & pgm & "'"
set processes = wmi.execquery(sQuery)
for each process in processes
process.terminate
next
End Sub
VBEND

VBRun>KillProcess,aawservice.exe

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri Jan 16, 2009 4:46 pm

It may actually be working, but aawservice has a nasty habit of automatically restarting itself. I don't know if it will do what you want, but it may be better to just stop it autostarting.

(aawaservice is Ad Aware, sometimes the cure is worse than the disease :roll: )

KWiz
Junior Coder
Posts: 30
Joined: Sat Oct 07, 2006 1:43 pm

Post by KWiz » Sun Jan 18, 2009 4:34 am

No, that's not it. I just learned something new about the problem.

On the Task manager, on the processes tab, under the heading "username", I see four different usernames as follows:

Local Service
Network Service
System
My Name

This particular script only effects processes running under "My Name".

How can I change this script so that it effects processes running under "System"?

Thanks for any ideas from anybody.

KWiz

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Not finding or not killing?

Post by gdyvig » Sun Jan 18, 2009 5:33 am

Is the SQL query finding the process?

Or is the kill command not working?

Can you kill it from the Task Manager?

KWiz
Junior Coder
Posts: 30
Joined: Sat Oct 07, 2006 1:43 pm

Re: Not finding or not killing?

Post by KWiz » Mon Jan 19, 2009 12:28 am

Yes, I can kill it from the Task Manager.

I don't know what you mean by the SQL query finding the process (I don't know what SQL queries are).... but I'm guessing that must be it??

Well thanks for your consideration here, hopefully you can solve the problem :!:

Kwiz

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Mon Jan 19, 2009 2:05 am

I confirm your result, that vbscript cannot kill a process owned by system.

One solution is to download pstools http://technet.microsoft.com/en-us/sysi ... 96649.aspx and automate the command line pskill command. It does kill system owned processes, I just tested it.

User avatar
JRL
Automation Wizard
Posts: 3505
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Jan 19, 2009 2:17 am

Have you tried DOS? Its free. No need to search the internet and download potentially dangerous programs. In this case its even fewer lines of code than VBScript. I have not tested because I don't use AdAware.

Code: Select all

Let>RP_WAIT=1
Let>RP_WINDOWMODE=0
Run>cmd /c TASKKILL /F /IM aawservice.exe

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Mon Jan 19, 2009 3:22 am

I tried to kill a system owned process (spysweeper.exe) with TASKKILL and if failed with "Access Denied".

pstools is a very useful set of utilities, and (since the author was hired by them) it is from microsoft.

KWiz
Junior Coder
Posts: 30
Joined: Sat Oct 07, 2006 1:43 pm

Post by KWiz » Mon Jan 19, 2009 3:02 pm

That worked for me, JRL. Thanks! I don't know if it works for all SYSTEM processes (apparently not Spysweeper), but it worked for aawservice.

Thanks again,
Kwiz

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts