PureBasic Forum
http://forums.purebasic.com/english/

Windows Services & Other Stuff
http://forums.purebasic.com/english/viewtopic.php?f=12&t=60881
Page 3 of 7

Author:  JHPJHP [ Wed Oct 05, 2016 6:22 pm ]
Post subject:  Re: Services, Stuff, and Shellhook

Updated:
- renamed 1 example
-- Stuff\AESEncryption\EncryptDecrypt.pb to Stuff\AESEncryption\AES_EncoderDecoder.pb
- added 2 examples
-- Stuff\AESEncryption\AES_CipherBuffer.pb
-- Stuff\OtherStuff\PlotCurve.pb: based on an equation found here

Plot Curve Function:
- used in PureBasic Interface to OpenCV to enhance the morphing examples

Author:  JHPJHP [ Tue Oct 18, 2016 11:27 pm ]
Post subject:  Re: Services, Stuff, and Shellhook

Updated:
- added 3 examples
-- Stuff\MemoryFolder\MemoryFolder.pb
-- Stuff\OtherStuff\CompressUncompress.pb
-- Stuff\OtherStuff\GetFolderSize.pb

Currently LSB (Least Significant Bit) File Embedding doesn't support embedding folders. While it does allow for embedding zipped folders, I wanted a way to compress a folder in memory without first writing to disk or requiring user-interaction.

MemoryFolder.pb:
- write a folder, subfolders, and files to memory
- compress the memory
- uncompress the memory
- recreate the folder, subfolders, and files to a specified location

The following options can be configured to suit requirements.
- Iterate Subfolders: empty folders are ignored
- Max Folder Size: 150MB or less
- Root Folder: folder path, new folder name, folder path \ new folder name
Code:
IterateSubfolders   = #True
MaxFolderSize.q     = 104857600
RootFolder.s        = "MemoryFolder"

Author:  JHPJHP [ Fri Oct 21, 2016 3:58 am ]
Post subject:  Re: Services, Stuff, and Shellhook

Updated:
- added 2 examples
-- Stuff\iPhoneIV\iPhoneIV.pb
-- Stuff\WebSnapshot\WebSnapshot.pb

iPhoneIV.pb (iPhone Image Viewer)
- press the iPhone Home button to slide between images
- press the Esc key to close the window

WebSnapshot.pb
- save a snapshot of a webpage regardless of scroll area

