Exitcode 6 using PsExec in Windows Service - windows-services

I am using PsExec to defrag machines remotely on my network. This works fine in my c# code, but because it also does a bunch of other tasks and I want it to run continuously I have converted it into a windows service.
When the code gets to the PsExec portion it exits with the code 6 which seems to mean "The handle is invalid" I have tried entering a username and password with sufficient privileges without success, I have also tried adding -s to use the system account which did not help either.
Here is the line where I set my PsExec arguements...
psexec.StartInfo.Arguments = #" \\" + machine + "/accepteula -s defrag.exe " + volume + " -f";
I have also tried...
psexec.StartInfo.Arguments = #" \\" + machine + "/accepteula defrag.exe " + volume + " -f";
psexec.StartInfo.Arguments = #" \\" + machine + "/accepteula defrag.exe " + volume + "-u myuser -p mypass -f";
Any help would be greatly appreciated!!
But nothing seems to fix my problem.

I know this has been open a long time, but did you find a stuck psexec service on the remote machine?
What we found was the PsExec service entry was still in Services and PsExeSvc was still in C:\WINDOWS folder.
We deleted exe from C:\WINDOWS and ran “sc delete PsExec” from an elevated command prompt to get rid of service.

Related

Adding printer on windows-docker

We are trying to dockerize some old powerbuilder batch jobs, and the existing code requires a ghostscript printer installed with the exact name (for the details see here)
Microsoft's documentation on Print Spooler in containers
states "apps that have a dependency on installing printer drivers into the host cannot be containerized because driver installation from within a container is unsupported"
I do not know if this is just a typo/missunderstanding, as why would any application want to install driver into host? I need it in the container, also is it only for the drivers or for the Printers as well?
Assuming this is only a typo/missunderstanding, and microsoft claims it can not be done in the container, the question is
could I do it through the host (and commit it into a new docker image)
could I do it through doccker file , using some MSI installer and run it there
is there any possibility to add a driver and printer in docker image ? (and if not it should be clearly stated)
Assuming this the above statement is not a typo/missunderstanding, than it should be possible to add printer to docker. For that we are using
FROM mcr.microsoft.com/windows:1909
and isolation is hyperv
We tried runnig this from the dockerfile
RUN powershell -command Add-Printer -Name \"Test Printer\" -DriverName \"Microsoft Print to PDF\" -PortName \"PORTPROMPT:\"
and get following errror
# InvalidData: (MSFT_Printer:ROOT/StandardCimv2/MS
# FullyQualifiedErrorId : HRESULT 0x80070006,Add-Printer
but I was not able to find anything meangifull for this error
I can list, rename and remove a printer but I can not add existing one, also if I execute
Get-PrintConfiguration "Microsoft Print To PDF"
I am getting
+ CategoryInfo : NotSpecified: (MSFT_PrinterConfiguration:ROOT/StandardCi...erConfiguration) [Get-PrintConfiguration], CimException
+ FullyQualifiedErrorId : HRESULT 0x8000ffff,Get-PrintConfiguration
so it seams there is something fishy with printers in the docker image.
Do you if there is any possibility to add printer to docker image / container?
thanks
almir
Probably your error in in the DockerFile command. You have to pass the hole command to the powershell and not just the Add-Printer.
I did not try it out, but i would do it like this:
RUN powershell -command "Add-Printer -Name \"Test Printer\" -DriverName \"Microsoft Print to PDF\" -PortName \"PORTPROMPT:\""
The question is quite old, but i would be curios to have a beedback :)

Confused by Docker directory structure (file not found error)

