psexec command invoking from Windows Service - c#

I created Windows Service problem which invokes psexec and run .exe in the remote Server. Every thing work fine, when i try to do run in debug mode of invoking pscommand code # console application, when i try to run pscommand from Windows service, It hangs out without any reason. Is there any reason or alternative.. psexesvc doesnot start on remote server
Here is the pscommand i used
psexec -accepteula \\XYZServer -u -p -h \ShareCompName\Component.exe.
There is no error message.

I found reason for hang state, basically psexec command is calling .exe application, where that exe aplication is performing Admin activity. When PSEXEC command is having -h parameter , then it asking psexec command to execute run as administrator. Since target server where psexec gets executed is having UAC enabling, It is waiting for user input , until user click Yes or NO. application remain in hang state. SO i added extra parameter -i along with -h which automatically takes care of above explained situation.
psexec -accepteula \XYZServer -u -p -h -i \ShareCompName\Component.exe.

Related

macos + C# : how can I start process with sudo prompt

I have an application built in C# .dotnet 6 on macos.
I want the application to be able to seamlessly update itself.
It's downloads the latest pkg and my problem is how I run it.
I want to start this process using "sudo installer -pkg /tmp/mypackage.pkg -target /" but sudo ask for password on the standard input.
How can I start a process with escalated privileges where the user permissions are asked first through something like:
You can use AppleScript to create a graphical authentication prompt:
#!/bin/sh
osascript -e "do shell script \"$*\" with administrator privileges"
Other methods: Is there any graphical "sudo" for Mac OS X?
You could try the option -S of sudo for accepting the password from standard input. After use echo password and | to pass the password to the command:
echo myPassword | sudo -S installer -pkg /tmp/mypackage.pkg -target

How can I know whether RabbitMQ application has started

I have a c# code that installs rabbitmq 3.7.4, erlang 20.2 on windows server 2012 R2 and I need to know when the application (not the service) has started. After running rabbitmq-service install and rabbitmq-service start I'm looking for a command line that will indicate that the application is running. I'm aware of the wait pid_file, wait --pid pid command but can't locate the pid file on my machine. The documantaion says:
This command will wait for the RabbitMQ application to start at the node. It will wait for the pid file to be created if pidfile is specified
specified where?
rabbitmq-echopid.bat returns:
The system cannot find the path specified.
On Windows, RabbitMQ does not create a PID file by default, so you have to discover the PID and then pass it as an argument: rabbitmqctl.bat wait -P PID
To discover the PID, you can run the following using the name of your RabbitMQ node:
.\rabbitmq-echopid.bat rabbit#my-hostname
At this time, there is a bug where The system cannot find... will be echoed before the PID is echoed. I filed this bug and will have a fix in soon, but in the meantime you can edit the rabbitmq-echopid.bat script to change !TDP0! to %TDP0%.
You can also use any other Windows tool to find the PID of the erl.exe process running RabbitMQ - see the script for an example of wmic.exe, or you could use tasklist, or Powershell, etc.
On windows, you can run the following batch script:
START /B rabbitmq-server
START /wait cmd /c "rabbitmq-echopid.bat -n rabbit#`hostname` > rabbitmq_pid.txt"
set /p PID=<rabbitmq_pid.txt
echo %PID%
del rabbitmq_pid.txt
cmd /c "rabbitmqctl wait -P %PID%"
Note that for the rabbitmq-echopid command to work, you have to add an -n before the nodename.
Moreover, in the above batch script, the nodename is dynamically generated by combining "rabbit#" withe the hostname windows command (inside backticks).

SU command for updates

I'm trying to update an app remotely. All devices are rooted.
Due to the nature of the apps and devices, there are no users, the devices monitor a range of sensors and send the info back to a server from key locations.
I know that
"pm install -r app.apk\n"
will install a downloaded apk.
But how would I get it to run without a user.
Once this command executes the app stops and all it's services stop aswell.
So is there a command to install + run ?
am start -n com.package.name/com.package.name.ActivityName
does not get executed and wont start the services because this code is not reached after the install command
edit:
this is the code once the apk is downloaded
dataOutputStream.WriteBytes("mount -o rw,remount -t /system\n");
dataOutputStream.Flush();
dataOutputStream.WriteBytes("chmod -R 777 "+localPath+"\n");
dataOutputStream.Flush();
dataOutputStream.WriteBytes("mount -o ro,remount -t /system\n");
dataOutputStream.Flush();
dataOutputStream.WriteBytes("pm install -r "+localPath+"\n");
dataOutputStream.Flush();
//The code below is not reached because the install kills the app
dataOutputStream.WriteBytes("am start -n com.company.remote/com.company.remote.RebootServices\n");
dataOutputStream.Flush();
Whenever you install an app through Android Studio, it installs your app and launches it immediately afterwards. By looking into the commands it executes, I have found the following line, it might help you:
adb shell am start -n "com.package.name/com.package.name.ActivityName" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Notice the intent filter flags: -a for "action" and -c for "category" as defined in manifest. If you have an intent filter, you can use those too.
EDIT: After reading the comment of SushiHangover, this is indeed a duplicate of this question: https://stackoverflow.com/a/4567928/3673616
According to the answer from there, instead of am start[...] you need to use adb shell am start[...]

