Windows Services & Other Stuff

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

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

Hi boyoss,

You're very much welcome.

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

Updated the Stuff folder:
- PrinterStuff\
-- PrinterStuff.pbi, AddMonitor.pb, DeleteMonitor.pb, AddPort.pb, DeletePort.pb, AddDriver.pb, UploadDriver.pb, InstallDriver.pb, DeleteDriver.pb
-- AddPrinter.pb, DeletePrinter.pb, SetSecurity.pb
-- MS_PS_CD_V3\... (required by AddDriver.pb)
-- MS_PS_CD_V4\... (required by UploadDriver.pb)

Based on a question asked here: Adding Port, Driver, Printer in Windows.

*** Tested in Windows 10 ***
- included driver files were taken from the Windows 10 OS

Instructions (order of execution is important):
- Setup
-- 1. AddMonitor.pb
-- 2. AddPort.pb
-- 3. AddDriver.pb: only needed if manually adding driver files
-- 3. UploadDriver.pb: only needed if driver is not in the Driver Repository
-- 3. InstallDriver.pb: only needed if driver is not already installed (not to be confused with an installed printer)
-- 4. AddPrinter.pb
-- 5. SetSecurity.pb: only needed if you want to restrict access, default security is ok for standard printing
- Cleanup
-- 1. DeletePrinter.pb
-- 2. DeleteDriver.pb: removes the installed driver (registry settings) not the actual files
-- 3. DeletePort.pb
-- 4. DeleteMonitor.pb

NOTE:
- Driver Repository: C:\WINDOWS\System32\DriverStore\FileRepository\...
- Printer Driver Directory: C:\Windows\System32\spool\drivers\x64\
-- identified using the Procedure GetDriverDirectory
- Important Registry Settings:
-- HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\...
-- HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\...

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; free executables, access key required for source code.
_________________
User avatar
JHPJHP
Addict
Addict
Posts: 1830
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

Updated Stuff\PrinterStuff\
- renamed 2 examples
-- UploadDriver.pb to UploadDriverPackage.pb
-- InstallDriver.pb to InstallDriverPackage.pb
- added 6 examples
-- GetDriver.pb
-- DeleteDriverPackage.pb
-- EnumerateMonitors.pb, EnumeratePorts.pb, EnumeratePrinters.pb, EnumerateDrivers.pb

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; free executables, access key required for source code.
_________________
boyoss
User
User
Posts: 74
Joined: Fri Feb 05, 2016 10:11 am

Re: Services, Stuff, and Shellhook

Post by boyoss »

Hi jhp thanks for your wonderful work!

Is it possible to create a service for an non-service exe?
I saw this software http://nssm.cc is doing it, but is it possible to do it with pb?
User avatar
JHPJHP
Addict
Addict
Posts: 1830
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

Hi boyoss,

Sorry, but there are too many questions floating around concerning your intentions, for me to feel comfortable helping you any further.

Either way its time to rethink your approach; you are either trying to program an ill-conceived idea, or an ineffectual virus.

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; free executables, access key required for source code.
_________________
walbus
Addict
Addict
Posts: 930
Joined: Sat Mar 02, 2013 9:17 am

Re: Services, Stuff, and Shellhook

Post by walbus »

Hi JHPJHP
boyoss wrote this:
i need this code for my program, i build a program for an office where i want to block internet on the computers, so the secretary will work and not wasting time in facebook etc.
for this i need to delete the restore points and create a new one, so they can't rool back the changements i made.
i can use a software that doing the work, but it's easyer for me to do all the work in my software.
Deleting restore points on a commercial used computer :evil:
User avatar
JHPJHP
Addict
Addict
Posts: 1830
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

Updated Stuff\
- renamed 2 examples
-- RestorePoints\PS_RestorePoints.pbi to PowerShell\RestorePoints\RestorePoints.pbi
-- RestorePoints\PS_CreateShowDelete.pb.pb to PowerShell\RestorePoints\CreateShowDelete.pb.pb
- added 1 example
-- PowerShell\SendHtmlEmail.pb

