C# service to call a form's method (Not UI) - c#

I have written a c# service to reset my windows XP password. As of now i learned few things about windows service. The main thing is windows service is incompatible with UI. I know that using service cant use form UI(Here is the link). So, by using my service code At least the hard coded password should work. Here i have given the form code. I just want to call the ResetAdminPass("DillGates"); function in service.
ResetAdminPass("DillGates");//By calling this method works fine in windows form.
private static void ResetAdminPass(string NewPass)
{
//Create New Process
Process QProc = new Process();
// Do Something To hide Command(cmd) Window
QProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
QProc.StartInfo.CreateNoWindow = true;
// Call Net.exe
QProc.StartInfo.WorkingDirectory = "C:\\windows\\SYSTEM32";
QProc.StartInfo.FileName = "net.exe";
QProc.StartInfo.UseShellExecute = false;
QProc.StartInfo.RedirectStandardError = true;
QProc.StartInfo.RedirectStandardInput = true;
QProc.StartInfo.RedirectStandardOutput = true;
QProc.StartInfo.Arguments = #" user 5mine " + NewPass;
QProc.Start();
// MyProc.WaitForExit();
QProc.Close();
}
Please do favor for me, with solution/suggestion for my service code. Thanks in advance.

Related

Selenium can't handle multiple ChromiumWebBrowser instances in C#

I have two instances of the ChromiumWebBrowser in my WinForms project (Visual Studio 2012). My goal is to have the second browser instance "copy" the behavior of the user input in the first browser instance. I can successfully retrieve the input from the first browser, and I managed to hook up Selenium in the project as well.
However, I'm having one issue. Whenever Selenium sends its commands, the first browser is the one that responds to them. For the life of me, I can't seem to figure out how to make the second browser respond. Whenever I completely remove the first browser, the second one starts responding correctly, but adding the first browser again will make only have the first browser use the Selenium commands. I even tried to switch out the moments the browsers are added to the form, but to no avail: whenever there are two available, the wrong one is responsive.
Relevant code:
public BrowserManager(Controller controller, string startingUrl)
{
_controller = controller;
var settings = new CefSettings { RemoteDebuggingPort = 9515 };
Cef.Initialize(settings);
// Input browser
inputBrowser = new ChromiumWebBrowser(startingUrl);
var obj = new XPathHelper(this);
inputBrowser.RegisterJsObject("bound", obj); //Standard object registration
inputBrowser.FrameLoadEnd += obj.OnFrameLoadEnd;
// Output browser
var browserSettings = new BrowserSettings();
var requestContextSettings = new RequestContextSettings { CachePath = "" };
var requestContext = new RequestContext(requestContextSettings);
outputBrowser = new ChromiumWebBrowser(startingUrl);
outputBrowser.RequestContext = requestContext;
outputBrowser.AddressChanged += InitializeOutputBrowser;
outputBrowser.Enabled = false;
outputBrowser.Name = "outputBrowser";
}
The selenium part:
public class SeleniumHelper
{
public SeleniumHelper()
{
DoWorkAsync();
}
private Task DoWorkAsync()
{
Task.Run(() =>
{
string chromeDriverDir = #"ActionRecorder\bin\x64\Debug\Drivers";
var chromeDriverService = ChromeDriverService.CreateDefaultService(chromeDriverDir);
chromeDriverService.HideCommandPromptWindow = true;
ChromeOptions options = new ChromeOptions();
options.BinaryLocation = #"ActionRecorder\bin\x64\Debug\ActionRecorder.exe";
options.DebuggerAddress = "127.0.0.1:9515";
options.AddArguments("--enable-logging");
using (IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(chromeDriverService, options))
{
driver.Navigate().GoToUrl("http://www.google.com");
var query = driver.FindElement(By.Name("q"));
query.SendKeys("A google search test");
query.Submit();
}
});
return null;
}
}
And finally, a screenshot for some visualization:
Some help with the issue would be very much appreciated. If i missed some crucial info, feel free to ask for it. Thanks in advance!
Greetz,
Tybs
The behavior is correct. You have one debug address and you can only have one debug address for CEF. Which means when you use Selenium it is only seeing one browser.
By default Selenium will send an command to current active Tab or Window. Now in your case you have multiple Chrome view embedded, but they are technically Chrome Tab/Windows which you have placed on the same form.
So if you are in luck below code in should be able to move you to the Window you are interested in
driver.SwitchTo().Window(driver.WindowHandles.Last());
See if it works. If it doesn't then your only other workaround would be to change the order of Adding ChromiumWebBrowser and that should reverse the window it works on.
Below are some important threads that you should read from top to bottom. Very relevant to your issue/request
https://code.google.com/archive/p/chromiumembedded/issues/421
https://github.com/cefsharp/CefSharp/issues/1076

Can you use LiveSDK from Console Application?

