if is on will turn it off,if is off will turn it on ! the ideea is a switch
Compile it and/OR run it from anywhere of your computer ... theoretically must work ...
Here is the code ...
Code: Select all
DisableDebugger
Global resultnet=InitNetwork()
Global xampppath.s="c:\xampp\"
Global apachepath.s="c:\xampp\apache\bin\"
Global mysqlpath.s="c:\xampp\mysql\bin\"
Global mysql=0
Global apache=0
Global standbysw=0
 Procedure.l port(port)
  If (Con = OpenNetworkConnection("127.0.0.1", Port)) = 0
  ProcedureReturn 0
  Else
  ProcedureReturn 1
  EndIf
  CloseNetworkConnection(Con)
EndProcedure
;Debug port(80)
;Debug port(3306)
Procedure.l apache(state.l)
iserror=0;success
If(state=1)
  If(Not(port(80)))
    RunProgram("httpd.exe","--defaults-file="+Chr(34)+"..\conf\httpd.conf"+Chr(34)+"  --standalone",apachepath,#PB_Program_Hide)
    Delay(50)
  Else
    iserror=1;it's already running
  EndIf
  apache=1
Else
  If(port(80))
    RunProgram("taskkill","/f /im httpd.exe","",#PB_Program_Hide)
    Delay(50)
  Else
    iserror=2;nothing to stop
  EndIf
  apache=0
EndIf
Delay(10)
ProcedureReturn iserror
EndProcedure
Procedure.l mysql(state.l)
iserror=0;success
If(state=1)
  If(Not(port(3306)))
    RunProgram("mysqld.exe","--defaults-file="+Chr(34)+"my.ini"+Chr(34),mysqlpath,#PB_Program_Hide)
    Delay(50)
  Else
    iserror=1;it's already running
  EndIf
  mysql=1
Else
  If(port(3306))
    RunProgram("taskkill","/f /im mysqld.exe","",#PB_Program_Hide)
    Delay(50)
  Else
    iserror=2;nothing to stop
  EndIf
  mysql=0
EndIf
Delay(10)
ProcedureReturn iserror
EndProcedure
Procedure startserver()
  apache(1):Delay(700):mysql(1):Delay(1000)
  ;waituntilport(80,1):waituntilport(3306,1)
  Delay(500)
  standbysw=1
  End
EndProcedure
Procedure stopserver()
  Repeat
    apache(0):mysql(0)
    Delay(200)
    ;If(apache=0)And(mysql=0)
    If(Not(port(3306))) And (Not(port(3306)))
    ProcedureReturn
    EndIf
  Until 1
  Delay(500)
  standbysw=1
    ;waituntilport(80,0):waituntilport(3306,0)
EndProcedure
;Debug apache(1):Debug mysql(1):waituntilport(80,1):waituntilport(3306,1)
;Debug apache(1):Debug mysql(1):waituntilport(80,1):waituntilport(3306,1)
;Debug apache(0):Debug mysql(0):waituntilport(80,0):waituntilport(3306,0)
If(Not(port(3306))) And (Not(port(3306)))
thread = CreateThread(@startserver(), 500)
  If thread
        Delay(2000)
        Repeat
        Delay(5)
        Until standbysw=1
        KillThread(thread)
  EndIf
 
Else
thread = CreateThread(@stopserver(), 500)
    If thread
          Delay(2000)
          Repeat
          Delay(5)
          Until standbysw=1
          KillThread(thread)
    EndIf
EndIf
End
EnableDebugger
The spy,
TOVARISH GENERAL CULITA


