View Full Version : For Function with Pipe Problem.


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.



Marty List

"BaKaR" wrote in message
news:c3rsov$3ea$1@brown.net4u.hr...
> 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




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.
"Marty List" wrote in message news:c3s215$2aeiod$1@ID-172409.news.uni-berlin.de...
>
> "BaKaR" wrote in message
> news:c3rsov$3ea$1@brown.net4u.hr...
> > 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
>
>
>
>



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.

"BaKaR" wrote in message
news:c3rsov$3ea$1@brown.net4u.hr...
> 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.
>
>



Marty List

"BaKaR" wrote in message
news:c3s549$mq4$1@brown.net4u.hr...
> 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.




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..

--


*. Remove: "DnotSpamMe" When R_ing.



"Paul R. Sadowski" wrote in message news:uRf1g2aEEHA.3408@tk2msftngp13.phx.gbl...
> If I try to run kernrate from the system account I get:
> RtlAdjustPrivilege(SE_PROFILE_PRIVILEGE) failed: c0000061
>
> Try running it under anadmin account.
>
> "BaKaR" wrote in message
> news:c3rsov$3ea$1@brown.net4u.hr...
> > 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.
> >
> >
>
>
>



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!

--

*. Remove: "DnotSpamMe" When R_ing.



"Marty List" wrote in message news:c3s6oh$2b68n2$1@ID-172409.news.uni-berlin.de...
>
> "BaKaR" wrote in message
> news:c3s549$mq4$1@brown.net4u.hr...
> > 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.
>
>
>
>



Paul R. Sadowski
"BaKaR" wrote in message
news:c3s6t7$qjo$1@brown.net4u.hr...
>
> 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.



BaKaR
Thanks!

--

*. Remove: "DnotSpamMe" When R_ing.


"Paul R. Sadowski" wrote in message news:O20OlGbEEHA.1272@TK2MSFTNGP12.phx.gbl...
> "BaKaR" wrote in message
> news:c3s6t7$qjo$1@brown.net4u.hr...
> >
> > 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.



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 ?

--

*. Remove: "DnotSpamMe" When R_ing.


"Paul R. Sadowski" wrote in message news:O20OlGbEEHA.1272@TK2MSFTNGP12.phx.gbl...
> "BaKaR" wrote in message
> news:c3s6t7$qjo$1@brown.net4u.hr...
> >
> > 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.
>
>
>



Paul R. Sadowski
The only thing I can think of is to use BeyondExec with the i switch (allow
to interact with the desktop) to launch some of the applications.

Look at http://www.beyondlogic.org/consulting/remoteprocess/BeyondExec.htm
for details and see if you can use it to get that visible window.

"BaKaR" wrote in message
news:c3v0tv$unv$1@brown.net4u.hr...
> 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 ?
>
> --
>
> *. Remove: "DnotSpamMe" When R_ing.
>
>
> "Paul R. Sadowski" wrote in message
> news:O20OlGbEEHA.1272@TK2MSFTNGP12.phx.gbl...
>> "BaKaR" wrote in message
>> news:c3s6t7$qjo$1@brown.net4u.hr...
>> >
>> > 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.
>>
>>
>>
>
>



Marty List

"BaKaR" wrote in message
news:c3rsov$3ea$1@brown.net4u.hr...
> 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




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.
"Marty List" wrote in message news:c3s215$2aeiod$1@ID-172409.news.uni-berlin.de...
>
> "BaKaR" wrote in message
> news:c3rsov$3ea$1@brown.net4u.hr...
> > 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
>
>
>
>



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.

"BaKaR" wrote in message
news:c3rsov$3ea$1@brown.net4u.hr...
> 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.
>
>



Marty List

"BaKaR" wrote in message
news:c3s549$mq4$1@brown.net4u.hr...
> 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.




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..

--


*. Remove: "DnotSpamMe" When R_ing.



"Paul R. Sadowski" wrote in message news:uRf1g2aEEHA.3408@tk2msftngp13.phx.gbl...
> If I try to run kernrate from the system account I get:
> RtlAdjustPrivilege(SE_PROFILE_PRIVILEGE) failed: c0000061
>
> Try running it under anadmin account.
>
> "BaKaR" wrote in message
> news:c3rsov$3ea$1@brown.net4u.hr...
> > 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.
> >
> >
>
>
>



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!

--

*. Remove: "DnotSpamMe" When R_ing.



"Marty List" wrote in message news:c3s6oh$2b68n2$1@ID-172409.news.uni-berlin.de...
>
> "BaKaR" wrote in message
> news:c3s549$mq4$1@brown.net4u.hr...
> > 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.
>
>
>
>



Paul R. Sadowski
"BaKaR" wrote in message
news:c3s6t7$qjo$1@brown.net4u.hr...
>
> 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.



BaKaR
Thanks!

--

*. Remove: "DnotSpamMe" When R_ing.


"Paul R. Sadowski" wrote in message news:O20OlGbEEHA.1272@TK2MSFTNGP12.phx.gbl...
> "BaKaR" wrote in message
> news:c3s6t7$qjo$1@brown.net4u.hr...
> >
> > 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.



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 ?

--

*. Remove: "DnotSpamMe" When R_ing.


"Paul R. Sadowski" wrote in message news:O20OlGbEEHA.1272@TK2MSFTNGP12.phx.gbl...
> "BaKaR" wrote in message
> news:c3s6t7$qjo$1@brown.net4u.hr...
> >
> > 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.
>
>
>



Paul R. Sadowski
The only thing I can think of is to use BeyondExec with the i switch (allow
to interact with the desktop) to launch some of the applications.

Look at http://www.beyondlogic.org/consulting/remoteprocess/BeyondExec.htm
for details and see if you can use it to get that visible window.

"BaKaR" wrote in message
news:c3v0tv$unv$1@brown.net4u.hr...
> 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 ?
>
> --
>
> *. Remove: "DnotSpamMe" When R_ing.
>
>
> "Paul R. Sadowski" wrote in message
> news:O20OlGbEEHA.1272@TK2MSFTNGP12.phx.gbl...
>> "BaKaR" wrote in message
>> news:c3s6t7$qjo$1@brown.net4u.hr...
>> >
>> > 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.
>>
>>
>>
>
>