Windows Services & Other Stuff

Developed or developing a new product in PureBasic? Tell the world about it.
User avatar
JHPJHP
Addict
Addict
Posts: 2250
Joined: Sat Oct 09, 2010 3:47 am

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

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

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
User avatar
JHPJHP
Addict
Addict
Posts: 2250
Joined: Sat Oct 09, 2010 3:47 am

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

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: Select all

IterateSubfolders   = #True
MaxFolderSize.q     = 104857600
RootFolder.s        = "MemoryFolder"
Last edited by JHPJHP on Thu Oct 20, 2016 8:24 pm, edited 1 time in total.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
User avatar
JHPJHP
Addict
Addict
Posts: 2250
Joined: Sat Oct 09, 2010 3:47 am

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

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)
Last edited by JHPJHP on Tue Oct 25, 2016 8:33 am, edited 3 times in total.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
User avatar
JHPJHP
Addict
Addict
Posts: 2250
Joined: Sat Oct 09, 2010 3:47 am

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

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
Last edited by JHPJHP on Tue Oct 25, 2016 1:24 pm, edited 3 times in total.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
User avatar
JHPJHP
Addict
Addict
Posts: 2250
Joined: Sat Oct 09, 2010 3:47 am

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

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

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
User avatar
JHPJHP
Addict
Addict
Posts: 2250
Joined: Sat Oct 09, 2010 3:47 am

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

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

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
User avatar
JHPJHP
Addict
Addict
Posts: 2250
Joined: Sat Oct 09, 2010 3:47 am

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

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.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
boyoss
User
User
Posts: 81
Joined: Fri Feb 05, 2016 10:11 am

Re: Services, Stuff, and Shellhook

Post by boyoss »

Thank you very much it's wonderfull!!

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

Code: Select all

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?
User avatar
JHPJHP
Addict
Addict
Posts: 2250
Joined: Sat Oct 09, 2010 3:47 am

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

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
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.
Last edited by JHPJHP on Wed Jan 11, 2017 4:40 am, edited 1 time in total.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
boyoss
User
User
Posts: 81
Joined: Fri Feb 05, 2016 10:11 am

Re: Services, Stuff, and Shellhook

Post by boyoss »

Yes, i need help to run the net command ftom purebasic.
Thank you very much
User avatar
JHPJHP
Addict
Addict
Posts: 2250
Joined: Sat Oct 09, 2010 3:47 am

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

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

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
boyoss
User
User
Posts: 81
Joined: Fri Feb 05, 2016 10:11 am

Re: Services, Stuff, and Shellhook

Post by boyoss »

i'm sorry i didn't understand
you mean you have a function NetStop(service.s)?
i don't see it??
User avatar
JHPJHP
Addict
Addict
Posts: 2250
Joined: Sat Oct 09, 2010 3:47 am

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

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.
Last edited by JHPJHP on Thu Jan 12, 2017 10:22 pm, edited 1 time in total.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
boyoss
User
User
Posts: 81
Joined: Fri Feb 05, 2016 10:11 am

Re: Services, Stuff, and Shellhook

Post by boyoss »

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

Code: Select all

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
User avatar
JHPJHP
Addict
Addict
Posts: 2250
Joined: Sat Oct 09, 2010 3:47 am

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

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: Select all

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)

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
Locked