I'm trying to launch notepad.exe(as a simpler test) from a web service using process.Start(). This web service is deployed to IIS 5.1 on Windows XP (for development) and will likely be deployed to a Windows 2003 server with IIS 6. This is the code that I am using:
[WebMethod]
public String ReqFormImage(String qString)
{
_qString = qString;
String imageLoc = #"http://localhost/MobileService/formImages/" + NameOfScreenshot(qString);
Process myProcess = new Process();
try
{
//Credentials
myProcess.StartInfo.Domain = "domain";
myProcess.StartInfo.UserName = "myUserName"; //local admin on development pc
myProcess.StartInfo.Password = PasswordGenerate("removed");
//StartInfo
myProcess.StartInfo.WorkingDirectory = #"C:\WINDOWS\System32";
myProcess.StartInfo.FileName = "notepad.exe";
//myProcess.StartInfo.Arguments = qString;
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardInput = true;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.StartInfo.RedirectStandardError = true;
//myProcess.StartInfo.LoadUserProfile = false;
myProcess.Start();
myProcess.WaitForExit();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
return imageLoc;
}
I also have impersonate set to true in the web.config (I've tried with and without my credentials in the config file, as well as with impersonate set to false). I've also given read/execute permission to my user ID, aspnet, and the service account on notepad.exe.
A breakpoint on myProcess.WaitForExit() causes a message box to pop up that says, "Application Failed to Initialize Properly (0xc0000142)." I looked at the event log and there is no further information than this.
What I need in the end is to be able to launch an exe impersonating an account that can be hardcoded or impersonating the user that accesses the web service. I know that there are issues with opening an exe with a GUI server-side, but I need this to work. I'm sure this isn't the best practice, but I am running short on time and am looking for a workaround. For now, at least getting notepad to launch will be sufficient.
Thanks for any help.
In IIS I had to set the web service to run scripts and executables, not just scripts. Notepad launches now, but without a full GUI. I don't think what I need is possible, but I solved what I asked.
Related
I'm attempting to get our PHPunit tests to run on our build server (Windows jenkins server).
They run on my local Ubuntu 16.04 system correctly, but when I get over to the windows build server I'm having some weird session issues.
I have a light wrapper around the Yii2 Session class that we use so that if we change frameworks I only need to update the session calls in one place.
Here's that class:
<?php
use \yii\web\Session AS Session;
class SessionHelper {
public static function get($key, $defaultValue = null) {
$yiiSession = new Session();
return $yiiSession->get($key, $defaultValue);
}
public static function set($key, $data) {
$yiiSession = new Session();
return $yiiSession->set($key, $data);
}
} //EOF
I'm using this SessionHelper for all things session in my app and inside my Test classes.
The issue i'm running into is this: when I call SessionHelper::set('something', 'something'); from my test case it will correctly set the property into the session. However, the very next time I call SessionHelper::set('something-different', 'something-different'); it loses all previous session data and only has this new session field.
Is this due to the generation of a "new Session();" in each get/set request? I checked and the session settings are identical between servers and the session_id() is the same all of the time.
I created a service that basically exposes some methods to update a sql server database.
I tested the service as a normal WCF Service (not a Windows Service) and it worked fine (which tells me that the ServiceModel definition in App.config is ok)
Then I turned it into a Windows Service, I installed it using InstallUtil, and it installed fine. But when trying to start it in the Services console, I get this message "The service WCFProductsWindowsService service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs"
The solution that exposes the service is composed of two projects,
a class library that defines the service, the contract, and an ADO
NET Entity Data Model to the database,
and a console application that exposes the service
The class that exposes the serice is:
public class ProductsWindowsService : ServiceBase {
public ServiceHost serviceHost = null;
public ProductsWindowsService() {
ServiceName = "WCFProductsWindowsService";
}
public static void Main() {
ServiceBase.Run(new ProductsWindowsService());
}
protected override void OnStart(string[] args) {
if (serviceHost != null) {
serviceHost.Close();
}
serviceHost = new ServiceHost(typeof(ProductsServiceImpl));
serviceHost.Open();
}
protected override void OnStop() {
if (serviceHost != null) {
serviceHost.Close();
serviceHost = null;
}
}
}
I uploaded the simple project in SkyDrive
What could I be doing wrong?
Does not allow me to add a comment.
This error "The service WCFProductsWindowsService service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs" indicates an exception is thrown.
I would check the event viewer to see the exception logged.
Does ProductsServiceImpl exists? I can't find it in your image or in your solution.
I have setup a Windows Server 2012 instance on AWS and I am running Jenkins with a Selenium grid server. The build portion goes through fine, however it is failing with a 404 when it tries to call the browserMob.NET server.CreateProxy() call. I thought perhaps it was a security port issue, so I opened 9090 and 9091 but still having the same issue. If I use the IWebDriver on my local system, everything goes through fine, but when I change over to the remoteWebDriver and point it to the AWS server and try to proxy, I get an error. If anyone has any ideas about how I might be able to go about this, I'm ready for a kick in the right direction :) Thanks!
--Edit:
Some more info: I now have Jenkins running on 8081 and now it stops with a InvalidOperationException. On the same call of server.CreateProxy() the error fired says:
"The specified domain either does not exist or could not be contacted"
Ports currently opened in IIS8 are 80, 9090, 9091, and 8080
I also downloaded the the project to the server and tried to run it from the server and I am seeing the same thing. I also am still running IWebDriver and it doesn't work. So if I run this locally on my personal Win 7 Box, it works fine, but when I run it from Windows Server 2012, it does not. This is the same project, but I have no clue as to what may be going on here.
try
{
Server server = new Server(pathToBrowserMobProxy);
server.Start();
Client client = server.CreateProxy();
client.NewHar("google");
var seleniumProxy = new Proxy { HttpProxy = client.SeleniumProxy };
var capabilities = DesiredCapabilities.Firefox();
capabilities.SetCapability(CapabilityType.Proxy, seleniumProxy);
var driver = new RemoteWebDriver(new Uri(seleniumServerUrl), capabilities);
driver.Navigate().GoToUrl("http://www.google.co.uk");
HarResult harData = client.GetHar();
driver.Quit();
client.Close();
server.Stop();
return Newtonsoft.Json.JsonConvert.SerializeObject(harData);
}
catch (Exception e) { throw e; }
So I finally figured out what was going on and thought I'd post here. The call to server.CreateProxy was using the AutomatedTester.BrowserMob .NET wrapper. This internally had a reference to a version of Newtonsoft JSON.net that was compiled as 32bit. Because of this and my Server 2012 box being 64bit, it was causing an error stating "32 bit processes cannot access modules of a 64 bit process" when it would instantiate the "Process" object. It would open the command window and then crash which would close the window and it wouldnt eb able to find the instance to conenct to. In looking at the NativeErrorCode of 299, I found this was stating that only part of a ReadProcessMemory or WriteProcessMemory request was completed. So I got the src for AutomatedTester, removed the ref to newtonsoft they were using (since this was the first 32bit ref I had found) and added the Nuget version which is compiled for Any CPU. This stopped the crash and allowed me to run my tests. Hope this helps someone else one day.
What is the best way to confirm that these consumed services are actually up and running before I actually try to invoke its operation contracts? I want to do this so that I can gracefully display some message to the customer to give him/her a more pleasant user experience. Thanks.
I created an IsAvailable method that checked all of my underlying dependencies for my service. My client would call this method before doing anything else with my service. If it returned true, my service was available for use.
We also put intermediaten checks to rollback any changes if one of the underlying dependencies was not able at the time of the transaction.
Example:
Here is a simple example of how my IsAvailable is used by the client:
IsAvailable code
[WebMethod]
public bool IsAvailable()
{
bool EverythingUpAndRunning = true;
try
{
string TestConnectionString = WebConfigurationManager.ConnectionStrings["Sql"].ConnectionString;
SqlConnection sqlConnection = new SqlConnection(TestConnectionString);
sqlConnection.Open();
sqlConnection.Close();
sqlConnection.Dispose();
}
catch(Exception ex)
{
EverythingUpAndRunning = false;
}
return EverythingUpAndRunning;
}
The client code:
MyWebService proxy = new MyWebService();
if(proxy.IsAvailable)
{
//if true, you can use the other available methods in the service
}
I wouldn't consider myself a part of the SO Community but I have been in this situation before and it was simple exception handling around the service calls. If you're in control of the services, than you can put up a status method that returns it's current state. If the network is down and you can't even hit the service than you'll have to handle that with some exception handling but you could get a status back if the parent service is unable to use it's child services.
If you're following SO though, my own opinion here, you shouldn't be concerned with the consumed service consuming other services.
I need to remotely install windows service on number of computers, so I use CreateService() and other service functions from winapi. I know admin password and user name for machines that I need access to. In order to gain access to remote machine I impersonate calling process with help of LogonUser like this:
//all variables are initialized correctly
int status = 0;
status = LogonUser(lpwUsername,
lpwDomain,
lpwPassword,
LOGON32_LOGON_NEW_CREDENTIALS,
LOGON32_PROVIDER_DEFAULT,
&hToken);
if (status == 0)
{
//here comes a error
}
status = ImpersonateLoggedOnUser(hToken);
if (status == 0)
{
//once again a error
}
//ok, now we are impersonated, do all service work there
So, I gain access to machine in a domain, but some of computers are out of domain. On machines that are out of domain this code doesn't work. Is there any way to access service manager on machine out of domain?
You can do it , the account needs to exist on the remote machine and you need to use the machine name for the domain name in the LogonUser call.
Rather than rolling your own, why not just use the SC built-in command?
OK, problem resolved (not really very good, but rather OK). I used WNetAddConnection() to ipc$ on remote machine.