I have IE8 add-on that needs to know command line arguments specified by user.
The problem is that real processes have command lines:
c:\program files\Internet Explorer\iexplore.exe SCODEF:5740 CREDAT:79873
c:\program files\Internet Explorer\iexplore.exe SCODEF:5740 CREDAT:79880
instead of
c:\program files\Internet Explorer\iexplore.exe www.yahoo.com
c:\program files\Internet Explorer\iexplore.exe www.google.com
So how can I get real arguments from add-on?
In IE8, you cannot easily do this. The command line arguments are sent to the LCIE Frame process, and only the LCIE process information is passed to the LCIE Tab process. Any command line data is passed as flags to the tab process using shared memory.
To do what you ask, you'd need to look at the SCODEF command line parameter to find the process identifier of the hosting LCIE Frame process, then examine the command line of THAT process.
It might be helpful to understand why you want to do this at all.
Related
I am trying to install Metricbeat on a Windows 10 machine so we can start monitoring it. When I open Powershell and run the following commands:
PS > .\metricbeat.exe modules list
I get the error
I copied that command as is from the Metricbeat documentation. I have seen videos on youtube of people running similar commands successfully. Please, why am I getting that error and what can I do to get my metricbeat.exe powershell commands to work?
You're copying the command TOO literally.
you've entered in the prompt PS > .\metricbeat.exe modules list
where you should have entered .\metricbeat.exe modules list
the latter executes modules list action against an application named "metricbeat.exe" located in .\ which indicates the current directory.
the former executes a redirection > of the output of an application named PS or get-process with input of .\metricbeat.exe modules and an argument of list.
wherever you copied this command from intended "PS >" to represent the beginning of the prompt and you don't need to include it.
Just like the error says... :P
I have an app deployed on a server that runs a PowerShell command to launch headless Chrome and print a website as a PDF but it fails to generate the file.
I tried running the command directly from PowerShell. It seems that when I try to generate the file in C:/Program Files or a folder within it, it silently fails. But then to some folders, like Download or where the app is deployed, it generates it fine. And to even other locations, like C:, it shows that I am missing permissions.
Chrome is installed on the server. I also tried this on my local machine and I'm getting the same results.
This is the failing command I'm using to try and generate a pdf within Program Files folder:
Start-Process -FilePath "C:\Program Files\Google\Chrome\Application\chrome.exe" -ArgumentList "--headless","--print-to-pdf=C:\Program Files\pdfFromPowershell.pdf","--no-margins","--enable-logging","https://google.com"
Command succeeds if the target folder is pointed to Downloads.
Why can't I generate a PDF within C:/Program Files folder (and possibly others) and what can I do to fix this?
Edit: I am actually using the following syntax for the command:
$chrome='C:\Program Files\Google\Chrome\Application\chrome.exe'; & $chrome --headless --print-to-pdf-no-header --print-to-pdf='C:\Program Files\temp\pdfFromPowershell.pdf' --no-margins https://google.com
The issue comes from Chrome.exe not understanding PowerShell's way of quoting, where it just wants double quotes for the path:
Start-Process -FilePath "C:\Program Files\Google\Chrome\Application\chrome.exe" `
-ArgumentList "--headless",
"--print-to-pdf=""C:\Program Files\pdfFromPowershell.pdf""",
"--no-margins","--enable-logging","https://google.com"
The need for double double-quotes only comes when you're looking to escape the quotes within a pair of double quotes, whereas single quotes would work too. I know, confusing, so here's an example:
# escape the double quotes inside double quotes by doubling quotes inside.
"--print-to-pdf=""C:\Program Files\pdfFromPowershell.pdf"""
# using single quotes this should work as well, where only one pair is needed.
'--print-to-pdf="C:\Program Files\pdfFromPowershell.pdf"'
For windows 7/8/9/10/11 users native inbuilt MSEdge can do this very simply (no need to add another chromium or slow it down it is instant from a cmd line or shortcut)
For 32bit users run
"C:\Program Files\Microsoft\Edge\Application\msedge.exe" --headless --print-to-pdf="C:\whichever folder\PDFfromCMD.pdf" https://google.com
For 64bit users run
"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" --headless --print-to-pdf="C:\whichever folder\PDFfromCMD.pdf" https://google.com
Note --no-margin or --no-margins does nothing other than make the line longer, and older --export-tagged-pdf is no longer needed as its the current default, however you may wish to add --print-to-pdf-no-header or some other options to slow down premature building as its so fast the html may not have fully loaded so perhaps you may use --run-all-compositor-stages-before-draw
Microsoft docs will refer you to a list of switches for chrome which can be found at https://peter.sh/experiments/chromium-command-line-switches/
so run this way we can print and view this question (and answers) note I did not switch off headline(s) so have both a timestamp and full title, and in the footline(s) a hyperlink to this page and number of pages.
"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" --headless --print-to-pdf="%userprofile%\desktop\pdfFromcmd.pdf" --enable-logging https://stackoverflow.com/questions/72018079/why-cant-chromes-print-to-pdf-powershell-command-generate-a-pdf-to-some-fold && "%userprofile%\desktop\pdfFromcmd.pdf"
I have to run the following command remotely on another server, the arguments are prefixed with !=:
wdrspc.exe !=BATCHTEST1,LGTY_PLAN_01
This works (but the exe fails because I'm not passing in any arguments):
psexec \\kiklogiappsd "c:\Program Files (x86)\Logility\SPC8.0\wdrspc.exe"
This does not work (psexec says system cannot find the file specified):
psexec \\kiklogiappsd "c:\Program Files (x86)\Logility\SPC8.0\wdrspc.exe !=BATCHTEST1,LGTY_PLAN_01"
I'm stumped, is it the != syntax throwing off psexec?
The correct command line would be:
psexec \\kiklogiappsd "c:\Program Files (x86)\Logility\SPC8.0\wdrspc.exe" !=BATCHTEST1,LGTY_PLAN_01
The program arguments should not be in quotes with the program path, or they'll be interpreted as part of the program path. When you quote a space in a command line argument, that tells the shell that the space is part of the argument, rather than separating two arguments. That's why you quote anything in C:\Program Files (x86). But you want an argument-separating space between the program path and its arguments.
I got some strange behaviour when executing a powershell script.
When I run my script using the ISE it works just fine.
When I open Powershell.exe and run my script it works just fine.
When I open cmd, and start my script using powershell.exe -noexit
./myscript.ps1, myscript works just fine.
When I double-click myscript however, powershell opens for some milliseconds, I see that it shows some error (red font) and the powershell window closes. I'm unable to track down the error causing this problem since the powershell windows closes to fast.
I even tried one single big try-catch block around my hole script, catching any [Exception] and writing it down to a log file. However: the log file is not generated (catch is not called).
How can I track that issue? What could possibly be causing the trouble?
Please note that my execution-policy is set to unrestricted.
Before trying the suggestion invoke this to see your current settings (if you want restore them later):
cmd /c FType Microsoft.PowerShellScript.1
Then invoke this (note that you will change how your scripts are invoked "from explorer" by this):
cmd /c #"
FType Microsoft.PowerShellScript.1=$PSHOME\powershell.exe -NoExit . "'%1'" %*
"#
Then double-click the script, it should not exit, -NoExit does the trick. See your error messages and solve the problems.
But now all your scripts invoked "from explorer" keep their console opened. You may then
remove -NoExit from the above command and run it again or restore your
original settings.
Some details and one good way to invoke scripts in PS v2 is here.
Unfortunately it is broken in PS v3 - submitted issue.
by default, for security reason when you double clic on a .ps1 file the action is : Edit file, not Run file .
to execute your script : right-click on it and choose run with powershell
I also wasn’t able to run a script by double clicking it although running it manually worked without a problem. I have found out that the problem was in the path. When I ran a script from a path that contained spaces, such as:
C:\Users\john doe\Documents\Sample.ps1
The scipt failed to run. Moving the script to:
C:\Scripts\Sample.ps1
Which has no spaces, solved the problem.
This is most likely an issue with your local Execution Policy.
By default, Powershell is configured to NOT run scripts that are unsigned (even local ones). If you've not signed your scripts, then changing your default double-click 'action' in Windows will have no effect - Powershell will open, read the execution policy, check the script's signature, and finding none, will abort with an error.
In Powershell:
Help about_execution_policies
gives you all the gory details, as well as ways to allow unsigned scripts to run (within reason - you'd probably not want to run remote ones, only ones you've saved onto the system).
EDIT: I see at the tail end of your question that you've set Execution Policy to 'unrestricted' which SHOULD allow the script to run. However, this might be useful info for others running into execution policy issues.
If you would catch the error you will most likely see this
The file cannot be loaded. The file is not
digitally signed. The script will not execute on the system. Please
see "Get-Help about_signing" for more details.
Because you are able to run it from the shell you started yourself, and not with the right mouse button click "Run With PowerShell", I bet you have x64 system. Manually you are starting the one version of PowerShell where execution policy is configured, while with the right click the other version of the PowerShell is started.
Try to start both version x64 and x86 version and check for security policies in each
Get-ExecutionPolicy
I was in exactly the same situation as described in the question : my script worked everywhere except when double-clicking.* When I double-clicked a powershell windows would open but then it will close after a second or so. My execution-policy is also set to unrestricted.
I tried the selected answer concerning FType Microsoft.PowerShellScript.1 but it didn't change anything.
The only solution I found was a work around: create a bat file which start the powershell.
Create a file, copy this and modify the path : powershell.exe -File "C:\Users\user\script\myscript.ps1"
Save it as a .bat
Double-click the bat
I also used .ahk to start my powershell with a shorcut and it didn't work when pointing directly to the powershell. I had to point to the .bat
Is there a command line syntax in which returns the Image Path / Location of the *.exe on the task manager?
I'm using Windows XP Professional Service Pack 3, I'm aware of the tslist(tasklist) command, but I only get all running *.exe files.
There is no way from XP's Task Manager to get this info (Vista on up, however, can show this info). Other apps, like MS/SysInternals' "Process Explorer" GUI can show you the full path of all exe's.
Alternatively, a built-in process called WMIC, which uses WMI, can give you this info as in Ramesh's answer:
WMIC PROCESS get Caption,Commandline,Processid
Or, to output to a file and not the command prompt window:
WMIC /OUTPUT:C:\ProcessList.txt PROCESS get Caption,Commandline,Processid
Note: the command prompt will need to have admin rights to launch WMIC.
The commands above will show you output like the following, which includes the PID, process name, full path, and switches passed to the command:
Caption CommandLine
ProcessId
System Idle Process
0
helpctr.exe "C:\WINDOWS\pchealth\helpctr\binaries\helpctr.exe" -mode hcp://system/sysinfo/msinfo.xml
4852
helpsvc.exe "C:\WINDOWS\PCHealth\HelpCtr\Binaries\HelpSvc.exe" /Embedding
1908
cmd.exe "C:\WINDOWS\system32\cmd.exe"
4308
cmd.exe "C:\WINDOWS\System32\cmd.exe" /k cd c:\ && color 71 & & title Admin Command Prompt - %username%
You can open the system information tool under Accessory/system tools to see the actual image path along with its PID.
This may be useful for you: http://www.raymond.cc/blog/determine-program-path-from-task-manager-for-each-program-in-windows-xp-windows-server-2003/