So I am running several instances of my program and I have to be able to distinguish between the instances in a good way from powershell. Since every instance is installed in a separate folder I thought that i could use:
get-process -Name MyProgram* | Select-Object name, path
and get a list showing me the folder from which the process was started. Unfortunately this returns with the path empty.
So I tried a bunch of other properties that might be unique but all of them come back empty.
What am I doing wrong? Or can I do something else perhaps?
I am using windows 8 btw.
Could you use PID? Or does your program start child-processes. Path works for me, like:
Get-Process iexplore | Select-Object ID, Name, Path
Id Name Path
-- ---- ----
10792 iexplore C:\Program Files (x86)\Internet Explorer\IEXPLORE.EXE
13928 iexplore C:\Program Files (x86)\Internet Explorer\IEXPLORE.EXE
17144 iexplore C:\Program Files\Internet Explorer\iexplore.exe
17772 iexplore C:\Program Files\Internet Explorer\IEXPLORE.EXE
20896 iexplore C:\Program Files (x86)\Internet Explorer\IEXPLORE.EXE
Does ExecutablePath or CommandLine return anything?
Get-WmiObject -Class Win32_Process -Filter "Name LIKE 'iexplore%'" | Select-Object ProcessID, Name, ExecutablePath, Commandline
ProcessID Name ExecutablePath Commandline
--------- ---- -------------- -----------
17144 iexplore.exe C:\Program Files\Internet Explorer\iexplore.exe "C:\Program Files\Internet Explorer\iexplore.exe" ...
32016 iexplore.exe C:\Program Files (x86)\Internet Explorer\IEXPLORE.EXE "C:\Program Files (x86)\Internet Explorer\IEXPLORE...
36744 iexplore.exe C:\Program Files\Internet Explorer\IEXPLORE.EXE "C:\Program Files\Internet Explorer\IEXPLORE.EXE" ...
If the process doesn't belong to you, then you need to run it as admin/elevated.
You have to be running with elevated permissions to see the path information of processes you're not the owner of.
Related
# run.bat
cmd /k python.exe "C:\Program Files (x86)\XXX\test.py"
cmd /k cd "C:\Program Files (x86)\XXX\" & python.exe "C:\Program Files (x86)\XXX\test.py"
cmd /k "cd "C:\Program Files (x86)\XXX\" & python.exe "C:\Program Files (x86)\XXX\test.py""
Question> I need to change the working directory to C:\Program Files (x86)\XXX\ then run the command python.exe "C:\Program Files (x86)\XXX\test.py". Several methods have been tested and none of them give me the desired result. They all end up run the command without changing the working directory.
For example,
If I run c:\temp\run.bat, I expect the script first to change to directory of C:\Program Files (x86)\XXX\ then run the python script.
Step 1: Find the short names for the directory with space
dir /X
PROGRA~2 Program Files (x86)
Step 2: Quote all commands
cmd /k "cd C:\PROGRA~2\XXX\ & python.exe C:\PROGRA~2\XXX\test.py"
When I run the command set programfiles in the command prompt, I get
ProgramFiles=C:\Program Files (x86)
ProgramFiles(x86)=C:\Program Files (x86)
However, the following code in python
import os
print os.getenv("programfiles")
or
msgbox %A_ProgramFiles% and %ProgramFiles%
in Autohotkey
or
$env:ProgramFiles
in PowerShell
all results in C:\Program Files
I cannot understand why I'm getting different results for the Program Files Environment Variables in Windows
What you see is the difference between a 32-bit and 64-bit application.
32-bit cmd.exe (%SystemRoot%\SysWOW64\cmd.exe)
C:\>set programfiles
ProgramFiles=C:\Program Files (x86)
ProgramFiles(x86)=C:\Program Files (x86)
64-bit cmd.exe (%SystemRoot%\System32\cmd.exe)
C:\>set programfiles
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
32-bit powershell.exe (%SystemRoot%\SysWOW64\WindowsPowerShell\v1.0\powershell.exe)
PS C:\> dir env:\programfiles*
Name Value
---- -----
ProgramFiles(x86) C:\Program Files (x86)
ProgramFiles C:\Program Files (x86)
64-bit powershell.exe (%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe)
PS C:\> dir env:\programfiles*
Name Value
---- -----
ProgramFiles(x86) C:\Program Files (x86)
ProgramFiles C:\Program Files
I am trying to write a batch file to run several WORD and POWERPOINT file as below:
"C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE" "D:\Files\Literature\Literature Review\Literature-Review.docx" & "C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE" "D:\Files\Literature\Literature Review\outline.docx" & "C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE" "D:\Files\Literature\Questions to be asked\Questions to be asked.docx" & "C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE" "D:\Files\Presaentationen\1. Gruppemeeting\ToDo.docx" & "C:\Program Files (x86)\Microsoft Office\Office14\POWERPNT.exe" "D:\Files\Presaentationen\1. Gruppemeeting\Presentation_Englisch.pptx"
The problem is that only the first file opens. If I close it the next one opens and so on. But I want to open them all at the same time. What should I do? (OS is Windows 7)
Thank you very much.
"C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE" "filename1" "filename2" ...
should open each file in winword.
If you wish to open powerpoint as well, you'd need to start each executable
start "windowtitle" "C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE" "filename1" "filename2" ...
start "windowtitle" "C:\Program Files (x86)\Microsoft Office\Office14\POWERPNT.exe "filename3"
but you would need to add the /w switch to the last executable you start this way, otherwise the commands following will be excuted (which you may not want)
Furthermore, the batch would then proceed when the waited application terminates, so
start "windowtitle" "C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE" "filename1" "filename2" ...
start /w "windowtitle" "C:\Program Files (x86)\Microsoft Office\Office14\POWERPNT.exe "filename3"
would wait until powerpoint exits and then proceed, regardless of whether winword is still open.
windowtitle may be empty, but should not be omitted (ie. use "" if you want, but don't leave out this element)
When cmd runs a GUI application it does not wait for it to complete. (Whether an application is windowed (GUI) or console is determined by a flag in its exe file.)
But you can use
start /wait SomeGuiApp
to force cmd to wait.
However you appear to have the oposite problem: it could be that &. It is designed for conditionally performing one action dependent on the return value from the previous. But return values are not really meaningful for GUI apps.
Why not run them as separate commands: on different lines of the cmd script or separated (IIRC) by a semicolon.
Remember, with command extensions on you can use parentheses to have multiple lines under the control of if etc.
I need a batch file that when I run would show touch input panel (virtual keyboard) when hidden, otherwise if already visible then hide it. The path to the touch input panel is:
C:\Program Files\Common Files\microsoft shared\ink\tabtip.exe
Here's what I've tried so far:
FOR /f "tokens=*" %%a IN ('TASKLIST ^| FINDSTR /i TabTip.exe') DO
( IF "%ErrorLevel%"=="0"
( TASKKILL /IM TabTip )
ELSE
( start "C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe" )
)
PAUSE
This should work:
# Settings
$ProcessName = "TabTip"
$Executable = "C:\Program Files\Common Files\microsoft shared\ink\TabTip.exe"
# Get process
$Process = Get-Process -Name $ProcessName -ErrorAction SilentlyContinue
# Is it running?
If($Process)
{
# Running
# Kill this process
$Process.Kill()
}
Else
{
# Not running
# Start the process
Start-Process $Executable
}
I have tried killing it with
Stop-Process $Process
aswell as with
Stop-Process $Process.Id
but I'm always getting an access denied (not sure why).
However, the Kill() method worked fine, you should use this
I'm trying to replace the programs that run from my startup directory with a batch script. The batch script will simply warn me that the programs are going to run and I can either continue running the script or stop it.
Here's the script as I have written so far:
#echo off
echo You are about to run startup programs!
pause
::load outlook
cmd /k "C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE" /recycle
::load Visual Studio 2008
call "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe"
Both of these commands will load the first program and wait until I close it to load the second. I want the script to load the processes simultaneously. How do I accomplish this?
Edit: When I use the start command it opens up a new shell with the string that I typed in as the title. The edited script looks like this:
start "C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE"
::load Visual Studio 2008
start "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe"
This works:
#echo off
echo You are about to run startup programs!
pause
::load outlook
start /b "" "C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE" /recycle
::load Visual Studio 2008
start /b "" "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe"
Use START like this:
START "" "C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE"
When your path is enclosed in quotes, START interprets it as the title for the window. Adding the "" makes it see your path as the program to run.
There is the start command that will behave much like if you clicked the files in Explorer.