Im making a cool hidden folder passworded USB drive. I have a little image that opens and I want to play music using this code.
set "file=music.mp3"
( echo Set Sound = CreateObject("WMPlayer.OCX.7"^)
echo Sound.URL = "%file%"
echo Sound.Controls.play
echo do while Sound.currentmedia.duration = 0
echo wscript.sleep 100
echo loop
echo wscript.sleep (int(Sound.currentmedia.duration^)+1^)*1000) >sound.vbs
start /min sound.vbs
I want to end the music after the user types the password. Or just the ability to tell it to stop.
I found in another post on here a solution by a user but he doesnt explain how to use it. Here is the link to that post. Link to the post Im new to batch so just giving me a script wont help I kind of need to know how to use it.
This is the script I dont understand how to use that will stop the music. According to the post I linked.
#ECHO OFF >NUL
for /F "usebackq tokens=*" %%G in (
`wmic process where "CommandLine like '%%sound.vbs%%' AND Caption like '%%script.exe%%'" get ProcessID/value ^|find /I "="`
) do (
rem echo %%G
for /F "tokens=2 delims==" %%H in ("%%~G") do echo taskkill /T /F /PID %%H
)
Here is the password code im using.
#echo off
set pass= 123abc
echo Enter Password
set /p ui=
if %ui%==%pass% (goto open)
echo Wrong Password
pause
exit
:open
start folder
How to stop the music
Note taskkill command is echoed merely... Remove echo when debugged.
see instruction by #JosefZ here : https://stackoverflow.com/a/29271203/9222942
remove the 'echo' word from this line :
for /F "tokens=2 delims==" %%H in ("%%~G") do echo taskkill /T /F /PID
will becomes :
for /F "tokens=2 delims==" %%H in ("%%~G") do taskkill /T /F /PID
#ECHO OFF >NUL
for /F "usebackq tokens=*" %%G in (
`wmic process where "CommandLine like '%%sound.vbs%%' AND Caption like '%%script.exe%%'" get ProcessID/value ^|find /I "="`
) do (
rem echo %%G
for /F "tokens=2 delims==" %%H in ("%%~G") do echo taskkill /T /F /PID %%H
)
Related
I'm trying to make a .bat file that pings arbitrary hosts, but my options are not working. Maybe someone can help with this question
Why not scan all devices at once? You can do it in seconds
Create a file named Scan.bat
#echo off
if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & exit /b)
arp -d
setlocal
setlocal enabledelayedexpansion
for /f "usebackq tokens=*" %%a in (`ipconfig ^| findstr /i "192"`) do (
for /f delims^=^:^ tokens^=2 %%b in ('echo %%a') do (
for /f "tokens=1-4 delims=." %%c in ("%%b") do (
set _o1=%%c
set _o2=%%d
set _o3=%%e
set _o4=%%f
set _3octet=!_o1:~1!.!_o2!.!_o3!.
for /L %%a in (1,1,254) do (start /min ping /n 1 /l 1 !_3octet!%%a)
)))
endlocal
Run the above file every time before typing the command below
arp -a | findstr 192 | findstr dynamic
You can then view all the devices connected to your network with this command
I'm making a program that needs a pendrive, and I want detect if a pendrive is in the pc and distinguish he from a internal disk or anything else, somebody can help me?
Here's an example.
#Echo Off
SetLocal EnableExtensions EnableDelayedExpansion
For /F "Skip=2 Tokens=*" %%A In ('WMIC DiskDrive Where InterfaceType^="USB"^
Assoc /AssocClass:Win32_DiskDriveToDiskPartition 2^>Nul') Do (
For /F UseBackQ^ Delims^=^"^ Tokens^=2 %%B In ('%%A') Do (
For /F Delims^=^":^ Tokens^=6 %%C In (
'WMIC Path Win32_LogicalDiskToPartition^|Find "%%B"') Do (
For /F "Skip=1 Delims=" %%D In ('WMIC LogicalDisk Where^
"DeviceID='%%C:'" Get DeviceID^, VolumeName') Do Echo( %%D
Set "_C=!_C!%%C")))
If Not Defined _C Echo( You do not have a USB drive connected && GoTo :EndIt
If "%_C:~,1%" Equ "%_C%" GoTo :Picked
Echo( Enter the USB drive letter from the above [%_C%]:
For /F "Delims=? Tokens=2" %%A In ('Choice /C %_C%') Do Set "Letter=%%A:"
:Picked
If Not Defined Letter (Call :Task %_C%:) Else (Call :Task %Letter%)
:EndIt
>Nul Timeout 5
Exit/B
:Task
Rem Place your commands here
Echo Your selected pen drive is %1
Pause
I want to search all files with .xlsx extension, for now I'm using this:
for /R c:\ %%f in (*.xlsx) do set target=%%f
echo %target%
But, only searchs in "C" and does not includes the hidden files. So, my questions:
1) How can I search in all locations, I mean: C, D, E ... drives?
2) How I can search for hidden files too?
You can try something like that :
#echo off
Color 9A & Mode con cols=70 lines=5
Set "Ext=xlsx"
Title %~nx0 to search all *.%Ext% files
set "Log=%~dp0%Ext%_PATH.txt"
If Exist "%Log%" Del "%Log%"
setlocal ENABLEDELAYEDEXPANSION
for /f "tokens=2" %%i in ('wmic logicaldisk where "drivetype=3" ^|find /i ":"') do (
set "Fixed_Drive=%%i"
Call :ShowMsg !Fixed_Drive!
(
#For /f "delims=" %%x in ('Dir /b /s /a "!Fixed_Drive!\*.%Ext%"') do (
#echo "%%x"
)
)>> "%Log%"
)
Start "" "%Log%"
Exit
::******************************************************************
:ShowMsg
Cls
echo(
echo ***********************************
Echo Please wait a while Scanning "%~1"
echo ***********************************
Timeout /T 2 /nobreak>nul
exit /b
::******************************************************************
Edit :
To make a multiple search by extension like .xlsx .docx at the same time and get a separte log archive per each extension, you should try like this way :
#echo off
Color 9A & Mode con cols=70 lines=5
Set "Ext=xlsx docx"
For %%a in (%Ext%) Do (
if exist "%~dp0%%a_PATH.txt" del "%~dp0%%a_PATH.txt"
Call :Search "%%a" "%~dp0%%a_PATH.txt"
)
For %%a in (%Ext%) Do (
If Exist "%~dp0%%a_PATH.txt" Start "" "%~dp0%%a_PATH.txt"
)
Exit
::**********************************************************************************
:Search <Ext> <Log>
Cls
Title %~nx0 to search all "*.%~1 files"
echo(
echo ***********************************
Echo Please wait a while Scanning "%~1"
echo ***********************************
Timeout /T 2 /nobreak>nul
setlocal ENABLEDELAYEDEXPANSION
for /f "tokens=2" %%i in ('wmic logicaldisk where "drivetype=3" ^|find /i ":"') do (
set "Fixed_Drive=%%i"
(
#For /f "delims=" %%x in ('Dir /A:-D /b /s "!Fixed_Drive!\*.%~1"') do (
#echo "%%x"
)
)>> "%~2"
)
exit /b
::**********************************************************************************
At "for in", hidden files cannot be searched. Using option "/a" of "dir", hidden files can be srarched.
To search all of files with the extension of "xlsx" on a drive, I thought following method. But about this, each drive name has to input by user.
Drive C:
dir c:\*.xlsx /b /s /a
Drive D:
dir d:\*.xlsx /b /s /a
If you want to use data from "dir" at a batch file, how about following script?
#echo off
setlocal enabledelayedexpansion
set ct=0
for /f "usebackq tokens=*" %%a in (`dir c:\*.xlsx /b /s /a`) do (
set target[!ct!]=%%a
set /a ct=!ct!+1
)
set /a ct=%ct%-1
for /l %%i in (0,1,%ct%) do echo !target[%%i]!
The Where command searches 'hidden files', so using a method similar to Hackoo's:
#Echo(Searching...&#(For /F "Skip=1" %%A In ('WMIC LogicalDisk Where^
"DriveType>1 And DriveType!=5 And FreeSpace Is Not Null" Get DeviceID'
) Do #For %%B In (%%A) Do #For /F "Delims=" %%C In (
'Where/F /R %%B\ *.xlsx') Do #Echo=%%C)&Timeout -1
I am relatively new to batch programing and programing altogether, but after searching for hours I found to no avail, this is the script I'm having problems with
set /p filename=What is the file name?:
cls
set /p lines=how many lines are there? (one number):
cls
set line=1
:batch_start
for /f "skip=%line% delims=" %%i in (%filename%.txt) do set "ip=%%i"& for /f "tokens=1,2 delims=[]" %%A in ('ping -a %ip% ^| find "Pinging"') do set ip=%%B& if '%lines%'=='%line%' goto done& echo %ip%& set line==%line%+1
pause
:done
echo Done!
pause
Please help as the code is ony setting %ip% and doing nothing else.
#echo off
set /p filename=What is the file name?:
cls
set /p lines=how many lines are there? (one number):
cls
set line=1
for /f "skip=%line% delims=" %%i in (%filename%.txt) do set "ip=%%i"
setlocal enableDelayedExpansion
for /f "tokens=1,2 delims=[]" %%A in ('ping -a %ip% ^| find "Pinging"') do (
set ip=%%B
if '%lines%'=='!line!' goto done
echo !ip!
set line==!line!+1
)
pause
:done
echo Done!
pause
Is this working as you expect?
how can i kill multiple task of same user we are using this two codes
Code no1
#ECHO OFF
TASKKILL /F /IM explorer.exe
cls
Echo "Please Specify the User ID"
Set /p u=
set USER=%u%#%userdomain%
Echo "Please Specify the PASSWORD"
runas /user:%USER% Explorer.exe
cls
echo "Press any key to Switch Back to Default USer Profile"
Pause
Echo "please enter your password again for verification"
runas /user:%USER% C:\switch.bat
pause
cls
start %windir%\explorer.exe
exit
Code no2 (this File name Switch.bat)
#echo off
TASKKILL /F /IM Explorer.exe
exit
Actually the general idea behind to create this it switches in win XP like win 7 without logging off
Issue is when it switch back to original profile
all the task of the second user doesnt stop
is that any way to stop all task for a specific user which are running
you can try with tskill . It can kill a process and accepts as parameter the user ID:
Kill explorer for the same user
setlocal enabledelayedexpansion
set exe_name=Explorer
for /f "skip=1 tokens=1,2,3" %%S in ('query user') do (
set "current_user=%%S"
if "!current_user:~0,1!" EQU ">" (
for /f "tokens=2 delims= " %%M in ('tasklist ^| find ^"%exe_name%^"') do (
tskill "%%M" /ID:%%U
)
)
)
endlocal
goto :eof
For all other users:
setlocal enabledelayedexpansion
set exe_name=Explorer
for /f "skip=1 tokens=1,2,3" %%S in ('query user') do (
set "current_user=%%S"
if "!current_user:~0,1!" NEQ ">" (
for /f "tokens=2 delims= " %%M in ('tasklist ^| find ^"%exe_name%^"') do (
tskill "%%M" /ID:%%U
)
)
)
endlocal
goto :eof
You can kill all processes of a particular user like this (provided you have admin privileges):
#echo off
taskkill /fi "username eq %1" /t /f
Run the script like this:
C:\>script.cmd joe
However, why don't you simply log the second user off instead of switching back? That would be the obvious (and much cleaner) solution. As admin you can even log off other users on the commandline:
logoff session
You can enumerate the sessions with query session (or qwinsta if the former doesn't work):
#echo off
for /f "tokens=3" %%s in ('qwinsta ^| find /i "joe"') do (
logoff %%s
)