I'm trying to make a console application which accesses my SkyDrive account, however I cannot figure out how to get the Live SDK working.
I'm running on Live SDK version 5.4 and this is the code I'm trying to run - the loginResult.Status is always "Unknown":
private static async Task<LiveConnectClient> ConnectToLive()
{
LiveAuthClient authClient = new LiveAuthClient("my live ID");
var loginResult = await authClient.IntializeAsync(new[] { "wl.basic" });
if (loginResult.Status == LiveConnectSessionStatus.Connected)
return new LiveConnectClient(loginResult.Session);
return null;
}
A few things I'm not certain about (since the SDK documentation is somewhat lackluster at best):
"My live ID" - is this just my e-mail address used for my personal Live account, or is it some sort of application specific ID that you have to create somewhere ?
Is InitializeAsync the proper method to call for authenticating ? All examples I've found mention a "LoginAsync", but that method is not available in the DLL.
Is it even possible to use the SDK outside of Windows Phone / Metro apps ?
I got the following code to work using a SkyDriveClient downloaded from http://skydriveapiclient.codeplex.com/releases/view/103081
static void Main(string[] args)
{
var client = new SkyDriveServiceClient();
client.LogOn("YourEmail#hotmail.com", "password");
WebFolderInfo wfInfo = new WebFolderInfo();
WebFolderInfo[] wfInfoArray = client.ListRootWebFolders();
wfInfo = wfInfoArray[0];
client.Timeout = 1000000000;
string fn = #"test.txt";
if (File.Exists(fn))
{
client.UploadWebFile(fn, wfInfo);
}
}

How to implement chat functionality in windows phone 7

I want to implement a simple online chat application in WP7.
I am using Matrix SDK to implement chat on my WP7
This is how I am trying to connect but I am not able to connect and send any messages.
Neither the events are getting fired..I am not getting any exception also..
what have I done wrong????
Please guide me
Thanks in advance
XmppClient xmppConn;
xmppConn = new XmppClient();
Jid jidUser = new Jid("username");
xmppConn.Username = jidUser.User;
xmppConn.Password = "password";
xmppConn.SetXmppDomain(jidUser.Server);
xmppConn.Uri = new System.Uri("http://server.com:7070/http-bind/",UriKind.RelativeOrAbsolute);
xmppConn.Status = "Testing on Windows Phone 7";
xmppConn.Show = Matrix.Xmpp.Show.Chat;
try
{
xmppConn.Open();
xmppConn.OnLogin += new EventHandler<Matrix.EventArgs>(xmppConn_OnLogin);
//xmppConn.OnPresence += new EventHandler<PresenceEventArgs>(xmppConn_OnPresence);
// xmpp.OnLogin += new EventHandler<Matrix.EventArgs>(xmpp_OnLogin);
}
catch
{
Console.WriteLine("Wrong login data!");
}
}
private void SendButton_Click(object sender, System.EventArgs e)
{
// loose focus to hide keyboard
this.Focus();
messages.Add(new ChatMessage()
{
Side = MessageSide.Me,
Text = TextInput.Text
});
var pm = new PresenceManager(xmppConn);
string sub_id = "xxxxxxxxx";
Jid jid = sub_id;
pm.Subscribe(jid);
xmppConn.Send(new Message(new Jid(jid), MessageType.chat, TextInput.Text));
xmppConn.OnMessage += new EventHandler<MessageEventArgs>(xmppConn_OnMessage);
TextInput.Text = "";
}
Take a look at SignalR for real time web based communications (including chat).
There is an official sample for Windows Phone 8 and also a 3rd party helper for WP7.
Before doing anything on xmpp you first need to set OnBind Event of xmmp class.
Reason: Most of the xmpp works asynchronously.When you call something like client.Open it returns immediately so you first need to wait for OnBind event.

Creating Facebook Application in asp.net

I want to create a Facebook IFRAME applicaton with asp.net. I just want to know should I need to host the application some where over internet? If yes, how could I test my application on localhost?
Update:
I just want a simple app for displaying a user name with "Hello." Can anyone show me the code for that with the complete web.config configuration?
I'm trying this code
using facebook.web;
namespace TestFbApplication
{
public partial class _Default:facebook.web.CanvasFBMLBasePage
{
facebook.Components.FacebookService _fbService = new facebook.Components.FacebookService();
private const string FACEBOOK_APPKEY = "66a8278bb94d969247a80815bab686e5"; // From the Facebook application page
private const string FACEBOOK_SECRET = "de76280e4ddaef72ac2166afe7ffb9d5"; // From the Facebook application page
protected void Page_PreInit(object sender, EventArgs e)
{
base.RequireLogin = false;
_fbService.IsDesktopApplication = false;
_fbService.ApplicationKey = FACEBOOK_APPKEY;
_fbService.Secret = FACEBOOK_SECRET;
_fbService.IsDesktopApplication = false;
_fbService.ConnectToFacebook();
abc.InnerText = _fbService.users.getInfo().ToString();
}
and it is throwing and Exception in the last line that that the object reference is not set.
You will need to host your production application somewhere, but you can test locally. If you set your Canvas URL to http://localhost:81 in Facebook, this should work. It did for me a couple of months ago, but they may have changed it since then.
this might be an interesting for you:
http://www.stevetrefethen.com/blog/DevelopingFacebookapplicationsinCwithASPNET.aspx

How do I register a new user in eJabberd server through C# Client?

I'm developing a messenger type application with Jabbernet Server & library. Currently I'm having a problem registering new users.
First of all I want to know, is it required to login as admin to register a new user?
I tried to register with and without admin login but it always "Not Authorized".
JID jid = new JID("test4", server_IP_address, "");
JClient.User = "test4";
JClient.Password = "test4";
JClient.AutoLogin = false;
JClient.OnLoginRequired += new bedrock.ObjectHandler(this.OnLoginRequired);
JClient.OnRegisterInfo += new RegisterInfoHandler(this.OnRegisterInfo);
JClient.OnRegistered += new IQHandler(this.OnRegistered);
JClient.Connect();
JClient.Register(jid);
JClient.Close(true);
return true;
What am I doing wrong?
You are not providing the host name, which is required by the register method
try using help to get full explanation in the parameters you must pass with register method, at least as far as I understand your question.

Categories