Protect Your Screen Saver From Restarting

Protect Your Screen Saver From Restarting

When you create a screen saver in Visual Basic, you may sometimes utilize the command-line options such as “/s” to start a screen saver directly or “/c” to run the configuration. By simply using App.PrevInstance, your application may not detect the running screen saver and attempt to start another when the normal Windows screen saver time-out occurs. To ensure that Windows will detect the running screen saver, regardless of the use of command-line options, use this code:

 Private Declare Function GetModuleHandle% Lib "Kernel" _	(ByVal lpModuleName$)Private Declare Function GetModuleUsage% Lib "Kernel" _	(ByVal hModule%)Sub StartUp()Dim Inst%	Inst = GetModuleHandle(App.Path + _		"" + CStr(Trim(App.EXEName) + ".scr"))	If GetModuleUsage_		(GetModuleHandle(App.Path + "" _		+ CStr(Trim(App.EXEName) + ".scr"))) > 1 Then EndEnd Sub

Call the sub like this:

 Sub Main()	Call StartUpEnd 

This method works well with Windows 3.11. You can use this basic idea with any application you write, not just screen savers.

See also  Essential Measures for Safeguarding Your Digital Data

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist