regarding windows xp services

nnCron and nnCron LITE discussion

regarding windows xp services

Postby bilal » Fri, 06 Oct 2006, 17:35

Hello,

OS: Windows xp

I am new to nnCron and I was wondering if there was a way in nnCron of automatically stopping a service from the services window and then restarting the same service.

So far i have only been able to open up the services windows, by using the run application or open document in the action tab, then in the application or document path i've entered C:\WINDOWS\system32\services.msc and in startup folder i've entered C:\WINDOWS\system32. So now in the advance tab you will see :-

Time: 52 13 * * * *
Action:
StartIn: "C:\WINDOWS\system32"
ShowNormal NormalPriority
START-APP: C:\WINDOWS\system32\services.msc

And this will open the services window.

What i would like to know is, how, if there is a way, will i be able to automatically open a particular service in the services window and then stop that service, and then after a couple of seconds restart that same service?

Please could someone help.
bilal
 
Posts: 15
Joined: Fri, 06 Oct 2006, 16:15

Postby Lynx » Fri, 06 Oct 2006, 19:13

Try following commands to manage services:
net start <servicename> to start service
net stop <servicename> to stop it
in START-APP:

You can find out service name by running net help start or net start (try both) in command prompt.

Also you can try using sc.exe from Windows Resource Kit
User avatar
Lynx
 
Posts: 321
Joined: Thu, 04 May 2006, 20:07
Location: Уфа

Postby bilal » Tue, 10 Oct 2006, 13:52

Hello,

Thank you for your reply lynx,

I tried to use the windows net stop command in nncron, but it brings up an error message.

This is what i tried.

Time: 42 11 * * * *
Action:
StartIn: "C:\WINDOWS\system32"
ShowNormal NormalPriority
START-APP: C:\WINDOWS\system32\services.msc
net stop "name of service went in here"

The command
net stop "name of service went in here"
work in command promt.

Could someone please help.
bilal
 
Posts: 15
Joined: Fri, 06 Oct 2006, 16:15

Postby bilal » Tue, 10 Oct 2006, 14:23

hello,

I worked out my mistake the code need another START-APP

Time: 20 12 * * * *
Action:
StartIn: "C:\WINDOWS\system32"
ShowNormal NormalPriority
START-APP: C:\WINDOWS\system32\services.msc
START-APP: net start "name of service"
bilal
 
Posts: 15
Joined: Fri, 06 Oct 2006, 16:15

Postby bilal » Tue, 10 Oct 2006, 15:10

hello,

I am now trying to restart the same service using this

Time: 3 13 * * * *
Action:
StartIn: "C:\WINDOWS\system32"
ShowNormal NormalPriority
START-APP: C:\WINDOWS\system32\services.msc
START-APP: net stop "name of service"
START-APP: net start "name of service"

This is still only stopping the service, Is there away of stopping and restarting or do i have to wait 1 min to restart.
bilal
 
Posts: 15
Joined: Fri, 06 Oct 2006, 16:15

Postby Lynx » Tue, 10 Oct 2006, 21:14

First of all, you don't need to
START-APP: C:\WINDOWS\system32\services.msc

Place pause between net stop and net start, so net stop has time to finish its work :)
Or you can create bat-file with net stop and net start, and then just run this bat-file with START-APP.
Or even better - use START-APPW, this will wait for the first command to finish.
User avatar
Lynx
 
Posts: 321
Joined: Thu, 04 May 2006, 20:07
Location: Уфа

Postby bilal » Thu, 12 Oct 2006, 12:44

Hello Lynx,

Thanks for all the help you have given.

The solution you recommended works.

Time: 12 10 * * * *
Action:
StartIn: "C:\WINDOWS\system32"
ShowNormal NormalPriority
START-APPW: net stop "name of service"
START-APPW: net start "name of service"

Again thank you for you time.

Bilal
bilal
 
Posts: 15
Joined: Fri, 06 Oct 2006, 16:15

Postby Lynx » Thu, 12 Oct 2006, 19:16

By the way, you can delete NormalPriority option. And yo can change ShowNormal to ShowHide, so command window won't be shown :)
User avatar
Lynx
 
Posts: 321
Joined: Thu, 04 May 2006, 20:07
Location: Уфа

Postby bilal » Mon, 16 Oct 2006, 15:00

Hi,


Thanks, I will remove the show normal, and will insert showhide later. It is just for testing purpose.

I got another question, to do with monitoring a process. Before i do the stop and then restart of a particular service, i want to monitor the actual process so that if the process reaches a particular memory usage point, nncron will then perform the stop and then restart of a service .