I am getting a file not found error and even though I manually create the file in the Docker container it still reports as not found. Solving this is of course complicated by me being new to Docker and learning how everything in the docker world works.
I am using Docker Desktop with a .net core application.
In the .Net application I am looking for the file to use as an email template. All of this works when I run outside a Docker container but inside docker it fails with file not found.
public async Task SendEmailAsyncFromTemplate(...)
{
...snipped for brevity
string path = Path.Combine(Environment.CurrentDirectory, #$"Infrastructure\Email\{keyString}\{keyString}.cshtml");
_logger.LogInformation("path: " + path);
//I added this line because when I connect to docker container the root
//appears to start with infrastructure so I chopped the app part of
var fileTemplatePath = path.Replace(#"/app/", "");
_logger.LogInformation("filePath: " + fileTemplatePath);
The container log for the above is
[12:40:09 INF] path: /app/Infrastructure\Email\ConfirmUser\ConfirmUser.cshtml
[12:40:09 INF] filePath: Infrastructure\Email\ConfirmUser\ConfirmUser.cshtml
As mentioned in the comments I did this because when I connect to the container the root shows Infrastructure as the first folder.
So naturally I browse into Infrastructure and the Email folder is missing. I have asked a separate SO question here about why my folders aren't copying.
OK my Email files and folders under Infrastructure are missing. So to test this out I manually created the directory structure and create the cshtml file using this command:
docker exec -i addaeda2130d sh -c "cat > Infrastructure/Email/ConfirmUser/ConfirmUser.cshtml" < ConfirmUser.cshtml
I chmod the file permissions to 777 just to make sure the application has write access and then added this debugging code.
_logger.LogInformation("ViewRender: " + filename);
try
{
_logger.LogInformation("Before FileOpen");
var fileExista = File.Exists(filename);
_logger.LogInformation("File exists: " + fileExista);
var x = File.OpenRead(filename);
_logger.LogInformation("After FileOpen:", x.Name);
As you can see from the logs it reports the file does NOT exist even though I just created it.
[12:40:09 INF] ViewRender: Infrastructure\Email\ConfirmUser\ConfirmUser.cshtml
[12:40:09 INF] Before FileOpen
[12:40:09 INF] File exists: False
Well, the only logical conclusion to this is I don't know / understand what is going on which is why I am reaching out for help.
I have also noted that if I stop the container (not recreate just stop) and then start it all my directories and files I created are gone.
So...are these directories / files in memory and not on "disk" and I need to commit the changes somehow?
It would seem to make sense as the application code is looking for the files on disk and if they are in memory then they wouldn't be found but in Googling, Pluralsight courses etc. I can't find any mention of this.
Where can I start looking in order to figure this out?
Front slash '/' in path is different than '\'. Just change direction of your slashes and it'll work.
I tried this program in my docker container and it worked fine.
using System;
using System.IO;
// forward slash don't work
// string path = Path.Combine(Environment.CurrentDirectory, #"files\hello\hello.txt");
string path = Path.Combine(Environment.CurrentDirectory, #"files/hello/hello.txt");
Console.WriteLine($"Path: {path}");
string text = System.IO.File.ReadAllText(path);
Console.WriteLine(text);

Azure Cloud Shell Trouble running ps1 Scripts

In our Azure Cloud Shell, Powershell mode we can't run ps1 files. Although we are doing the same asin the MS Doc.
Any Suggestions, what am I doing wrong.
PS Azure:\> dir
Directory: Azure:/Shared PAAS – Test/StorageAccounts/tstoweuyptobi/Files/azureshellfiles/goal0402preprod/powershell
Mode Name
---- ----
. Build_goal.ps1
. Test goal_Files.ps1
. test.ps1
Azure:/Shared PAAS – Test/StorageAccounts/tstoweuyptobi/Files/azureshellfiles/goal0402preprod/powershell
PS Azure:\> ./test.ps1
./test.ps1 : The term './test.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ ./test.ps1
+ ~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (./test.ps1:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Azure:/Shared PAAS – Test/StorageAccounts/tstoweuyptobi/Files/azureshellfiles/goal0402preprod/powershell
PS Azure:\>
The example below is from Microsoft Docs.
The trick is for the shell to be open in the location that the script is saved.
This will only work if your script doesn't use libraries that are stored on your local device. You may also need to import any modules needed, e.g. AzureAD
# change to your cloud drive fileshare
cd $HOME\clouddrive
# run the script
.\helloworld.ps1
Hello World!
The default directory for Cloud Shell does not seem to allow script running. Copy the script to "$HOME\clouddrive", change to that dir, then run it from there.

How can I run and stop IISExpress from jake

I'm able to kick off IIS express to run my mvc 3 app with the following coffeescript line:
iisex = jake.createExec(['iisexpress /path:' + process.cwd() + ' /port:9090 /systray:false'], {printStdout: true})
#listening code here
iisex.run()
I then run some jasmine tests using
ex = jake.createExec(['phantomjs run_jasmine_test.coffee http://localhost:9090/app/applebees_testrunner.html'], {printStdout: true});
Test pass and now I want to kill IISExpress.
The problem is that now I have a long running process and the process wants me to 'press q' to stop the server. Is there a way to send a q to the running process so that the server will stop?
Perhaps this helps. Is there a way for you to run the following command (needs cmd line opened with admin rights - to do this manually).
iisreset /stop

How to run redis server and juggernaut server in production mode

I am using juggernaut push server. How to start redis and juggernaut in production mode cause I
juggernaut
or
redis-server will keep on showing me log etc.
I am using ruby on rails 3.
EDIT
I followed these two guides to setup juggernaut and redis on production server
Seems like both the servers are running smooth now. But how can i access
:8080/application.js for juggernaut.
I tried
my_ip:8080/application.js but nothing.
For hosting I am using Linode.
EDIT2
When I am trying to stop/start redis server its gives me output ie:
Starting/Stopping redis-server: redis-server.
But nothing when i m doing the same for juggernaut. Check screenshot.
EDIT
I can't see any log for juggernaut.. There is one for redis but nothin for juggernaut
EDIT
Executable file permissions to /etc/init.d/juggernaut file -- YES
-rwxr-xr-x 1 fizzy fizzy 1310 Sep 19 11:06 juggernaut
PIDFILE=/var/run/juggernaut.pid' is defined. Does that exist? --- NO
In the 'start' part it runs 'chown juggernaut:juggernaut'. Does the user juggernaut exist and is it member of the group juggernaut? -- YES/YES
cat /etc/group
redis:x:1002:
juggernaut:x:113:
groups juggernaut
juggernaut : juggernaut
EDIT
fizzy#li136-198:~$ sudo ls -l /usr/bin/juggernaut
ls: cannot access /usr/bin/juggernaut: No such file or directory
fizzy#li136-198:~$ sudo ls -l /usr/local/bin/juggernaut
lrwxrwxrwx 1 root root 40 Sep 20 02:48 /usr/local/bin/juggernaut -> ../lib/node_modules/juggernaut/server.js
I tried changing
DAEMON=/usr/bin/juggernaut
to
DAEMON=/usr/local/bin/juggernaut
after that i tried restarting the juggernaut using
sudo /etc/init.d/juggernaut start
Server started but not as background process/service.
EDIT
Running script in debugging mode ie
changing the shebang line at the top to add an -x, eg
#! /bin/bash -x
Here is the output:-
+ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
+ DAEMON=/usr/bin/juggernaut
+ NAME=Juggernaut2
+ DESC=Juggernaut2
+ PIDFILE=/var/run/juggernaut.pid
+ test -x /usr/bin/juggernaut
+ exit 0
EDIT
Changing path of my juggernaut as it seems my juggernaut is installed somewhere else. Now here is the output
fizzy#li136-198:~$ sudo /etc/init.d/juggernaut start
+ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
+ DAEMON=/usr/local/bin/juggernaut
+ NAME=Juggernaut2
+ DESC=Juggernaut2
+ PIDFILE=/var/run/juggernaut.pid
+ test -x /usr/local/bin/juggernaut
+ set -e
+ case "$1" in
+ echo -n 'Starting Juggernaut2: '
Starting Juggernaut2: + touch /var/run/juggernaut.pid
+ chown juggernaut:juggernaut /var/run/juggernaut.pid
+ start-stop-daemon --start --quiet --umask 007 --pidfile /var/run/juggernaut.pid --chuid juggernaut:juggernaut --exec /usr/local/bin/juggernaut
20 Sep 06:41:16 - Your node instance does not have root privileges. This means that the flash XML policy file will be served inline instead of on port 843. This will slow down initial connections slightly.
20 Sep 06:41:16 - socket.io ready - accepting connections
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: EADDRINUSE, Address already in use
at Server._doListen (net.js:1106:5)
at net.js:1077:14
at Object.lookup (dns.js:153:45)
at Server.listen (net.js:1071:20)
at Object.listen (/usr/local/lib/node_modules/juggernaut/lib/juggernaut/server.js:51:21)
at Object.listen (/usr/local/lib/node_modules/juggernaut/lib/juggernaut/index.js:9:10)
at Object.<anonymous> (/usr/local/lib/node_modules/juggernaut/server.js:21:12)
at Module._compile (module.js:402:26)
at Object..js (module.js:408:10)
at Module.load (module.js:334:31)
+ echo failed
failed
+ exit 0
You probably want to start Juggernaut and Redis as a service / background process. Starting it as a service gives the opportunity to redirect the logs to a file which you then can inspect regularly.
To create a service that automatically starts at boot time, you have to do different things based on the OS you're using:
In Linux you can add an init.d script (Juggernaut Ubuntu example, Redis Ubuntu example)
In Mac OS X you use launchd.
In Windows you use this method.
Make sure you start the services after creating them by adding the service to the default runlevel (will start automatically during boot time) or start them manually.
Add service to default runlevel (Linux), is also part of both the Linux tutorials above:
sudo update-rc.d -f juggernaut defaults
sudo update-rc.d -f redis-server defaults
After adding the service to the default runlevel, you still need to start the service manually (Linux):
sudo /etc/init.d/juggernaut start
sudo /etc/init.d/redis-server start
I ran into the same problem (using Ubuntu 12.04 LTS). Using upstart did it for me.
Create a file 'juggernaut.conf' containing:
start on filesystem and started networking
stop on shutdown
script
# We found $HOME is needed. Without it, we ran into problems
export HOME="/root"
exec /usr/local/bin/juggernaut 2>&1 >> /var/log/juggernaut.log
end script
Save this file in /etc/init/ (not init.d) and make it executable (chmod +x). This is it, Juggernaut runs as a deamon if the server started.
A note: next to the juggernaut.log of juggernaut itself, there is a juggernaut.log located in /var/log/upstart/ where information is written on the attempts of upstart to start juggernaut.
I more or less copy-pasted the above script from this blog . However, the script shown there started with:
start on startup
This did not work for me, because the filesystem was not mounted properly at startup, so no possibility to create juggernaut.log (Read-only filesystem error). Credits to this post on serverfault for solving that.

Resources