how to terminate chrome (that started with "--user-data-dir="profilename"" argument) in vbscript - typeconverter

this snippet code is working in powershell but i dont know the code for vbscript
$scriptName = "myprofile"
$profileArgs = "--flag-switches-begin --user-data-dir=..\profiles\{0} --no-default-browser-check --allow-outdated-plugins --disable-logging --disable-breakpad --flag-switches-end" -f $scriptName
$filterString = "Name='chrome.exe' AND CommandLine LIKE '%{0}%'" -f $scriptName # $profileArgs would be better, but for some reason gives an error
(Get-WmiObject win32_process -filter $filterString).Terminate()

Related

Why QProcess is not showing stdout from bash script executed in remote server?

I made an script (findx.h) that doesn't have any problem when i ran it on Solaris server via console (bash-3.2$ ./findx.sh)
The problem appears when i try to run it from a windows Qt app using QProcess (code below) where it doesn't display the ouput of the command.
I tried little variations and appear to show data when just use one pipe instead of two. But i need the two: grep and ggrep.
//findx.h in solaris
//WHAT WORKS
#!/bin/bash
echo pass | sudo -S /usr/sbin/snoop -x0 -ta HSM1000 port 1000
//WHAT I WANT
#!/bin/bash
echo pass | sudo -S /usr/sbin/snoop -x0 -ta HSM1000 port 1000 | /usr/sfw/bin/ggrep -A 2 KR01
//Qt on windows
QString commands="(";
commands +="source setpath.sh";
commands +=";/path/to/script/findx.sh";
commands +=")";
this->logged=false;
QString program = "plink.exe";
QStringList arguments;
arguments <<"-ssh"
<<ip
<<"-l"
<<user
<<"-pw"
<<pass
<<commands;
this->myProcess=new QProcess(this);
connect(this->myProcess,SIGNAL(started()),
this, SLOT(onprocess_started()));
connect(this->myProcess, SIGNAL(errorOccurred(QProcess::ProcessError)),
this, SLOT(onprocess_errorOcurred(QProcess::ProcessError)));
connect(this->myProcess, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(onprocess_finished(int, QProcess::ExitStatus)));
connect(this->myProcess, SIGNAL(readyReadStandardError()),
this, SLOT(onprocess_readyReadStandardError()));
connect(this->myProcess, SIGNAL(readyReadStandardOutput()),
this, SLOT(onprocess_readyReadStandardOutput()));
connect(this->myProcess, SIGNAL(stateChanged(QProcess::ProcessState)),
this, SLOT(onprocess_stateChanged(QProcess::ProcessState)));
this->myProcess->start(program, arguments);
this->ui->labStatus->setText("Starting");
return 0;
// How i read, i do the same for stderr and put it also in plainOutput
QByteArray err=this->myProcess->readAllStandardOutput();
QString m="Standard output:"+QString(err.data());
this->ui->plainOutput->appendPlainText(m);
please any advice would be useful.
Thanks in advance.

Powershell: Issue redirecting output from error stream when using docker

I am working on a set of build scripts which are called from a ubuntu hosted CI environment. The powershell build script calls jest via react-scripts via npm. Unfortunately jest doesn't use stderr correctly and writes non-errors to the stream.
I have redirected the error stream using 3>&1 2>&1 and this works fine from just powershell core ($LASTEXITCODE is 0 after running, no content from stderr is written in red).
However when I introduce docker via docker run, the build script appears to not behave and outputs the line that should be redirected from the error stream in red (and crashes). i.e. something like: docker : PASS src/App.test.js. Error: Process completed with exit code 1..
Can anyone suggest what I am doing wrong? because I'm a bit stumped. I include the sample PowerShell call below:-
function Invoke-ShellExecutable
{
param (
[ScriptBlock]
$Command
)
$Output = Invoke-Command $Command -NoNewScope | Out-String
if($LASTEXITCODE -ne 0) {
$CmdString = $Command.ToString().Trim()
throw "Process [$($CmdString)] returned a failure status code [$($LASTEXITCODE)]. The process may have outputted details about the error."
}
return $Output
}
Invoke-ShellExecutable {
($env:CI = "true") -and (npm run test:ci)
} 3>&1 2>&1

Invoke-wmimethod win32_process

