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/
Related
In Windows 7, I have an executable A.exe. I want that when the user launches it (by double click), it prompts for administrator privileges. I know it can be done graphically by selecting "Run this program as an administrator" then pressing "Change settings for all users" in the properties dialog, like this :
But I need a command line that does exactly the same thing. How to achieve that ?
EDIT : I don't want to run A.exe as admin from the command line. For now A.exe doesn't prompt for admin privileges during launch. I want a batch program B.bat such that when I launch B.bat, it will change this behavior of A.exe. So after successful execution of B.bat, when any user launches A.exe by double click (not from command line), it prompts for admin privileges. B.bat doesn't execute A.exe, it only changes this "setting" of A.exe. I now it's not so easy to understand ...
You can use from runas.exe in CMD
>runas.exe
RUNAS USAGE:
RUNAS [ [/noprofile | /profile] [/env] [/savecred | /netonly] ]
/user:<UserName> program
RUNAS [ [/noprofile | /profile] [/env] [/savecred] ]
/smartcard [/user:<UserName>] program
RUNAS /trustlevel:<TrustLevel> program
/noprofile specifies that the user's profile should not be loaded.
This causes the application to load more quickly, but
can cause some applications to malfunction.
/profile specifies that the user's profile should be loaded.
This is the default.
/env to use current environment instead of user's.
/netonly use if the credentials specified are for remote
access only.
/savecred to use credentials previously saved by the user.
/smartcard use if the credentials are to be supplied from a
smartcard.
/user <UserName> should be in form USER#DOMAIN or DOMAIN\USER
/showtrustlevels displays the trust levels that can be used as arguments
to /trustlevel.
/trustlevel <Level> should be one of levels enumerated
in /showtrustlevels.
program command line for EXE. See below for examples
Examples:
> runas /noprofile /user:mymachine\administrator cmd
> runas /profile /env /user:mydomain\admin "mmc %windir%\system32\dsa.msc"
> runas /env /user:user#domain.microsoft.com "notepad \"my file.txt\""
NOTE: Enter user's password only when prompted.
NOTE: /profile is not compatible with /netonly.
NOTE: /savecred is not compatible with /smartcard.
Found a solution ! The key is to embed a manifest file to the exe.
I would like to have the console window kept open when running a scheduled task which executes a batch file. If I run it manually meaning execute the batch file the window stays open but through task scheduler it doesn't open but I can see the task is still running. I put a pause at the end to do this.
#echo off
TITLE PROCESS_MGR
tasklist /FI "IMAGENAME eq JOESMO.exe" | find /I "JOESMO.exe">nul &&(echo PROCESS
JOESMO.exe IS ALREADY RUNNING!
echo %DATE%
echo %TIME%
pause
) || (
echo JOESMO PROCESS IS NOT RUNNING
cmd /c start "JOESMO.exe" "C:\Users\xxxx\Documents\
Visual Studio 2010\Projects\Projects2013\JOESMO.exe"
pause)
I found this suggestion cmd /k myscript.bat but having creating the task in task scheduler for windows server 2008 I am not sure where to apply this. I added /k to the add arguments box in edit action in task.
In the Scheduled Task dialog, just before the name of the batch file it's going to run (it's labeled Program/script. You now have something like:
myscript.bat
Change it to
cmd
Add the following to the **Add Arguments (optional) entry:
/k "C:\My Batch File Folder\MyScript.bat"
Tested on my system (Win7 64-bit), and it worked perfectly. I'm looking at the open command window it created as I type this text. :-)
Unfortunately Ken's solution didn't work for me on a Windows 2008 R2 Std server, I was able to launch an interactive window by modifying the scheduled tasks setting using schtasks.exe
In a command window I did the following command:
schtasks /Change /TN "My Task" /IT
However that does require you be logged in as the same user context in which the scheduled task is executing. So if your scheduled task is use the localsystem "taskaccount" then you will have to log into the system as the "taskaccount" user.
Oddly enough it worked when I manually run the task but it didn't pop for me when it kicked off at a scheduled time.
Ken's answer didn't worked for me.
Found this way of doing :
in your BAT file (create one if you only have an EXE) :
start C:/Absolute/Path/To/MyScript.exe myScriptArg
works like a charm !
Note: In the scheduled task, you must check "Exec only if user is logged"
Create a shortcut to the Batchfile and put that in the action. Worked for me
I tried all of the above, but they did not work for me. Here is what I did to get this to work:
Platform
Windows Server 2003 R2 SP2
ActivePERL v5.10.1
Steps
Create DOS BATCH script -- this runs the actual program, ie, myscript.bat
Create PERL script to call the DOS batch script, ie, myscript.pl
myscript.pl is a 1-line script: system("e:\scripts\myscript.bat");
Create scheduled task: perl myscript.pl
The DOS command prompt window now always opens up. And more importantly, the task now successfully runs and completes. NOTE: The scheduled task RunAs user is logged in to the server.
I would like to make my installer silent. I would like to have flexibility to make installer silent or not depending on a command line option. In doc, I have found this to launch NSIS script compilation:
"C:\Program Files\NSIS\makensis.exe" "D:\Produts\folder\Install\nsis\MyApp.nsi"
this is working. By default, this is generating a non silent installer. To have a silent installer (with a command line option only), i tried this
"C:\Program Files\NSIS\makensis.exe" \S "D:\Produts\folder\Install\nsis\MyApp.nsi"
but \S is not a recognized option. How can i make installer silent with command line option?
I can find this in doc
4.8.1.36 SilentInstall
normal|silent|silentlog Specifies whether or not the installer should
be silent. If it is 'silent' or 'silentlog', all sections that have
the SF_SELECTED flag are installed quietly (you can set this flag
using SectionSetFlags), with no screen output from the installer
itself (the script can still display whatever it wants, use
MessageBox's /SD to specify a default for silent installers). Note
that if this is set to 'normal' and the user runs the installer with
/S (case sensitive) on the command line, it will behave as if
SilentInstall 'silent' was used. Note: see also LogSet.
See section 4.12 for more information.
so that i feel abused
Or should some instruction be added to NSIS script, so that compilation is receptive to /S option ?
Tried it with -S and not working either.
Thanks and regards
/S option is available for your installer, not the makensis.exe. So you can run the installer in silent mode from commandline:
MyApp.exe /S
In case you want to build installer to be always silent, you can use following technique:
In the .onInit function:
Function .onInit
!ifdef IsSilent
SetSilent silent
!endif
FunctionEnd
And then build the installer with /D option to define the IsSilent constant:
makensis.exe /DIsSilent MyApp.nsi
That means, in case you build with /D option like above, the installer will be always silent; without /D option your installer will be non-silent by default and still you can run it from commandline MyApp.exe /S to be silent.
If you want to COMPILE the NSI script silently from a command line, that is not the same as having the installer run silently.
In my compile batch scripts, I use:
c:\progra~1\nsis\makensis /V0 .\sample.nsi | findstr /b /r /c:"YouCantFindMe"
The /V# option suppresses all output but still includes a ribbon/banner when the compiler starts (see NSIS command line option documentation. Piping all output through "findstr" suppresses that output as well.
I have a program which requires Administrative privileges that I want to run from a batch file. What command can I run from command line will run my program with administrative privileges? I'm okay with the pop-up window asking for permission. Additionally, the file needs to be able to run from anywhere on a computer so additional files are run from ./src. The problem is that if I right-click and choose "run as administrator" it changes my current directory so ./src no longer works. If I disable UAC on my machine then everything runs fine. Thank you!
Look here: https://superuser.com/a/269750/139371
elevate seems to be working, calling
C:\Utils\bin.x86-64\elevate.exe -k dir
executes dir in the "current directory" where elevate was called.
This is tough, Microsoft provides no utility to do this (mostly because giving a batch file that ability breaks security), except for RunAs, and that requires that the Administrator account be activated.
There IS a JScript program that can do something similar, by using SendKeys to open the Start menu and type cmd[CTL]+[SHIFT]+[ENTER] which will launch a Command-Line shell.
Save the following as as .js file, like StartAdmin.js:
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys("^{esc}cmd^+{ENTER}"); The equivilent of [CTRL]+[ESC] cmd [CTRL]+[SHIFT]+[ENTER]
To run StartAdmin.js from a batch file, you will need the following line:
wscript StartAdmin.js
To launch from a particular directory and launch a batch file, change line 2 in StartAdmin.js to something like:
WshShell.SendKeys("^{esc}cmd /C "cd %userprofile% & batchfile.bat"^+{ENTER}");
/C switch tells it to run the commands, then close the command-line window.
/K would leave the command window open after it exited the batch file.
To help you understand the SendKeys commands:
+=[Shift Key]
^=[Control Key]
{esc}=[Escape Key]
{enter}=[Enter Key]
To learn more about using CMD.EXE, type CMD /? at the command prompt.
This is a very untidy and ugly way to do it, but it's the only way I know how using only the tools that come with Windows.
Context: Oracle Enterprise Manager has a feature to "execute host command." If into that feature I enter "dir c:\temp" then the output window echos the command and then shows a directory listing. If into that feature I enter "powershell dir c:\temp" the output window shows only the echo'd command. No directory listing. If on the target machine I enter those two commands in both cases I get the echo'd command followed by a directory listing.
I hypothesize that what I see in the cmd.exe window on the client blends two stdout streams: one from the cmd.exe itself and one from the invoked process (powershell dir c:\temp). The Oracle thing seems to recognize only the cmd.exe's stdout.
Is there some way I can force the stdout from the invoked process to be in the cmd.exe's stdout stream so that Oracle will recognize it and the thing I am trying to build will work?
I don't think you can directly pipe the output from one program back into STDOUT of a parent cmd.exe - assuming that is what Oracle is doing at some level.
That being said, you could try something clever like the following:
cmd /c "powershell -Command ""& echo Hello" > %TEMP%\a.txt & TYPE %TEMP\a.txt
Basically this is capturing the output from PowerShell, placing it in a temporary file, then dumping that file back onto STDOUT in cmd.exe. A nice touch would be cleaning up the temp file with a & DEL %TEMP%\a.txt on the end of the command.
You will probably need to toy around with the command line to account for any quirks in how Oracle is passing things along - my guess is that it is invoking cmd.exe /c directly so you can probably leave that part off.