Windows Services & Other Stuff

Developed or developing a new product in PureBasic? Tell the world about it.
Mythros
Enthusiast
Enthusiast
Posts: 306
Joined: Mon Aug 19, 2013 3:28 pm

Re: Services, Stuff, and Shellhook

Post by Mythros »

Sweet, is there a way this can be used for example to check whether 2 same processes are open at once?
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

Hi Mythros,

Stuff Folder:
- GetProcessPath.pb can be used to check for a running PATH\executable
- ProcessList.pb can be used to check for a running executable

Shellhook Folder
- shellhook.pb includes the following FindWindow Procedure

Code: Select all

Procedure FindWindow(WindowName.s)
  Protected hWnd

  hWnd = GetWindow_(GetDesktopWindow_(), #GW_CHILD)

  Repeat
    winCaption.s = Space(#MAX_PATH)
    GetWindowText_(hWnd, winCaption, #MAX_PATH)

    If Len(Trim(winCaption)) > 0
      If FindString(winCaption, WindowName) > 0 : Break : EndIf
    EndIf
    hWnd = GetWindow_(hWnd, #GW_HWNDNEXT)
  Until hWnd = 0
  ProcedureReturn hWnd
EndProcedure

hWnd = FindWindow("Window Watcher")

If hWnd
  MessageBox_(hWnd, "The application is already running.", "Window Watcher", #MB_ICONWARNING)
EndIf
Another option may be to use either the CreateMutex or FindWindow function.
- CreateMutex: http://msdn.microsoft.com/en-us/library ... s.85).aspx
-- test for: GetLastError = ERROR_ALREADY_EXISTS
- FindWindow: http://msdn.microsoft.com/en-us/library ... s.85).aspx
-- test for: return value NOT NULL
Last edited by JHPJHP on Thu Nov 20, 2014 2:10 am, edited 1 time in total.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

Updated the Services scripts to be more intuitive and easier to use.

See the first post for a more in-depth description.

Cheers!
User avatar
Rings
Moderator
Moderator
Posts: 1427
Joined: Sat Apr 26, 2003 1:11 am

Re: Services, Stuff, and Shellhook

Post by Rings »

thx a lot
SPAMINATOR NR.1
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

Hi Rings,

You're welcome, and thank you for your many positive comments across my "Tricks 'n' Tips" posts.

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

The following are some simple examples that may help a beginner with learning PureBasic:
- updated the Stuff folder

Added 3 additional script files and 1 image file.
- GlobalKeyboardHook.pb: global keyboard hook capturing keystrokes
-- currently set to capture: A - Z, ESC to quit
- RotateImage.pb: 90, 180, 270, and flip
-- logo.jpg: image used by: RotateImage.pb
- TreeGadget_Sync.pb: 2 TreeGadget's synced

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

Here is another example added to the Stuff folder.
- ADS.pb: (Windows) Alternate Data Streams
-- http://www.bleepingcomputer.com/tutoria ... a-streams/

The example demonstrates one approach to hide / link an executable to a text file, but the process is not limited to text / executable files.
- read the documentation to better understand the application and dangers with using this method
Last edited by JHPJHP on Mon Dec 29, 2014 6:46 pm, edited 1 time in total.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

Added another three examples to the folder: Stuff
- CacheChrome.pb
- CacheExplorer.pb
- AlwaysOnTop.pb

Both cache examples list browser cache with the option to delete.
- unlike other browsers Google Chrome uses SQLite to store cache

AlwaysOnTop.pb: Tries to set the window using the current thread as the active window.

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

Updated all the examples to work with Windows 8.
- an additional update was made to the service example
-- #SC_MANAGER_ALL_ACCESS was changed to #SC_MANAGER_ENUMERATE_SERVICE
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

Added another three examples to the folder: Stuff
- RunElevated.pb: run an executable in an elevated process using the Function: ShellExecuteEx
- SetManifest.pb: set a manifest file to an executable
- IsOS64Bit.pb: returns true if the OS is 64 bit otherwise false

I used the RunElevated & SetManifest scripts in the latest update to PureBasic Interface to WinDivert.

Information:
- http://mfctips.com/2013/01/04/createpro ... -manifest/
- http://msdn.microsoft.com/en-us/library ... 85%29.aspx
-- tool to view manifest in binary: http://www.angusj.com/resourcehacker/

Running the example: SetManifest.pb on the current folder will set: rpau.manifest to the executable: rpau.exe.

I used the IsOS64Bit script in updating the example: GetProcessCL.pb.
- http://stackoverflow.com/questions/1581 ... -or-64-bit

NB*: Numerous other improvements have been made to various examples.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

Added another example to the Stuff folder:
- ListIconGadget_Move.pb: allows the moving of multiple selected items [ CTRL / SHIFT ]

NB*: Update also includes numerous improvements and bug fixes to various examples.
Last edited by JHPJHP on Wed Feb 18, 2015 5:45 am, edited 3 times in total.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

Updated:
- GetExternalIP.pb: get the external IP Address using DNS
- WebGadget_NoScroll.pb: remove scrolling / scrollbars from the webgadget
Last edited by JHPJHP on Wed Feb 18, 2015 6:02 am, edited 2 times in total.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

Added another couple examples to the Stuff folder:
- MovieData
-- Alternate Data Stream (folder: ADS)
--- folder: videos
---- walking.avi
--- MovieData.pb
---- MovieData.exe
--- ADS.pb
-- DataSection (folder: DS)
--- MovieData.pb
---- MovieData.exe
--- DataSection.pbi

The example: MovieData.pb was from a question asked here: http://www.purebasic.fr/english/viewtop ... 78#p459078

The ADS folder example uses an Alternate Data Stream to conceal the video file.
- the current executable: MovieData.exe will not work because zip files do not include ADS
-- if I chose to compress using WinRAR the option to include ADS is available
- recompile the file: MovieData.pb (MovieData.exe) then add the ADS by running the file: ADS.pb

The DS folder example uses a DataSection to conceal the video file.
- the example highlights PureDataConverter by ts-soft

NB*: In both examples the temp file is created in the current directory, but this should be changed for better concealment.
- Function: GetTemporaryDirectory
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

Added another three examples to the Stuff folder.
- folder: MoreStuff
-- AWS.pb: (Amazon Web Services) used to retrieve a variety of information
--- utilizes the script (HMAC_SHA1 Procedure) by hss: http://www.purebasic.fr/english/viewtop ... 12&t=46460
-- CreateMountableImage.pb: creates a mountable image file from a folder location
--- bingo did it first: http://www.purebasic.fr/english/viewtopic.php?t=29757
-- Power2Bitwise.pb: extracted from: PureBasic Interface to ImDisk

AWS.pb
- the following information will need to be filled in for the example to work

Code: Select all

SecretAccessKey.s = ""
AWSAccessKeyId.s = ""
AssociateTag.s = ""
CreateMountableImage.pb
- a mountable image file cannot be created from a drive-root, or a circular reference

Power2Bitwise.pb

I asked myself this question: If given a number that is the total sum of a group of numbers, how can I extract the individual numbers?

General information:
- counting by powers of two: 1, 2, 4, 8, 16, 32, 64, 128, 256, ...
-- every leading number is greater (by 1) then the sum of all the previous numbers combined

Power of Two / Bitwise:
- Value = Pow(2, nCount) (starting from 0)
-- nCount: the position in the series you want returned: Pow(2, 6) = 64
- (Value & Sum) = Value (Bitwise comparison)
-- Value: the number you want to test is included in the Sum
-- Sum: the sum of various numbers from the series

NB*: I've use the "Power of Two / Bitwise" technique in conjunction with a database to control access privileges, track various auditing information, etc.
Last edited by JHPJHP on Thu Nov 30, 2017 5:35 pm, edited 2 times in total.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

Added another two examples to the Stuff folder:
- WindowStuff/TimerStuff
-- messagebox.pb
-- splash.pb
--- processing.gif

splash.pb: from a question asked here: http://www.purebasic.fr/english/viewtop ... =7&t=61565
- a timed splash window created in a separate thread

messagebox.pb: something I was going to use in: PureBasic Interface to UnRAR (WinRAR)
- a timed message box created in a separate thread
Last edited by JHPJHP on Wed Feb 18, 2015 5:43 am, edited 2 times in total.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

Added another four examples to the Stuff folder:
- SendToNotepad
-- SendToNotepad.pb
--- gpl.txt (test file)
- WindowStuff/CopyData
-- Text_Send.pb, Text_Receive.pb
- WindowStuff/ShareMemory
-- Image_Send.pb, Image_Receive.pb, baboon.jpg
-- Text_Send.pb, Text_Receive.pb

SendToNotepad
- Open / change the Title of Notepad / Work with an opened instance of Notepad
-- RunNotepad: two optional parameters (Title.s, nDelay)
- Append (newline)
-- WriteToNotepad: nStart < 0 (default) / nLength < 0 (default)
- Prepend (newline)
-- WriteToNotepad: nStart = 0 / nLength < 0 (default)
- Replace
-- WriteToNotepad: nStart >= 0 / nLength > 0
- ReplaceAll
-- WriteToNotepad: nStart = 0 / nLength = 0
- Insert
-- WriteToNotepad: nStart > 0 / nLength <= 0 (default)

ShareMemory
- CopyData examples pass text from one PureBasic window to another.
- ShareMemory examples pass text / images from one PureBasic window to another

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

Updated the Share Memory examples.
- Image_Send.pb: includes the option to change images
- Image_Receive.pb: includes a separate thread to monitor changes
Last edited by JHPJHP on Wed Feb 18, 2015 1:29 am, edited 4 times in total.
marroh
User
User
Posts: 72
Joined: Wed Aug 06, 2008 8:21 am

Re: Services, Stuff, and Shellhook

Post by marroh »

Thx for update and share :mrgreen:
PureBASIC v5.41 LTS , Windows v8.1 x64
Forget UNICODE - Keep it BASIC !
Locked