Based on script found here by Kiffi.
- fixed a bug in the original code not correctly calculating height with some webpages (e.g. https://en.wikipedia.org/wiki/PureBasic)

Author:  JHPJHP [ Fri Oct 21, 2016 7:55 pm ]
Post subject:  Re: Services, Stuff, and Shellhook

Updated Stuff\iPhoneIV\iPhoneIV.pb (iPhone Image Viewer)
- renamed the example Stuff\PNGWindow\PNGWindow.pb to Stuff\PhoneIV\PhoneIV.pb
- fixed a bug with the iPhone Home button

Author:  JHPJHP [ Mon Oct 24, 2016 8:30 am ]
Post subject:  Re: Services, Stuff, and Shellhook

Updated:
- added 1 example
-- Stuff\InflateDeflate\InflateDefalte.pb

This example creates a gzip (*.gz) compressed file to the current folder, and an uncompressed version of the original file.
- the windowBits parameter determines the format: see zlib Manual
Quote:
-- 8..15 = zlib format
-- 24..31 = gzip format
-- -8..-15 = raw zlib format with no header

NB*: Originally used in PureBasic Interface to WinDivert to compress and decompress webpages; updated to work with any file.

------------------------------------------------------------------------------

Updated:
- OSX compatible
- added additional OS Constants: GZIP file format specification version 4.3
- added header Procedures
- fixed a bug that caused the header filename to display incorrectly

NB*: Enable Debug to view header data.

Author:  JHPJHP [ Tue Oct 25, 2016 1:16 pm ]
Post subject:  Re: Services, Stuff, and Shellhook

Updated Stuff\iPhoneIV\iPhoneIV.pb (iPhone Image Viewer)
- added the option to toggle between Portrait and Landscape
-- press the Spacebar to switch orientation
- added image scaling on resize
- added a couple sound effects

Image

Author:  JHPJHP [ Tue Jan 10, 2017 8:06 pm ]
Post subject:  Re: Services, Stuff, and Shellhook

Updated the first post:
- added individual download links to all parts of the package

NB*: Some of the download links contain executables (source code included), and may be flagged by your AV software.

Author:  boyoss [ Tue Jan 10, 2017 10:34 pm ]
Post subject:  Re: Services, Stuff, and Shellhook

Thank you very much it's wonderfull!!

i'm using a batch script for starting and stopping services:


Code:
stop
sc config dhcp start= disabled
net stop dhcp /y
start
sc config dhcp start= auto
net start dhcp /y


it seems your code is only doing the first line, sc, how can i do also the second line, net?

Author:  JHPJHP [ Wed Jan 11, 2017 1:38 am ]
Post subject:  Re: Services, Stuff, and Shellhook

Hi boyos,

The following is from the first post... or is there something else you need help with?

Services:
- WindowsServices.pbi (ServiceStatusEnum, ServiceCreate, ServiceDelete, ServiceStatus, ServiceStartup, ServiceStart, ServiceStop)
- TestService.pb: example to create a service
- binaries\
-- TestJHP_EXE.pb : TestJHP.exe
--- example program run as a service
-- TestJHPService_EXE.pb : TestJHPService.exe
--- example service used to execute: TestJHP.exe
Quote:
This window / executable is being run from a service.

If the window is closed, it will reopen within 10 seconds.

The service is being executed using the current user's credentials.

Run the file: TestService.pb a second time to delete the service.

The following is a list of services created using the ServiceStatusEnum Procedure.

Author:  boyoss [ Wed Jan 11, 2017 1:42 am ]
Post subject:  Re: Services, Stuff, and Shellhook

Yes, i need help to run the net command ftom purebasic.
Thank you very much

Author:  JHPJHP [ Wed Jan 11, 2017 4:47 am ]
Post subject:  Re: Services, Stuff, and Shellhook

Hi boyos,

I'm assuming you mean the START and STOP parameters of the NET command used for a service :?:
- if so the equivalent Procedures are located in the file WindowsServices.pbi (recently updated)
Quote:
The syntax of this command is:
NET
[ ACCOUNTS | COMPUTER | CONFIG | CONTINUE | FILE | GROUP | HELP |
HELPMSG | LOCALGROUP | PAUSE | SESSION | SHARE | START |
STATISTICS | STOP | TIME | USE | USER | VIEW ]

I've also updated the SERVICES section of the package to include an additional example.
- StartStopService.pb: example to stop then start a service

NB*: Some filenames have been changed.

Author:  boyoss [ Wed Jan 11, 2017 2:18 pm ]
Post subject:  Re: Services, Stuff, and Shellhook

i'm sorry i didn't understand
you mean you have a function NetStop(service.s)?
i don't see it??

Author:  JHPJHP [ Wed Jan 11, 2017 3:31 pm ]
Post subject:  Re: Services, Stuff, and Shellhook

Hi boyos,

If you haven't already done so, download the updated SERVICES section of the package.

The two files you will need to review:
- StartStopService.pb: example script-file testing three of the Procedures from WindowsServices.pbi
-- ServiceStatus, ServiceStop, ServiceStart
- WindowsServices.pbi: include-file hosting Structures, and Procedures interfacing Windows (service) API's

Run the file StartStopService.pb for a working example on starting and stopping a service, but notice the main body of work is from the Include file WindowsServices.pbi.

NB*: In order to interface Windows API's, a licenced version of PureBasic is required, the demo version excludes this feature.

Author:  boyoss [ Wed Jan 11, 2017 10:27 pm ]
Post subject:  Re: Services, Stuff, and Shellhook

i'm sorry, but i think i need also the "net" command, because when i stop the services, they restart automaticly.

Code:
IncludeFile "plus\WindowsServices.pbi"
services.s = "dhcp dnscache netman netprofm nsi webclient wlansvc rasauto rasman IKEEXT sstpsvc wcmsvc"

Procedure yhe_service(services.s, mode.l)
   Define.l i, result
   Define.s service, success, not_success
   
   
   
   For i = 1 To CountString(services, " ") + 1
      service = StringField(services, i, " ")
      Select mode
         Case 0
            If ServiceStop(service) : success + service + " " : Else : not_success + service + " " : EndIf
         Case 1
            If ServiceStart(service) : success + service + " " : Else : not_success + service + " " : EndIf
         Case 2
            Select ServiceStatus(service)
               Case "The service is running." : success + service + " "
               Case "The service is stopped." : not_success + service + " "
            EndSelect
      EndSelect
   Next
   
   Debug "OK: " + success
   Debug "ERROR: " + not_success
EndProcedure

yhe_service(services, 0); stop
;yhe_service(services, 1); start
yhe_service(services, 2); check



thanks

Author:  JHPJHP [ Wed Jan 11, 2017 11:14 pm ]
Post subject:  Re: Services, Stuff, and Shellhook

Hi boyoss,

Try the following:
- make sure to set Request Administrator mode for Windows Vista and above from Compiler Options

NOTE: Services such as DHCP have dependencies services, and may need a greater timeout then the current 60 seconds to report the status accurately
- you can try running the script a second time to see if the service is "stop pending"
- some services may have a timed-restart or cannot be stopped
Code:
IncludeFile "WindowsServices.pbi"

Procedure set_service(services.s, mode)
  Define.s service, status

  Debug "STARTED" + #LF$

  For i = 1 To CountString(services, " ") + 1
    service = StringField(services, i, " ")
    status = ServiceStatus(service)
    nTimeOut = ElapsedMilliseconds()

    Select mode
      Case 0
        If status = "The service is running."
          Debug service + " [ STOP ] working..."
          ServiceStop(service)

          Repeat
            Delay(100) : status = ServiceStatus(service)
          Until status <> "The service is running." Or ElapsedMilliseconds() - nTimeOut > 60000
          Debug service + ": " + ServiceStatus(service) + #LF$
        Else
          Debug service + ": The service is not running (" + status + ")" + #LF$
        EndIf
      Case 1
        If status = "The service is stopped."
          Debug service + " [ START ] working..."
          ServiceStart(service)

          Repeat
            Delay(100) : status = ServiceStatus(service)
          Until status = "The service is running." Or ElapsedMilliseconds() - nTimeOut > 60000
          Debug service + ": " + ServiceStatus(service) + #LF$
        Else
          Debug service + ": The service is not stopped (" + status + ")" + #LF$
        EndIf
    EndSelect
  Next
  Debug "COMPLETED"
EndProcedure

services.s = "dhcp dnscache netman netprofm nsi webclient wlansvc rasauto rasman IKEEXT sstpsvc wcmsvc"
set_service(services, 0)

Page 3 of 7 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/