SendHtmlEmail.pb was based on a question asked here: How to use html in body of PB mail?

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; free executables, access key required for source code.
_________________
coder14
Enthusiast
Enthusiast
Posts: 327
Joined: Tue Jun 21, 2011 10:39 am

Re: Services, Stuff, and Shellhook

Post by coder14 »

Hi JHPJHP. When I tested the printer functions before - AddMonitor > AddPort > AddDriver > AddPrinter - they all worked.

But testing them again now AddDriver is giving a windows error 3014 (The printer driver is known to harm the system) and this message:
Driver Installation Error
Windows can't install the Miscrosoft PS Class Driver print driver. To obtain a driver that is compatible with the version of Windows your are running, contact the manufacturer.
I deleted all the monitors and ports and removed all the printers that I created - registry too - and tried again. But still getting the same error.

Any ideas why this is happening?

Windows 8.1 - tried with various versions of PB x86 and x64 Unicode & ASCII - Your original code unedited.
User avatar
JHPJHP
Addict
Addict
Posts: 1830
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

Hi coder14,

Make sure you have the latest version of PrinterStuff, there have been some changes.

Is this the same computer where it worked previously?
- if so, I cannot tell you what has changed on your system
Are you using the drivers I provided, or providing you own?
- depending on the answer to the first question... the drivers I provided came from Windows 10 and may not be compatible

It also sounds like you're using a Version-3 driver in a newer OS; you will get better compatibility using a Version-4 driver.
- instead of AddDriver.pb use InstallDriver.pb (may need to execute UploadDriver.pb first)

Creating your own driver package (Version-4):
- install the printer manually
- goto HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows x64\Drivers\Version-4\[PRINTER]
- find the String Value: InfPath (used in the example InstallDriverPackage.pb)
- copy the files from InfPath to a new folder (used in the example UploadDriverPackage.pb)
- remove the printer you manually created

NB*: I created the Version-3 driver package from the following folder in Windows 10: C:\Windows\System32\spool\drivers\x64\3\

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; free executables, access key required for source code.
_________________
coder14
Enthusiast
Enthusiast
Posts: 327
Joined: Tue Jun 21, 2011 10:39 am

Re: Services, Stuff, and Shellhook

Post by coder14 »

Thank you JHPJHP. I'm still working it out.
User avatar
JHPJHP
Addict
Addict
Posts: 1830
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

Updated the Stuff folder:
- AnimateGIF\AnimateGIF.pb

