Why does my wbemservices execquery work when I run from command prompt, but triggers an access violation when run as a service? - wbem

I have a query that gets a list of the running processes so I can monitor some of them. When I run my software from the command prompt it works just fine, but when I install it as a service I get an access violation. On the exec query call.
I would have expected the program running as a service to behave like the program running from command line.

Related

How can I launch postgres server headless (without terminal) on Windows?

Using Postgres 9.5 and the libpqxx c++ bindings, I want to launch a copy of postgres that is not installed on the users machine, but is instead packaged up in my application directory.
Currently, I am using pg_ctl.exe to start and stop the server, however when we do this, pg_ctl.exe seems to launch postgres.exe in a new terminal window.
I want it to launch postgres.exe in a headless state, but can't work out how.
I have tried enabling/disabling the logging collector, setting the logging method to a csv file (instead of stdout/stderr), and a couple of other logging related things, but I don't think the issue is the logging.
I have also tried running postgres.exe manually (without pg_ctl) and can get that to run headless by spawning it as a background process and redirecting the logs, but I would prefer to use the "pg_ctl start" api for the "wait for startup" (-w), and "timeout" (-t) options that it provides.
I believe you won't be able to do that with pg_ctl.
It is perfectly fine to start PostgreSQL directly through the server executable postgres.exe. Alternatively, you can use pg_ctl register to create a service and start the service.
In my use case, I was able to resolve the issue by running pg_ctl.exe using
CreateProcess, and providing the dwCreationFlags CREATE_NEW_PROCESS_GROUP | CREATE_NO_WINDOW.
I was originally using CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS, but DETACHED_PROCESS still allowed a postgres terminal to appear. This is because DETACHED_PROCESS will spawn the pg_ctl without a console, but any process that inherits stdin/stdout from pg_ctl will try to use it's console, and since there isn't one, one will be spawned. CREATE_NO_WINDOW however will launch the process with a conhost.exe, however the console will have no window. When the executables spawned by pg_ctl try to write to the terminal, they will successfully write to the console created by the conhost.exe which has no window.
I am now able to run pg_ctl from code with no console appearing.

PsExec fails to open the stdin, stdout and stderr named pipes

I am using PsExec to access two servers from my laptop. Access to one of the servers (running Windows 2008R2 Enterprise) works fine. Access to the other (Windows 2008R2 Standard) fails with an error (message below). My laptop has Windows 8.1.
Literature
I've verified that my systems match the requirements, as specified here
Investigating an earlier access denied, I followed the steps outlined here
Commands
Steps taken:
net use \\<servername>\Admin$ /user:me * succeeds
dir \\<servername>\Admin$ lists the remote directory, as expected
PsExec.exe \\<servername> -e cmd is very slow, and then fails with the message:
Error establishing communication with PsExec service on <servername>:
The system cannot find the file specified.
To the best of my knowledge (though I'm no Windows expert), I am in the administrator group on both the client and server machine.
Analysis 1
After executing the command, psexesvc.exe is still running on the remote machine, so the command at least partially succeeds
Before each invocation, I stop and delete the psexesvc service, and remove the executable manually
Analysis 2
I used wireshark to observe the communication between client and server. The following seems to happen:
File PSEXESVC.EXE gets successfully created and written
A "Bind" and a "Map" of SVCCTL
Delay of about 20 seconds (?)
Several SVCCTL calls (presumably resulting in the PSEXESVC service being created and started)
Named pipe PSEXESVC is opened and successfully written to
Named pipes for stdin, stdout and stderr cannot be found (STATUS_OBJECT_NAME_NOT_FOUND)
Trying to eliminate a permissions problem, I tried to verify that the named pipes actually don't exist, by running pipelist.exe (found here) on the server side. I did not actually see the pipes, but if they existed only for a very short time, I might not have run pipelist.exe frequently enough.
Version numbers
PsExec version 2.11

How to uninstall a service on remote machine using powershell?

I am a newbie in powershell script. I want to uninstall a service on remote machine and re-install it again. I am able to stop the service, change the files that service is using and again start it.
But, now I want to completely uninstall it.
One more thing, I will be executing these scripts via TeamCity.
I have tried following ways, but each one is giving trouble:
using wmi class
running installutil command on remote machine. But, cant execute this on remote machine since there is problem in accessing that service.
Using Get-WmiObject command and then calling delete() on retrieved service.
Is there any promising solution ??
Any help will be appreciable..
After playing a lot with TC and many commands, finally I got my answer to uninstall a service on remote computer, and its working properly.
I have made use of "wmic" command and provided the remote computer name, username and password for /node:, /username:, and /password: parameters. And, provided 'installutil.exe' command to be executed remotely. Here, the actual command is..
"wmic /NODE:$serverName /USER:$userName /PASSWORD:$password process call create '$path_to_installutil_exe\installutil /u $exe_location_path_of_service'"

How to make a server daemon which re-runs automatically when they're terminated unexpectedly?

I'm trying to running OrientDB on Ubuntu. Currently, I'm running with bin/server.sh. This works fine except it runs foreground on shell. I can make it work background by Ctrl+Z and bg command, but this doesn't mean it's running as daemon.
I wish the program will keep running after I logout. And will be started again when it terminated unexpectedly or OS restarts. Like MS Windows Services. But the problem is I don't know how can I do this.
How can I run a program as a long-running service?
If you do not own the server, look into using the "screen" command. It will allow you to run a command, detach from the console where the command is running, then log out while leaving it running. You may reconnect to the running screen to see output or restart the script. Here's more info about the screen command:
http://www.manpagez.com/man/1/screen/
If you own the server, you should write an init script. It's not very hard, and you can set it up to run automatically on startup. The system will run the script with a "start" parameter when you want it to start, and a "stop" parameter when you want it to stop. Here's more detailed information:
http://www.novell.com/coolsolutions/feature/15380.html
If the command doesn't already detach from the console (run in daemon mode) then in the init script place the command in parenthesis to run in it's own shell. You will not see any output unless you pipe it to a file within the parenthesis.
(bin/server.sh >> /var/log/server.log)

netbeans 6.91 and gdb - attaching to a process run by another user

I am trying to debug a program run as another user, using Netbeans. I can do this manually at the command line, by running sudo gdm and then attaching to the pid.
However, I would like to make use of the Netbeans GUI for easier/quicker/visual debugging. When I select the pid from the list of running processes, I get the error:
GDB failed to attach to process
When I attempt to attach manually (i.e. by running gdb at the command line - without sudo), I get an 'Operation not permitted', so I know Netneans is failing to attach because of permissioning.
Does anyone know how I can attach to processes being run by another user?.
BTW I am running all this on my dev machine at home (Ubuntu), so security is not an issue.
Have you tried running netbeans as the target user?
You can do "sudo -u username netbeans"
With that, you shouldnt have a problem attaching to the process. If the target user is in another computer, I would suggest ssh with X forwarding (ssh -X user#machine).
Actually, if the target (local) user has no password set, you can try changing your gdb command to "sudo -u username gdb" to start the debugger as that user.