0

Am trying to run "show Desktop.scf" using System.diagnostics.Process.Start() in C#. But the debug line just passes and takes no action.

When I try using Start -> Run, it performs the show desktop action.

Process.Start takes a filename. Why wouldn't this work from the code. I tried in Admin mode too.

Any guidance pls.

Andrii Kalytiiuk
  • 1,501
  • 14
  • 26
  • But when you write `"show Desktop.scf"` in Start -> Run, it doesn't work either.. You sure about that? Or do you create this `.scf` file custom? – Soner Gönül Jul 02 '13 at 12:34
  • 2
    Rather than trying to run a `.scf`, why didn't you, say, search for Show Desktop Programmatically? Which for me, brings back a [blog post](http://blogs.msdn.com/b/robgruen/archive/2004/02/24/79294.aspx) as a first result that shows some simple code in C#. – Damien_The_Unbeliever Jul 02 '13 at 12:40
  • [Shell] Command=2 IconFile=Explorer.exe,3 [Taskbar] Command=ToggleDesktop This is the code in showDesktop.scf When I run this from start->run, it does the trick. But not from the code. Not sure why. I tried sinni800's suggestion, but doesnt work either. – user1056111 Jul 02 '13 at 13:04
  • @Damien_The_Unbeliever:: Am trying to perform this operation to move away from Metro mode. I've placed this .scf file in c:\users\..\startup folder, so upon reboot; the desktop appears. But at times, the metro mode appears while my code is running on desktop, so am trying to see if calling this script from the code can restore desktop. I'll checkout the blog, tx for sharing. – user1056111 Jul 02 '13 at 13:06
  • That's why I posted a link to a blog post that shows how to invoke `ToggleDesktop` directly from your code - even if it fails to work, it's more likely to give you a decent error code/message that will tell you what's going wrong. – Damien_The_Unbeliever Jul 02 '13 at 13:08
  • @Damien_The_Unbeliever:: tx for the post, i tried it out. The toggling happens while am trying the code from within the desktop mode. I tried to put the console app to sleep within the code and activated the metro mode (pressing the win key). The code executed in the background, but the desktop mode didnt appear; the screen remained in metro mode. Alternatively, I put this code in c:\users\..\startup folder & initiated a restart. The metro came up, but didnt switch to desktop. The showDesktop.scf worked in this case. Tx again. I'll keep looking for suggestions & will keep trying. – user1056111 Jul 02 '13 at 13:38

2 Answers2

1

Hand in a ProcessStartInfo with UseShellExecute set to true.

This executes the scf in the same way START -> RUN would do.

sinni800
  • 1,451
  • 14
  • 29
  • System.Diagnostics.Process pp = new System.Diagnostics.Process(); pp.StartInfo = new System.Diagnostics.ProcessStartInfo(); pp.StartInfo.UseShellExecute = true; pp.StartInfo.FileName = @"C:\Users\SkipMetro.scf"; pp.Start(); This is my code. This just passes through, unfortunately. – user1056111 Jul 02 '13 at 13:02
1
shell:::{3080F90D-D7AD-11D9-BD98-0000947B0257}

in Start -> Run does the same as running the .scf
I was making an AutoHotKey script when i encountered the same problem.
But when i replaced the path to .scf with the above code it worked like a charm.

Sheo
  • 11
  • 2