Running PsExec From IIS: PsExecSVC hanging on remote host

I am trying to run a .bat file on a remote host from a web page.
PSEXECSVC (on host) will hang and not close after the execution of the batch causing the server to wait indefinitely.
When running the exact same code (See at bottom) in a Console Application the service closes and everything is fine...
The weird part is when the batch file consists of a one liner echo:
#echo off
echo ------ Start -----
exit
PsExecSvc will close and "------ Start -----" is shown on the page. (This is what I want..)
On the other hand,
#echo off
echo ------ Start -----
echo echo2
exit
PSEXECSVC will hang at the end of execution...
When manually killing PSEXECSVC, only "------ Start -----" shows and StdErr
prints:
PsExec v1.98 - Execute processes
remotely
Copyright (C) 2001-2010 Mark
Russinovich
Sysinternals - www.sysinternals.com
The handle is invalid.
Connecting to novi2...
Starting PsExec service on novi2...
Connecting with PsExec service on
novi2...
Starting C:/dbInfo.bat on novi2...
Error communicating with PsExec
service on novi2:
No matter what is run in the batch file, only the first line of StdOut is redirected and psexecsvc hangs (but after the whole batch is executed :O ).
If running:
info.bat:
#echo off
cscript /nologo test.vbs
exit
test.vbs:
Set objOut = Wscript.StdOut
objOut.WriteLine "----------------------------------"
objOut.Writeline "Win32_OperatingSystem instance"
objOut.Writeline "----------------------------------"
objOut.close
Wscript.quit 666
A ConsoleApplication will print everything and return 666
IIS will only get "----------------------------------" in StdOut and psexecsvc will hangs...
Here is the code used to run psexec in C#...
Process proc = new Process();
ProcessStartInfo procInfo = new ProcessStartInfo(#"C:/PsExec.exe", #"\\novi2 -u Domain\usernameadmin -p Password C:/info.bat");
procInfo.UseShellExecute = false;
procInfo.RedirectStandardOutput = true;
procInfo.RedirectStandardError = true;
proc.StartInfo = procInfo;
proc.Start();
String output = proc.StandardOutput.ReadToEnd();
String err = proc.StandardError.ReadToEnd();
Trace.WriteLine("Out >> " + output);
Trace.WriteLine("Err >> " + err);
proc.Close();
I am using IIS 7, ASP MVC3 and .NET4.0 on the Server (Sample projects from VS2010) and WinXP SP3 for the host.
To avoid problems the ApplicationPool in IIS is using the same admin account as psexec.
The problem is likely the PSExecSvc on your remote host (novi2) did not clean up after itself and now needs to be deleted before it can run successfully. I now add the following at the end of each script that starts PSExec against a remote host:
sc \\novi2 delete PSExecSvc
Also, if you're instantiating PSExec on, and not against, a remote host, then you'll need to ensure you add the switch for accepting its EULA like so:
psexec \\HOST1 /accepteula -u userid -p password COMMAND
Hope that helps,
Lizz

Parameter Not Applied when Executing sqlcmd from CruiseControl.NET

OK, so here's the scenario.
CruiseControl.NET (Version : 1.5.7256.1) runs a project to rebuild a database. The CruiseControl.NET windows service is running as a windows user we created for CC.NET. There are several tasks in the project but they all run fine. However, one of the tasks that runs is a console based utility I wrote in C# that generates a batch file and then runs it via an instance of the .NET Process class.
The batch file is generated properly and the process runs fine in C#. However the batch file that runs, runs the sqlcmd command line utility for SQLServer (Version 2005 SP3). sqlcmd runs as expected, but one of the options for sqlcmd never gets applied... -I (turning quoted identifiers on).
e.g.
sqlcmd -U %1 -P %2 -S %3 -d %4 -i someScript.sql -k -b -I >> %LogFileName%
The odd thing is if I run this from a command prompt on the continuous integration server, it runs with -I being applied.
I'm very confused. I'd understand if the sqlcmd failed because the user executing the process didn't have enough privileges and I'd understand if something went wrong on the SQLServer side if the SQLServer authentication failed, but for it to work but not apply an option to sqlcmd is mystifying.
Could it be it's because -I is the last parameter? Perhaps there's a missing space there or something.. have you tried switching parameter order?
(also, why are you running a C# console app that create a batch file and the invokes it? Can't cc.net run this file itself?)

Categories

Resources