I am creating a program (in C#, .net 4) that allows the user to highlight an IP address from a textbox and click a button that launches RDP (MSTSC.EXE) supplied with the highlighted IP. What I'd like to do is NOT have RDP try to auto-connect to the IP (which is what happens if you provide the -v: argument). Rather, bring up the usual RDP dialog that will allow the user to either edit the IP or click "Connect" to go ahead and connect.
Is this possible? There doesn't appear to be any command line switch that prevents autoconnecting. The only thing I can think of is to create an .RDP file with the IP and then use the -edit switch. Although I'm wondering if it's possible to launch mstsc.exe and then do some kind of Clipboard paste to paste the IP into mstsc.exe?
Found the answer after rewording my question.
SendKeys.SendWait("^V") did the trick.
To avoid reconnection see this link
For the rest use
using System;
using System.Diagnostics;
using System.ComponentModel;
namespace MyProcessSample
{
class MyProcess
{
static void Main()
{
// Get the path that stores favorite links.
Process.Start("mstsc.exe", "/v:10.58.45.24"); //Or whatever
}
}
}
Related
Question
How to use these private functions on other windows? It would be nice to have this knowledge back in the wild. I am specifically trying to get CGSOrderWindow and CGSSetWindowLevel to work.
I was trying in the direction of:
temporarily register as the dock and then register the dock as the dock again immediately afterwards
or
code injection into the Dock process per this comment:
Also, the author of the above project seems determined to make all core functionality available as a framework. It seems to be implemented as code injection into the Dock process.
Reason I know this is possible
I have been doing work on trying to setLevel on window of another app, and focus window of another app if focused. I am posting this again with the info I learned because from my searching online, I know this was done in the past, its just the knowledge is not publicly out there anymore. The sourceforge pages are no longer there. So I was wondering if you could help me make this information public again.
This is the topic I read that gave me this information - http://cocoadev.com/HowtoControlOtherAppsWindows
Here you see comments like:
You cannot control an another app's windows from a user-level process, unfortunately.
SlavaKarpenko
You can, Slava, you just need to register as the Dock. It might be possible to temporarily register as the dock and then register the dock as the dock again immediately afterwards, not sure. I think the call you'd be wanting to investigate as CoreDockRegisterDockOwner in HIServices.framework.
FinlayDobbie
You could also use APE or similar to do control the windows, or (as mentioned above) register as the Dock (look for the private APIs with Universal Connection in their name). Has anyone found a polite way of getting the Dock to give up its universal connection? The only way I can find is to force quit the Dock and grab the universal connection when it's not looking (which prevents the dock reloading).
SamTaylor
There's an open source project up on sourceforge.net that looks much more like the window managers I've used on Unix boxes than Space.app (or Space.dock): http://wsmanager.sourceforge.net/
SteveCook
Verifying things work
This is what I learned, from the sources at bottom of this post, we see all these functions work with CGWindowIds, so how do I get that, this is how:
Get all windows with CGWindowListCopyWindowInfo. Then access each element from that array with CFArrayGetValueAtIndex and then get the CGWindowId with objectForKey:, kCGWindowNumber, and then integerValue.
Now if I try to focus or set level of a window that is OWNED by the app running the code, it works fantastic. For instance:
MY_TARGET_CGWINDOW_ID = 179;
rez_CGError = CGSOrderWindow(_CGSDefaultConnection, MY_TARGET_CGWINDOW_ID, kCGSOrderAbove, 0);
Will focus it, rez_CGError is 0. Even if the window is minimized, it is unminimized, without animation, and shown.
Now however, if I try this on a window of a different app we get some errors:
MY_TARGET_CGWINDOW_ID_of_other_app = 40;
rez_CGError = CGSOrderWindow(_CGSDefaultConnection, MY_TARGET_CGWINDOW_ID_of_other_app, kCGSOrderAbove, 0);
This fails and rez_CGError is 1000, which I suspect means "cid (CGSConnection) used does not have permission to modify target window". The same happens if I first do [app activateWithOptions: (NSApplicationActivateIgnoringOtherApps | NSApplicationActivateAllWindows)] before making the call above.
So I first get the cid of that owning window like this:
var rez_CGError = CGSGetWindowOwner(_CGSDefaultConnection, MY_TARGET_CGWINDOW_ID_of_other_app, &ownerCid);
This works good and I get ownerCid is set to a value. Then I do the focus command with this new connection:
rez_CGError = CGSOrderWindow(ownerCid, MY_TARGET_CGWINDOW_ID_of_other_app, kCGSOrderAbove, 0);
However this gives rez_CGError of 268435459, which I suspect means "current app does not have permission to use this ConnectionId (cid)". (Same happens if I call activateWithOptions first.
My Sources for the Private Functions
Here is the sources for some private functions I found - https://code.google.com/p/undocumented-goodness/source/browse/trunk/CoreGraphics/CGSPrivate.h
This one source here contains a function that is not in the above link - CGSGetConnectionIDForPSN - i test it and it exists - from - https://github.com/mnutt/libqxt/blob/767498816dfa1742a6f3aee787281745afec11b8/src/gui/qxtwindowsystem_mac.h#L80
Windows Store rule 4.1.1 mandate that:
You must provide access to your privacy policy in the Description page
of your app, as well as in the app’s settings as displayed in the
Windows Settings charm.
The Description page is easy, since when you setup your app in the store there's a field where you can enter the URL.
However I'm a bit clueless about how to add this entry in the Windows Setting charm in a Unity project. I've found this answer but that assumes you are in full control and knowledge of your Windows Store app, while I'm just exporting from Unity, so I've no clue on where I would put that code.
So, how do I do that?
Unity is exporting the game as JS or C#.
So have a look to these samples http://code.msdn.microsoft.com/windowsapps/Windows-8-Modern-Style-App-Samples. In these samples, there are a few Setting Charm screnios that you can use in your application.
But remember that, you should add setting charm after export the game.
The plugin prime31/MetroEssentials has the function registerSettingsCommand, which allows you to do just that.
// Registers a settings item with an associated message that will be displaed in a popup when clicked
public static void registerSettingsCommand( string title, string message )
// Registers a settings item with an action. When the settings item is clicked the action will be called.
public static void registerSettingsCommand( string title, Action onActivated )
I'm using Fiddler on daily life. However, the most used feature for me, such as Reissue and Edit and Reissue from composer don't have any shortcuts. I don't know how to use fiddler script for this. Can anybody point a solution for this?
Hit CTRL+R to open the FiddlerScript editor.
Inside the OnBoot() function add the following code:
FiddlerApplication.UI.lvSessions.add_KeyDown(HandleAKey);
Immediately after the closing brace for the OnBoot function, add the following code:
static function HandleAKey(Sender, theKey:KeyEventArgs) {
if (theKey.KeyData == Keys.E)
{
var oS: Session = FiddlerApplication.UI.GetFirstSelectedSession();
if (null == oS) return;
theKey.Handled = theKey.SuppressKeyPress = true;
FiddlerApplication.DoComposeByCloning(oS);
}
}
Save the file. Restart Fiddler. Now, when you press the E key on any selected session in the Web Sessions list, that session will be cloned to the composer to resend.
Currently, the FiddlerApplication.UI.actReissueSelected() function is not public, which means that there's no simple way to invoke that functionality without calling FiddlerApplication.oProxy.SendRequest() directly.
I am using SetWindowText Function to rename Window Title it seems to work with Windows program like "notepad" but when trying with other 3rd party program its not working.I am grabbing window handle via Process..MainWindowHandle . I want to spawn firefox and rename its window title this is my requirement.Process is getting launched but Window Title rename is not happening i am getting "Send Error Report" Dialog window.Please Help me out.Below is the code.
using System;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.Threading;
using System.Diagnostics;
namespace SampleNamespace
{
public class SampleClass
{
[DllImport("user32.dll")]
static extern int SetWindowText(IntPtr hWnd, string text);
public static void Main()
{
Process p = Process.Start("C:\\Sham\\pg\\Firefox\\firefox.exe");
Thread.Sleep(1000);
SetWindowText(p.MainWindowHandle, "FireFox via Process-Start");
} // End of Main function (program statup)
}
}
Many programs set their main window titles repeatedly during their execution.
A good example is Firefox which changes its main window title whenever you browse to a new page. Likewise Notepad will change its main window title whenever you open or save a file to include the name of the latest file.
The only way you can realistically expect to exert control like this is to poll.
The problem may occur because Firefox, google, IE work in few processes to isolate different pages from each other, so if one tab crashes, the other will still alive. Open Windows Task Manager to ensure. (Opera is still dont but thes feature is already planned for future releases).
Possible solution for you is to enumerate all processes with name 'firefox.exe' for instance and change window titles of windows that match some of your criteria.
I have a simple windows service called lets say "MyService", built using WCF that on start adds a registry entry to "HKEY_CLASSES_ROOT\Folder\Shell\{ContextMenuEntryName}" thus allowing for the right click menu anywhere in windows to have an entry named : {ContextMenuEntryName}. The target executed on clicking this entry is another program e.g. "{Path}\serviceclient.exe %1". The "%1" gives me the path of the windows folder that that context menu has been invoked on. This program then takes that value and passes it to my service by creating a proxy of the service and invoking its method.
The WindowsService code for its OnStart method is as follows:
protected override void OnStart(string[] args)
{
if (_serviceHost != null)
{
_serviceHost.Close();
}
// Add registry entry for context menu option System.IO.Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
string contextMenuCommandPath =
Environment.CurrentDirectory.Substring(0, Environment.CurrentDirectory.IndexOf("MyService")) +
"serviceclient\\bin\\Debug\\serviceclient.exe %1";
_contextMenu.AddContextMenu(ContextMenuName, contextMenuCommandPath, "Folder");
_contextMenu.AddContextMenu(ContextMenuName, contextMenuCommandPath, "*");
// Create a ServiceHost for the CalculatorService type and
// provide the base address.
_serviceHost = new ServiceHost(typeof(MyService));
// Open the ServiceHostBase to create listeners and start
// listening for messages.
_serviceHost.Open();
}
The serviceclient.exe has the following code after adding a service reference named "MyService" to it:
// Instantiate service proxy
var myServiceClient = new MyService.MyServiceClient();
// Execute monitor target based on path specified (or default).
myServiceClient .Monitor(args.Length > 0 ? args[0] : string.Empty);
I would like to directly pass arguments to the Windows service itself when I click on the context menu entry instead of invoking another separate program that does the same thing.
Would it be possible to have the context menu entry directly pass information to a Windows Service in WCF while it is running?
It doesn't look like it on first glance, but it's a complicated subject. See Creating Shortcut Menu Handlers.
If you implemented a named pipe server inside your Windows service maybe you could send the file path data directly from the context menu command with something like:
echo %1 > \\.\pipe\{pipe-name}
However, you can't use the standard WCF NetNamedPipeBinding to implement the pipe server, because of all the .NET-specific protocol requirements baked into that binding, so you would need to do it either using the System.IO.Pipes classes, or write a custom WCF transport which just receives raw messages from the pipe.