Jump to content

Run As Service


Recommended Posts

Yoo there, i'm making this little tool that cleansup ur pc and stuff but i have some trouble hiding it.

since its gonna run on my school ( with the damn kids that shutdown every think they don't know) i wanted to install it as a service. this way it won't show up in the taskbar and will only be able to shutdown when the pc shutsdown.

soo,

1. How do i make the program install itself as a service?

2. How do i make the program RUN as a service?

and if any of u has time left.

3. How can i make an program replace itself?

BIG THANKS,

zeroZshadow

*If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip...
Link to comment
Share on other sites

  • Moderators

If by replace you mean restart, MHz had a nice option, here is an example: http://www.autoitscript.com/forum/index.ph...ndpost&p=159442

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

no no, i didn't mean restart. in my program it downloads an exe ( when there is an new version) and then it should replace the old one. do i just have to make and EXTRA script do that ? or maby a bat file ?

*If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip...
Link to comment
Share on other sites

I read something on the forums ones.

I tried it also.

Small explenation.

Windows locks files wich are running as a program also related dll files are often locked.

You cannot delete them then.

Wich you can do is rename them. Then download new version as original name. Then run that one and exit. (and delete the old script with the new program)

It really works. I made a bogus autoupdate script with that idea and it worked ofcourse the program only updated and restarted.

Kinda weird you can just rename locked files. Ofcourse some files can be locked so the name cannot be changed. But autoit exes are not locked that way.

Running as service, try search for 'service' there are some subjects on this with full examples.

I also have this problem at my school but I used some free tool to run as a service. Also because they have to be administrator (or have the rights(they have to be able to change stuff)) I had to find a way to disable the changing of passwords. Fun way I just kill the window that popups where you type the password. And no more change. Luckely they are stupid enough not to use pspasswd.

Good luck.

Link to comment
Share on other sites

  • Moderators

no no, i didn't mean restart. in my program it downloads an exe ( when there is an new version) and then it should replace the old one. do i just have to make and EXTRA script do that ? or maby a bat file ?

You should check the scripts and scraps forum... or even look at the new one that AutoIt is using to check for updates on theirs. They use a combination of a few things, me... I just use an .ini and a personal script I wrote to do all the hard work.

Here's the one I was looking at this morning, a really great job, and lots of detail to follow.

http://www.autoitscript.com/forum/index.ph...ndpost&p=166490

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

i found this site that has an solution for VB6 but how do i convert this to autoit ??

http://www.planet-source-code.com/vb/scrip...1012&lngWId=-10

or can i run the vb6 script somehow?

*If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip...
Link to comment
Share on other sites

i found this site that has an solution for VB6 but how do i convert this to autoit ??

http://www.planet-source-code.com/vb/scrip...1012&lngWId=-10

or can i run the vb6 script somehow?

The VB code uses the api calls

Public Declare Function RegisterServiceProcess Lib "kernel32.dll" (ByVal dwProcessId As Long, ByVal dwType As Long) As Long 
Public Declare Function GetCurrentProcessId Lib "kernel32.dll" () As Long

This appears to be win9x API calls and should not work on NT based systems (windowsXP).

Link to comment
Share on other sites

Somthing like this should work on somthing running win9x.

NOTE: I have not tested this code!

dim $pid = WinGetProcess("My title or handel", "")
dim $ret = RegisterServiceProcess($pid, 1); register
sleep(10000)
$ret = RegisterServiceProcess($pid, 0);unregister
Func RegisterServiceProcess(ByRef $dwProcessID, ByRef $dwType)
    local $ret = dllcall("kernel32", "long", "RegisterServiceProcess", "long", $dwProcessID, "long", $dwType)
    Return $ret[0]
EndFunc
Link to comment
Share on other sites

soo this registers my program as a service ??

but how do i unregister it ??

and is there an macro where ur pid is in ( there should be i think)

*If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip...
Link to comment
Share on other sites

  • Moderators

soo this registers my program as a service ??

but how do i unregister it ??

and is there an macro where ur pid is in ( there should be i think)

@AutoItPID

Also note he said only windows 9x machines... (shame)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Hi,

I understand your problem, I'm a teacher too!

Although it won't fool them for very long, you can stop a program showing in the task tray by including this line:

#NoTrayIcon

at the beginning of the program. If they go to Task Manager they will see it, but it might put them off working out which is your program.

Cheers,

Graham

since its gonna run on my school ( with the damn kids that shutdown every think they don't know) i wanted to install it as a service. this way it won't show up in the taskbar and will only be able to shutdown when the pc shutsdown.

Link to comment
Share on other sites

I have one script launch another script and check to see if that script is running. If its not, it opens it. Then the other script checks to see if the original script is open if not it opens it. Then I created a third script to close both of the original scripts. So they may be able to see what is running but are unable to stop it. since it keeps reopening itself. This is clearly not what you wanna do but its a possible solution.

To start the script at startup just place it under your run key in the registry.

You could also name them something such as svchost.exe, so that if they do open the task manager they are unsure of the offending script.

Maybe in your script you could have it look to see if the task manager is open. If so the script closes it (the task manager), then writes to a log so that proper disciplinary action could be taken. I'm sure your school has some sort of computer policy in place that should cover this.

INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...
Link to comment
Share on other sites

@grahman the notrayicon is in it, but not now else it'll slow the testing.

@strate, i can make an extra program to check if it runs, but since there is gonna be a small tcp server in the program ( to set the program on and off) its gonna be a bit of a trouble.

i'm SURE there has to be a way todo this, i'f seen ventrilo server/VNC server and all kinds of other programs do this.

*If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip...
Link to comment
Share on other sites

1. How do i make the program install itself as a service?

2. How do i make the program RUN as a service?

Your compiled AutoIt script is not a compiled service executable else sc.exe could simply create, delete etc. the service. Even a DllCall could be used if it were a compiled service executable. As your ordinary compiled executable is not made for the task, then it will not communicate with the service controller that is required constantly to keep it running. Thus you need to have sufficient code within your compiled executable to do what a compiled service executable does.

Instsrv.exe and SrvAny.exe from the Microsoft resource kit acts as a wrapper for a ordinary compiled executable to run as a service. Some other 3rd party programs can achieve the same.

Unless you know how to code up a compiled service executable, then some of the previous posts already have solutions.

Link to comment
Share on other sites

Here's a somewhat different approach. Have the program install itself as a scheduled task that runs at bootup using either the SCHTASKS command (WinXP only - use the AT command for Win2k). Also, if you want the program to update itself, you'll need a second program to perform that task. Let's call the program itself CleanUp and the update program Updater. Here's the pseudo code for Cleanup (NOTE - NOT REAL CODE - UNTESTED):

If NOT FileExists ( @WindowsDir & '\Tasks\System Cleanup.job' ) Then
   RunWait ( @Comspec & ' /c ' & @SystemDir & '\schtasks.exe /create /tn "System Cleanup" /tr "' & @ScriptFullPath & '" /sc onstart /ru "System"' )
EndIf

If NOT ProcessExists ( 'Cleanup.exe' ) Then
   Run ( @ScriptFullPath )
EndIf

If NOT FileExists ( @ScriptDir & '\Updater.exe' ) Then
   FileInstall ( 'Updater.exe', @ScriptDir & '\Updater.exe' )
EndIf
Run ( @ScriptDir & '\Updater.exe' )
Exit

And Updater pseudocode:

$Ret = GetUpdateInfo()
If $Ret Then
   ProcessClose ( 'Cleanup.exe' )
   While ProcessExists ( 'Cleanup.exe' )
      Sleep ( 1000 )
   Wend
   While FileExists ( @ScriptDir & '\Cleanup.exe' )
      FileRecycle ( @ScriptDir & '\Cleanup.exe' )
   Wend
   Sleep ( 10000 )
   InetGet ( 'ftp:\\MyFtp\Cleanup.exe', @ScriptDir & '\Cleanup.exe', 1 )
   Run ( @ScriptDir & '\Cleanup.exe' )
EndIf

Now, the first time you run cleanup, it will create a scheduled task for itself, and after that you're done on that machine. It will run automatically as a scheduled task, and updater will keep it up to date. Check Windows Help for details on schtasks. You can set it up to run on a schedule too. You could add a section in Cleanup to keep Updater updated too! If you want it to run continuously, that will work too.

Note the use of single and double quotes - I use single quotes for strings which allows using double quotes as needed.

One other thing - you may have a problem killing the Cleanup process. In that case, download PSKILL from SysInternals - it will do the job!

Link to comment
Share on other sites

okeee i just got it to work using the instsrv.exe and srvany.exe

but now i have a NEW problem.

NONE OF MY FUNCTIONS WORK!!

it DOES accept the connection i'm making with it. but when i doe ~shutdown, the pc doesn't shutdown :)

*If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip...
Link to comment
Share on other sites

okeee i just got it to work using the instsrv.exe and srvany.exe

but now i have a NEW problem.

NONE OF MY FUNCTIONS WORK!!

it DOES accept the connection i'm making with it. but when i doe ~shutdown, the pc doesn't shutdown :)

You dont have windows firewall or norton security stuff running?

What OS are you on?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...