问题
I am creating a program in C#.Net, one of the features allows a user to select a screensaver from a list and either preview or configure it. After doing some research I found that by calling the *.scr file with the "/c" argument will display the configuration dialog.
Using this argument from the command line works fine ("C:\Windows\System32>PhotoScreensaver.scr /c") but calling this from C# will always result in the screensaver being simply displayed as though the argument is just being ignored.
The code I am using is this:
Process.Start(ScreensaverPath, "/c");
where ScreensaverPath contains the path to (and including) the *.scr file.
I have also tried this code but to no avail:
Process.Start(ScreensaverPath + "/c");
Any help would be greatly appreciated.
P.S. I am using Windows 8 Pro but I need the solution to be compatible with XP and newer.
回答1:
I would suggest you first create instance of ProcessStartInfo set your properties and then pass the instance to Process.Start(instanceOfProcessStartInfo)
I had similar issues using Process.Start directly and this was the solution to it
回答2:
I don't think that passing args directly will work from C#. If you type c:\windows\system32\sspipes.scr /c
into the Start|Run box, this will also just go straight to the screensaver and not bring up the config screen.
I have been able to do it via a cmd file however, so a solution (albeit not perfect) is to create a cmd file somewhere that has a single line %1 /c
Then you can pass the path and filename of the screensaver to the cmd file and this will bring up the config screen
Some quick and dirty VB code will illustrate
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim path As String = "C:\temp\scr.cmd"
Dim args As String = "C:\WINDOWS\system32\sspipes.scr"
Dim psi As New ProcessStartInfo
psi.Arguments = args
psi.FileName = path
Process.Start(psi)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim app As String = "C:\WINDOWS\system32\sspipes.scr"
Process.Start(app)
End Sub
End Class
This is for a form with 2 buttons. Button1 brings up the config screen and Button 2 runs the screensaver. Obviously you would remove hardcoding, etc so please excuse the bad coding style.
You just need to create a text file called scr.cmd with %1 /c
in it and save it to c:\temp
来源:https://stackoverflow.com/questions/13078311/configure-scr-file-from-c-sharp