Background: I am creating a script to send out a message to everyone in my Domain. I was able to complete this using Invoke-WMImethod and MSG.exe. However, my supervisor wants a more customizable message to be sent. Like changing Color, font size, font style...etc. Which i have created using PowerShell.
Script:
Invoke-WmiMethod -ComputerName $Computer -Class Win32_Process -Name Create -ArgumentList {"C:\x\x\x\Powershell.exe -File `"\\Server\Share\Folder\Script.ps1`""}
When i run this script against my Computer it works perfectly. However, when i attempt to run it on a remote computer it fails.
I don't understand why.
It's the same exact script that i used with MSG.exe, which worked, but it still doesn't work with a powershell script.
I attempted to copy the script to the remote computers 'C:\' and run it from that file path but it still didn't work.
I've verified the file path to Powershell.exe is the same as the script and that the remote workstation can access the .PS1 Script.
However, the script does run and says it is successful with a Return Value of 0. Example:
__GENUS : 2
__CLASS : __PARAMETERS
__SUPERCLASS :
__DYNASTY : __PARAMETERS
__RELPATH :
__PROPERTY_COUNT : 2
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
ProcessId : 8748
ReturnValue : 0
My Suggestion would be to check for the versions on both the machines. The CmdLet you using may not be working on the previous version.
I again have a suggestion to make, you can use the below command to get your work done, if you have powershell Version 3 or above.
$Outputreport = "Test message to send data using port 443"
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }
$wc = new-object System.Net.WebClient
Invoke-RestMethod -Method Post https://hostnamedotcom/cgi-bin/dir-path/$hostname-filename -Body $Outputreport

Powershell Parameters

I am extreme newbie to powershell. I have a script that I want to pass a URL as a parameter. The url runs a PHP process that creates and downloads a PDF file then the script prints the pdf and then deletes the pdf. I cannot get the URL parm to work.
Below is my script
$w=$args[0]
Start $w
$Directory = "C:\Users\pslessor\downloads\"
Get-ChildItem -path $Directory -recurse -include *.pdf | ForEach-Object {Start-Process -FilePath $_.fullname -Verb Print -PassThru | %{sleep 5;$_} | kill }
Remove-Item C:\Users\pslessor\downloads\* -include *.PDF
This script is being executed by a batch file PrintPl.bat
SET ThisScriptsDirectory=%~dp0
SET PowerShellScriptPath=%ThisScriptsDirectory%PrintPl.ps1
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '%PowerShellScriptPath%' %1";
And I am testing with testprint.bat
C:\Wget\PrintPl "https://partners.wayfair.com/print_shipping_docs.php?Print=1&printPackingSlips=1&PackingSlipPOs=CS287851107"
The URL is all in one string this editor is forcing the line feed at .php?
The Error I am getting is
The string starting:
At Line:1 Char:25
+ & 'C:\Wget\Printpl.ps1' <<<< 'https://partners.wayfair.com/print_shipping_docs.php?print;
is missing the terminator: '.
At line:1 Char:85
+ & 'C:\Wget\PrintPl.psl' 'https://partners.wayfair.com/print_shipping_docs.php
?print; <<<<
+ CategoryInfo :ParserError: <https://partner...docs.php?print;:
String> [], ParentContainsErrorRecordException
+ FullyqualifiedErrorid : TerminatorExpectedAtEndOfString
'printPackingSlips' is not recognaized as internal or external command,
Operable program or batch file.
'PackingSlipPOs' is not recognized as an internal or external command,
operable program or batch File
This is happening because when you pass the arguments the command interpreter expands your variables and see this:
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& 'C:\Wget\PrintPl.ps1' https://partners.wayfair.com/print_shipping_docs.php? Print=1&printPackingSlips=1&PackingSlipPOs=CS287851107"
So the command that it is trying to execute is C:\Wget\PrintPl.ps1, and it assumes that what comes next are arguments. Since what it is passed has a space, and is not enclosed in quotes or double quotes it assumes that it is multiple arguments. It sees it as:
Execute this script: C:\Wget\PrintPl.ps1
With the following arguments:
$Args[0]=?
$Args[1]=Print=1&printPackingSlips=1&PackingSlipPOs=CS287851107
To stop this from happening you will need to enclose the URL in quotes as well, so your command should look like this:
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '%PowerShellScriptPath%' '%1'"
Edit: Ok, that didn't work for your case. So we're going to change this a little bit. Instead of -Command I'm going to suggest you use -File. So your Powershell execution line within the batch file will look like this:
PowerShell -NoProfile -ExecutionPolicy Bypass -File "%PowerShellScriptPath%" %*
You should be able to run the batch file exactly as you previously had been. I'm fairly confident that will work for you.

Rails not responding to ffmpeg commands

I am trying to run this command here:
f = open("|ffmpeg -i /Users/joaoh82/Desktop/teste.MP4")
result = f.read()
But I am not getting any response...
But when I try this command in the terminal it works great:
ffmpeg -i /Users/joaoh82/Desktop/teste.MP4
But now on rails code. Funny thing is that when I try the same thing with some else like an echo $PATH it works great! Like:
f = open("|echo $PATH")
result = f.read()
Any ideas!?
ffmpeg -i prints to stderr, which won't be captured by your pipe. You could redirect stderr to stdout:
result = `ffmpeg -i /Users/joaoh82/Desktop/teste.MP4 2>&1`
You probably need to specify the full path to ffmpeg. It might be working in your shell because ffmpeg is in your PATH.
Basically in your shell, type which ffmpeg. Use that full path in your open() call.

Resources