Code: Select all
@echo off
set mypid=%PID%
%PID% would be a system variable containing PID of a process asking for it.
If you are familiar with OpenVMS here is its equivalent:
Code: Select all
$ mypid=F$GETJPI ("","PID")
I don't want to use tasklist because:
- if I make a tasklist search for an image name (or a window title) there is a chance that there is more than one on the system with the same name
Can WMIC do this?
If not then I guess TASKLIST would do the job (based on viewtopic.php?p=21175#p21175):
Code: Select all
@echo off
set titl=RANDOMTITLE%RANDOM%
title %titl%
for /f tokens^=3^ delims^=^" %%a in ('tasklist /nh /v /fi "WINDOWTITLE eq %titl%" /fo csv') do (
echo %%a
)
The problem is that there is a chance that two TITLEs are the same on the system.
So if there is another way that would be great.
Then I guess always adding some more %RANDOM% numbers to the TITLE would elimiate the chance of making two identical TITLEs on the system.
The main reason why I need this is that this is the only unique number on the system so I can use it in temporary filenames. Using %RANDOM% in a batch file is not 100% secure method. PID is because not two processes can have identical PIDs.
Thanks,
Saso