For Function with Pipe Problem.

B

BaKaR

Hi!
I have a problem with a *.cmd batch script.
If i run it "on click" it is working, but if i run it with "schtasks.exe" and "system" user (in background) its not running one of
the two for functions:


@echo off

for /f "tokens=2" %%i in ('tasklist ^| findstr /i aplication') do (
echo %date% %time% Info.PID: %%i >> file.log

for /f "tokens=4" %%k in ('kernrate -p %%i -s 2 ^| findstr /C:"User Time"') do (
echo %date% %time% Info.CPU: %%k >> file.log

if %%k GTR 40.0% (
echo %date% %time% "CPU OverUse Positive ( %%k )" >> file.log
call taskkill /pid %%i /F
)
echo Out_1 >> file.log
)
echo Out_2 >> file.log
)
echo %date% %time% "Finished!" >> file.log

So, the problem is happening in for function where i use kernrate and findstr. If i run the batch "on click", everything is working
well, but if im using schtasks.exe with system user that part of the batch is skipped (also, i cant see echo Out_1) ?! or something,
cauze i cant see its run, every echo i set in front, or after is initiated (again, except Out_1).

Any ideas ?

Thank You,


*. Remove: "DnotSpamMe" When R_ing.
 
M

Marty List

BaKaR said:
Hi!
I have a problem with a *.cmd batch script.
If i run it "on click" it is working, but if i run it with "schtasks.exe"
and "system" user (in background) its not running one of
the two for functions:


@echo off

for /f "tokens=2" %%i in ('tasklist ^| findstr /i aplication') do (
echo %date% %time% Info.PID: %%i >> file.log

for /f "tokens=4" %%k in ('kernrate -p %%i -s 2 ^| findstr /C:"User Time"') do (
echo %date% %time% Info.CPU: %%k >> file.log

if %%k GTR 40.0% (
echo %date% %time% "CPU OverUse Positive ( %%k )" >> file.log
call taskkill /pid %%i /F
)
echo Out_1 >> file.log
)
echo Out_2 >> file.log
)
echo %date% %time% "Finished!" >> file.log

So, the problem is happening in for function where i use kernrate and
findstr. If i run the batch "on click", everything is working
well, but if im using schtasks.exe with system user that part of the batch
is skipped (also, i cant see echo Out_1) ?! or something,
cauze i cant see its run, every echo i set in front, or after is initiated (again, except Out_1).

Any ideas ?

Thank You,


*. Remove: "DnotSpamMe" When R_ing.


Which OS are you using?

Where is tasklist.exe located? Is this folder in the PATH of the SYSTEM
account?

Where is kernrate.exe located? Is this folder in the PATH of the SYSTEM
account?

While you're troubleshooting, comment out that @Echo Off. That makes it
look nicer but it's hiding a lot of good troubleshooting info from you.

The >> redirection is only redirecting standard output to your file.log.
You're not seeing any error output, add " 2>>errors.log" or " 2>>file.log"
like this:
for /f "tokens=2" %%i in ('tasklist ^| findstr /i aplication') do (
echo %date% %time% Info.PID: %%i >>file.log 2>>file.log
 
B

BaKaR

Hi!

OS: WinXP Pro.

Tasklist.exe: C:\windows\system32\
Kernrate.exe: C.\program files\MS Resource Kit\Tools\kernrate.exe

Both are in the "Environment Variables">"System Variables"

Im using echo and 2>>, just i gave you part of "almost" finished problem.

Well, im using schtasks.exe (WinXP/Win2K3 at.exe) command which is working very well.

schtasks /create /sc minute /mo 5 /tn "test" /tr c:\scripts\test.cmd /ru System

So, it will put the task in the background process and execute it every 5 minutes with NTAuthority\System privilages/permissions.


If i run the script, i tested, with my account (local Admin) it works fine, still, if ran with that schtasks and system account,
aint working ...



--


-------;.Wo0o0oS!h:..
!#!Int3RGAlaCTic Fu!x!#!:..
=!:MESING a.k.a. BaKaR a.k.a BR4iNL355:..
-------;.Ca0Tic EXp:..
*. Remove: "DnotSpamMe" When R_ing.
 
P

Paul R. Sadowski

If I try to run kernrate from the system account I get:
RtlAdjustPrivilege(SE_PROFILE_PRIVILEGE) failed: c0000061

Try running it under anadmin account.
 
M

Marty List

BaKaR said:
Hi!

OS: WinXP Pro.

Tasklist.exe: C:\windows\system32\
Kernrate.exe: C.\program files\MS Resource Kit\Tools\kernrate.exe

Both are in the "Environment Variables">"System Variables"

Im using echo and 2>>, just i gave you part of "almost" finished problem.

Well, im using schtasks.exe (WinXP/Win2K3 at.exe) command which is working very well.

schtasks /create /sc minute /mo 5 /tn "test" /tr c:\scripts\test.cmd /ru System

So, it will put the task in the background process and execute it every 5
minutes with NTAuthority\System privilages/permissions.
If i run the script, i tested, with my account (local Admin) it works
fine, still, if ran with that schtasks and system account,
aint working ...


Are you sure you're looking at the correct file.log? If the current
directory is different for the scheduled task, then a new copy of file.log
will be created elsewhere. Try specifying the full path to your output
file.

I think you should post the exact contents of your script, not something
"almost" the same.
 
B

BaKaR

True, Got same error msg.
Also, got same msg when i tryed running kernrate with another user on the system.

Well, the problem is, System user is giving me "background" option from schtasks.exe which i cant get like a normal user..
 
B

BaKaR

Ya, that was the right *.log file.
Almost as in not so much error cheking + cleared all comments and some start, call lines in the end.

+ ill use Local computer Admin user - it will be enough.


Thank You All!
 
P

Paul R. Sadowski

BaKaR said:
Well, the problem is, System user is giving me "background" option from
schtasks.exe which i cant get like a normal user..

If that's an issue then here's a simple way to run a batch file in a hidden
window using WSH.

Set WshShell = WScript.CreateObject("WScript.Shell")
cmd = "c:\bin\scripts\ftpputiefavs.cmd"
Return = WshShell.Run(cmd, 0, True)
set WshShell = Nothing

Just change the string that cmd points to to whatever your batch file is.
Then run this script using wscript.exe as a scheduled job.
 
B

BaKaR

Well, one more thing ..
Ill use schtasks as "local computer\Administrator" so the tasks run in background.
When i execute an *.exe file from the script ran in the schtasks .. background i get its process in task manager but the task is
invisible in the tray bar.
Any ideas how to run an exe aplication to foreground ?
Think thats mapped to logged user ...
But if i run schtasks as me i cannot hide the schtasks initiating, even with WSH script you provided.
Every time it runs it pops svchost window (wsh script).

The thing is, i have a *.cmd (which i provided) that needs to run every 3 minutes to check some things.
In the end of that *.cmd there is If chk. If its positive then is starts an exe "start aplication.exe" and after that one "cscript
script.vbs".

If i run schtasks and *.cmd with local Admin right its working every 3 minutes in the background so i cant see it == thats ok.
But, when it comes to that IF and its postive running exe is in background, including that *.vbs in the end.

So, everything is kewl up to IF chk. There i need a mechanizm to run *.exe and *.vbs after to foreground/desktop.

Any ideas ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top