The Procedure AnimateGIF includes five parameters:
- GIFFolder: folder of GIF files [ mandatory ]
- GIFFile: animated GIF [ mandatory ]
- DisposalMethod: how cumulative layers are handled [ optional: default 0 ]
- DelayTime: delay between each frame [ optional: default -1 ]
- LoopAnimation: enable/disable continuous looping [ optional: default #True ]

The example is based on code found here with additional support from here.

NB*: You may find the code interesting if you are curious about working with Structures that include Bit fields.
Last edited by JHPJHP on Mon Feb 13, 2017 4:24 am, edited 8 times in total.

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; free executables, access key required for source code.
_________________
coder14
Enthusiast
Enthusiast
Posts: 327
Joined: Tue Jun 21, 2011 10:39 am

Re: Services, Stuff, and Shellhook

Post by coder14 »

Hello JHPJHP. I've been struggling with InstallDriver - it just doesn't work. The separate functions work but I don't know how to get the individual driver files (.DLL, .PPD, .NTF) for a specific printer. If I download a Xerox or HP driver I only get an .INF file - maybe to be used with InstallDriver.

The generic PS files (PS5UI.DLL, PSCRIPT5.DLL, PSCRIPT.NTF, MSXPSINC.PPD) work but outputs only mono prints - no color.

Which is the better way? MSDN recommends InstallPrinterDriverFromPackage but that is not backward compatible with XP. I think that the AddMonitor/AddPort/AddDriver/AddPrinter combination is still compatible with Windows 8 & 10 but I can't find the files.

Can you please point me right? :?
User avatar
JHPJHP
Addict
Addict
Posts: 1830
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

Hi coder14,

Version 3 drivers are not guaranteed to be compatible with Windows 7, 8, 10.

Use both solutions: OSVersion()
- install the printer manually in Windows XP... create a Version 3 driver package from the installed files
- install the printer manually in Windows 10... create a Version 4 driver package from the installed files

NB*: Refer to my previous post on this topic, for instructions on creating a driver package.
Last edited by JHPJHP on Mon Feb 13, 2017 4:55 am, edited 2 times in total.

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; free executables, access key required for source code.
_________________
User avatar
JHPJHP
Addict
Addict
Posts: 1830
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

Updated the Stuff folder:
- AnimateGIF\SplitGIF.pb

The Procedure SplitGIF includes three parameters:
- GIFFile: file to split [ mandatory ]
- ResetDisposal: removes all disposal settings [ optional: default #False ]
- ResetDelay: removes all delay times [ optional: default #False ]

Included with the examples are two animated GIFs:
- \images\Banana.gif
- \images\BugsBunny.gif
Last edited by JHPJHP on Mon Feb 13, 2017 4:24 am, edited 3 times in total.

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; free executables, access key required for source code.
_________________
User avatar
JHPJHP
Addict
Addict
Posts: 1830
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Services, Stuff, and Shellhook

Post by JHPJHP »

Updated:
- modified 2 examples
-- Stuff\AnimateGIF\AnimateGIF.pb
-- Stuff\AnimateGIF\SplitGIF.pb

Optimized the example AnimateGIF.pb.
- updated the Application Extension block based on data from Netscape Looping Application Extension

Fixed an issue in the example SplitGIF.pb that caused color distortions when the file included a local color table.
- based on information from What's In A GIF - Bit by Byte

** Tested both examples against a variety of GIF files without any noticable problems.

Cumulative Layers:
- change the DisposalMethod parameter if an animation isn't layering correctly

NB*: I've noticed with some files, setting a delay time of 1 or 2 will transition the frames faster then a setting of 0.

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; free executables, access key required for source code.
_________________
coder14
Enthusiast
Enthusiast
Posts: 327
Joined: Tue Jun 21, 2011 10:39 am

Re: Services, Stuff, and Shellhook

Post by coder14 »

JHPJHP wrote:Hi coder14,

Make sure you have the latest version of PrinterStuff, there have been some changes.

Is this the same computer where it worked previously?
- if so, I cannot tell you what has changed on your system
Are you using the drivers I provided, or providing you own?
- depending on the answer to the first question... the drivers I provided came from Windows 10 and may not be compatible

It also sounds like you're using a Version-3 driver in a newer OS; you will get better compatibility using a Version-4 driver.
- instead of AddDriver.pb use InstallDriver.pb (may need to execute UploadDriver.pb first)

Creating your own driver package (Version-4):
- install the printer manually
- goto HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows x64\Drivers\Version-4\[PRINTER]
- find the String Value: InfPath (used in the example InstallDriverPackage.pb)
- copy the files from InfPath to a new folder (used in the example UploadDriverPackage.pb)
- remove the printer you manually created

NB*: I created the Version-3 driver package from the following folder in Windows 10: C:\Windows\System32\spool\drivers\x64\3\
Hi JHPJHP. For compatibility with older Windows I'm sticking with V3 drivers. I copied 32bit and 64 bit drivers and the installer works on XP(x86), 7(x86), 8.1(x64) and 10(x64).

Uninstalling fails to remove the monitor and driver unless we reboot after deleting the printer and port. I tried restarting the spooler and that works too (but not on XP). Is there a way to do this through code (net start/stop spooler)?
Post Reply