Question screensaver .scr parameters not working in VB.net

remusrigo

New member
Joined
Jun 18, 2025
Messages
1
Programming Experience
Beginner
Hi all
I am trying to create a screensaver in vb.net but when I want to implement the /c /p parameters, they don't work. The main app, screensaver.exe is renamed to screensaver.scr and when I rightclick Install from the context menu, the Screen Saver Settings appears. If I click on settings or on preview nothing happens (mostly). Some times the config form shows.
- the project is set to x86
- unchecked Application Framework

frmSS is the main form
frmCfg is the config form
modParam is the main module that has the Sub Main()

vbproj:
XML:
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net9.0-windows</TargetFramework>
    <RootNamespace>TestSS</RootNamespace>
    <StartupObject>TestSS.modParam</StartupObject>
    <UseWindowsForms>True</UseWindowsForms>
    <MyType>WindowsFormsWithCustomSubMain</MyType>
    <RunPostBuildEvent>Always</RunPostBuildEvent>
    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
    <Platforms>x86</Platforms>      
  </PropertyGroup>
modParam.vb
VB.NET:
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports System.Diagnostics
Module modParam
   Public Sub Main()
      Dim args() As String = Environment.GetCommandLineArgs()
      System.IO.File.AppendAllText("D:\My Projects\Test\bin\TestLog.txt", DateTime.Now.ToString() & "Executable: " & Application.ExecutablePath & vbCrLf)

      Dim currentProcess As Process = Process.GetCurrentProcess()
      Dim runningProcesses() As Process = Process.GetProcessesByName(currentProcess.ProcessName)

      If runningProcesses.Length > 1 Then
         Exit Sub
      End If

      System.IO.File.AppendAllText("D:\My Projects\Test\bin\TestLog.txt", DateTime.Now.ToString() & "Args: " & String.Join(" ", args) & vbCrLf)

      If args.Length > 1 Then
         Dim cmd As String = args(1).ToLower()

         Select Case cmd
            Case "/s"
               System.IO.File.AppendAllText("D:\My Projects\Test\bin\TestLog.txt", DateTime.Now.ToString() & " - /s triggered" & Environment.NewLine)
               Application.Run(New frmCfg())

            Case "/c"
               Try
                  System.IO.File.AppendAllText("D:\My Projects\Test\bin\TestLog.txt", DateTime.Now.ToString() & " - /c triggered" & Environment.NewLine)
                  Dim newFrmCfg = New frmCfg()
                  newFrmCfg.ShowDialog()
               Catch ex As Exception
                  System.IO.File.AppendAllText("D:\My Projects\Test\bin\TestLog.txt", DateTime.Now.ToString() & " - /c error: " & ex.Message & Environment.NewLine)
               End Try
               Application.Exit()

            Case "/p"
               If args.Length > 2 Then
                  System.IO.File.AppendAllText("D:\My Projects\Test\bin\TestLog.txt", DateTime.Now.ToString() & " - /p triggered" & Environment.NewLine)
                  Try
                     Dim previewHwnd As IntPtr = CType(Integer.Parse(args(2)), IntPtr)
                     Dim newFrmSS = New frmSS(previewHwnd)
                     Application.Run(newFrmSS)
                  Catch ex As FormatException
                     System.IO.File.AppendAllText("D:\My Projects\Test\bin\TestLog.txt", DateTime.Now.ToString() & " - Invalid window handle for preview mode" & ex.Message & Environment.NewLine)
                     Dim newFrmSS = New frmSS()
                     Application.Run(newFrmSS)
                  End Try
               Else
                  System.IO.File.AppendAllText("D:\My Projects\Test\bin\TestLog.txt", DateTime.Now.ToString() & " - Missing window handle for preview mode" & Environment.NewLine)
                  Dim newFrmSS = New frmSS()
                  Application.Run(newFrmSS)
               End If

            Case Else
               System.IO.File.AppendAllText("D:\My Projects\Test\bin\TestLog.txt", DateTime.Now.ToString() & " - unkown trigger" & Environment.NewLine)
               Application.Run(New frmCfg())
         End Select
      Else
         System.IO.File.AppendAllText("D:\My Projects\Test\bin\TestLog.txt", DateTime.Now.ToString() & " - no trigger" & Environment.NewLine)
      End If
   End Sub

End Module

log file:
2025-06-18 20:28:17Executable: D:\My Projects\Test\bin\x86\Release\net9.0-windows\TestSS.scr
2025-06-18 20:28:18Args: D:\My Projects\Test\bin\x86\Release\net9.0-windows\TestSS.dll /p 133040
2025-06-18 20:28:18 - /p triggered
2025-06-18 20:28:19Executable: D:\My Projects\Test\bin\x86\Release\net9.0-windows\TestSS.scr
2025-06-18 20:28:20Executable: D:\My Projects\Test\bin\x86\Release\net9.0-windows\TestSS.scr
2025-06-18 20:28:22Executable: D:\My Projects\Test\bin\x86\Release\net9.0-windows\TestSS.scr
2025-06-18 20:28:22Executable: D:\My Projects\Test\bin\x86\Release\net9.0-windows\TestSS.scr
2025-06-18 20:28:24Executable: D:\My Projects\Test\bin\x86\Release\net9.0-windows\TestSS.scr
2025-06-18 20:28:24Executable: D:\My Projects\Test\bin\x86\Release\net9.0-windows\TestSS.scr
2025-06-18 20:28:26Executable: D:\My Projects\Test\bin\x86\Release\net9.0-windows\TestSS.scr
2025-06-18 20:28:27Executable: D:\My Projects\Test\bin\x86\Release\net9.0-windows\TestSS.scr
2025-06-18 20:28:28Executable: D:\My Projects\Test\bin\x86\Release\net9.0-windows\TestSS.scr
2025-06-18 20:28:29Executable: D:\My Projects\Test\bin\x86\Release\net9.0-windows\TestSS.scr
2025-06-18 20:28:30Executable: D:\My Projects\Test\bin\x86\Release\net9.0-windows\TestSS.scr
2025-06-18 20:28:30Executable: D:\My Projects\Test\bin\x86\Release\net9.0-windows\TestSS.scr
2025-06-18 20:28:40Executable: D:\My Projects\Test\bin\x86\Release\net9.0-windows\TestSS.scr
2025-06-18 20:28:40Args: D:\My Projects\Test\bin\x86\Release\net9.0-windows\TestSS.dll
2025-06-18 20:28:40 - no trigger
2025-06-18 20:28:47Executable: D:\My Projects\Test\bin\x86\Release\net9.0-windows\TestSS.scr
2025-06-18 20:28:47Args: D:\My Projects\Test\bin\x86\Release\net9.0-windows\TestSS.dll /S
2025-06-18 20:28:47 - /s triggered


As you can see if a parameter is called, it is redirected to the dll file!!??

Can anyone help me out?
Or redirect me to a tutorial?
 
Last edited by a moderator:
Back
Top