I know that if you want to watch a process you use the WatchProc command and then the name of the process. If you want to monitor the memory usage which is the next thing i need to do, I'm not sure what to use.

I know you can use the WatchCPUUsage command to monitor the CPU, but is of no use since i want to monitor the memory usage of a process.

Could someone please advice me on how to go about performing this task

Time: 10 10 * * * *
WatchProc: "name of process.exe"

Action:
StartIn: "C:\WINDOWS\system32"
ShowNormal NormalPriority
START-APPW: net stop "name of service"
START-APPW: net start "name of service"

Thanks,
Bilal
bilal
 
Posts: 15
Joined: Fri, 06 Oct 2006, 16:15

Postby bilal » Mon, 16 Oct 2006, 15:34

Hi,

Please ignore the Time: 10 10 * * * * part since WatchProc is a OnEvent function.

Thanks,
Bilal
bilal
 
Posts: 15
Joined: Fri, 06 Oct 2006, 16:15

Postby bilal » Mon, 16 Oct 2006, 17:58

Hi,

I used wmic process list brief command in windows command promt, this brought up all the process i have plus the amount off memory usage. Could this be used in my code?

Thanks,
Bilal
bilal
 
Posts: 15
Joined: Fri, 06 Oct 2006, 16:15

Postby Lynx » Mon, 16 Oct 2006, 18:42

You can try:
wmic process list brief|find /i "procname">proc.txt
and then read proc.txt file (you can read about file input/output in nnCron help.
PS. You can read line and then process it with help of regexp.
User avatar
Lynx
 
Posts: 321
Joined: Thu, 04 May 2006, 20:07
Location: Уфа

Postby bilal » Tue, 17 Oct 2006, 19:52

Hi,

Thanks for that.

I have created a proc.bat file which contains the command

wmic process where name="nameofprocess.exe" get workingsetsize>proc.txt

so that each time the proc.bat file runs it creates a proc.txt file which contains the following:-

line1: workingsetsize
line2: the process memory usage figure for that process(a number e.g. 41742336)

I have also created a nncron tab file called batch.tab, which runs the proc.bat file every 5 min
E.G.

Time: */5 * * * * *
Action:
StartIn: "C:\batchfiles"
ShowNormal NormalPriority
START-APP: C:\batchfiles\proc.bat


This will then update the proc.txt file with a up to date value of the memory usage.

Now I am trying to use my original nncron tab file called test.tab to try and lookup/read line the value in line2 of the proc.txt file, If it exceed a certain value (say 50000000) then carry out the stop and restart of that service.

This is where i need some advice/guidance to carry out this task.

Time: START-TIME(ON EVENT function)
Action:
StartIn: "C:\WINDOWS\system32"
ShowNormal NormalPriority
START-APPW: net stop "name of service"
START-APPW: net start "name of service"


Thanks,
Bilal
bilal
 
Posts: 15
Joined: Fri, 06 Oct 2006, 16:15

Postby Lynx » Tue, 17 Oct 2006, 22:00

I'd suggested something like this:
Code: Select all
Time: */5 * * * * *
VARIABLE list-file
CREATE list-contents 258 ALLOT
Action:
    StartIn: "C:\batchfiles"
    ShowHide
    START-APPW: C:\batchfiles\proc.bat
    S" c:\batchfiles\proc.txt" R/O OPEN-FILE-SHARED THROW list-file !
    BEGIN list-contents 1+ 255 list-file @ READ-LINE THROW WHILE
    list-contents C!
    REPEAT
    DROP
    list-file @ CLOSE-FILE DROP
    list-contents COUNT S>NUM 50000000 > IF
        START-APPW: net stop "name of service"
        START-APPW: net start "name of service"
    THEN

But there's one problem - wmic process where name="nameofprocess.exe" get workingsetsize>proc.txt creates Unicode-encoded file and I can't make nnCron read it in normal way :)
User avatar
Lynx
 
Posts: 321
Joined: Thu, 04 May 2006, 20:07
Location: Уфа

Postby bilal » Wed, 18 Oct 2006, 18:43

Hello Lynx,

The code you supplied works.

As for nncron reading unicode-encoded file, basically convert this file to ASCII in proc.bat and then get nncron to read the ascii file.

The command in the proc.bat file contained:-

wmic process where name="nameofprocess.exe" get workingsetsize>proc.txt

Enter the following line as well:-

type proc.txt > proc2.txt

Which will create the unicode file to a new ascii file.
bilal
 
Posts: 15
Joined: Fri, 06 Oct 2006, 16:15


Return to nnCron forum (English)

Who is online

Users browsing this forum: No registered users and 4 guests