I write a small desktop application (main form) in the C# language (.net). And i want to have my application in top of the start menu (Windows 8), just like the “camtasia studio screenrecoder”.
See screenshot what i want for my small application.
What code must i add in my application?
note:
I have try to set the topMost = true
, and that doesn’t work.
If you want a window on top of Metro, you need it to declare accessibility. Here are the key points:
-
The application must demand uiAccess (app.manifest)
-
The application must assert “topmost” window positioning (either in Win32/SetWindowPos or WinForms/WPF’s “Topmost” property, programmatically or otherwise)
-
Without making changes to the group policy setting, it must be installed to some trusted location [C:\Windows, C:\Program Files, C:\Program Files (x86)].
a. Note: If you want to be able to run it out of an arbitrary location, you must disable the security setting: “User Account Control: Only elevate UIAccess applications that are installed in secure locations”.
b. Note2: This is the same as setting HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System\ValidateAdminCodeSignatures to 0
-
Said application cannot be ran in the debugger
-
If it’s a .NET application
a. The manifest must be embedded in a post-build step
b. The application must have “delayed signing” (meaning it cannot be ran from the built-in debugger, although you can build and attach – this is what Microsoft does)
-
The application must be signed with a trusted certificate.
-
Said trusted certificate must be installed to the Trusted Root Certificate Authority (this is important! It must not just simply installed)
For more info see:
http://msdn.microsoft.com/en-us/library/ms726294
In order to force your application above Metro’s User-Interface you’ll need to do the following:
- Create a Win32 Project
- Finish the wizard with no changes.
- Change the
CreateWindowEX
andset WS_EX_TOPMOST
- Go to
Project.Properties
and link to manifest file. - Change UAC to bypass UI Protection; should be
/uiAccess = "true"
- Build your project.
- Use the
SignTool
to sign the application. - Ensure the application is stored in
Program Files
orProgram Files (x86)
- Run your application.
- Load your
Start Menu
and your application should be running above Metro.
Your manifest should look like:
<trustInfo xmlns="urn:0073chemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="highestAvailable"
UIAccess="true" />
</requestedPrivileges>
</security>
</trustInfo>
By default it is set to false
if the attribute is omitted, or a manifest doesn’t exists for your assembly. With it false
you will not be able to gain access to ProtectedUI
.
More information on the security can be found here:
Here is a script that may work or allow modification to test UAC:
class Elevated_Rights
{
// Token Bool:
private bool _level = false;
#region Constructor:
protected Elevated_Rights()
{
// Invoke Method On Creation:
Elevate();
}
#endregion
public void Elevate()
{
// Get Identity:
WindowsIdentity user = WindowsIdentity.GetCurrent();
// Set Principal
WindowsPrincipal role = new WindowsPrincipal(user);
#region Test Operating System for UAC:
if (Environment.OSVersion.Platform != PlatformID.Win32NT || Environment.OSVersion.Version.Major < 6)
{
// False:
_level = false;
}
#endregion
else
{
#region Test Identity Not Null:
if (user == null)
{
// False:
_level = false;
}
#endregion
else
{
#region Ensure Security Role:
if (!(role.IsInRole(WindowsBuiltInRole.Administrator)))
{
// False:
_level = false;
}
else
{
// True:
_level = true;
}
#endregion
}
}
}
Something like that to ensure that it you can handle or at least alert the user that the feature may not work. Please note that in the above I actually protect the call and invoke the method; that way I can access the _level
value at any point to ensure the authentication remains present. And it is only inherited or used when desired to avoid unnecessary calls. Hopefully that helps.
Update for Comment:
This is for your C# Project, you’d call the following:
using System.Diagnostics;
The above assembly will provide you the capability. Then inside a method just invoke the following.
Process command = new Process();
command.StartInfo.FileName = "notepad.exe";
command.Start();
As you can see it isn’t to technical, but it will allow you to call a batch
, open a program, or even run other utilities such as msiexec
. Hopefully that helps.
Winforms? Metro? As far as I am aware you cannot do this without messing with the shell, which is what Camtasia most likely does. Why do you want to?
I mean the Desktop application (like “camtasia studio screenrecoder”)
In Windows8 desktop applications sit seperately to the new full screen start menu. Could you provide a screenshot of what you are comparing against with Studio Recorder?
Interesting. My suspicion is that they have done something clever using the shell. Makes sense for this application. But what application do you have that makes it worth breaking design convention?
want to make a similar basic screen capture.
Show 1 more comment