NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums General General Discussion v
« Previous 1 … 15 16 17 18 19 … 159 Next »
get working/batch/file dirs from one line[any dir of it's path too!]

 
  • 0 Vote(s) - 0 Average
get working/batch/file dirs from one line[any dir of it's path too!]
pBS
Offline

Posting Freak

Posts: 4,829
Threads: 182
Joined: Aug 2005
#11
2011-10-11, 04:47 PM (This post was last modified: 2013-02-13, 03:05 AM by pBS.)
This one's a bit flaky...better ways to do it...Sad

Here's a crude way to get your public ip address from batch without service! [no whatismyip,etc]
Using tracert, traces the route to a non-existant website [1.1.1.1, or use *any* address] and watches the server hops as it goes out..
It ignores 192. and 10. and 172.x.x.x adresses so should skip the internal adapter and router..[ymmv tho]
It may need tweaking if you use weird local ip, or multiple routers..
but once you tweak it for your setup if needed, it should work fine from then on...[unless you add another router hop in the mix]

I'm curious to hear what setups it DOESN't work on... let me know.. Smile
here 'tis:

Code:
@for /f "tokens=5,8,9,10,11 skip=3 delims=. " %%e in ('tracert -d -h 5 -w 50 1.1.1.1') do (
if %%f NEQ 192 (if %%f NEQ 10 (if %%f NEQ 172 (@echo %%f.%%g.%%h.%%i
pause
goto :eof
)))
)

or a one liner:
Code:
@for /f "tokens=8,9,10,11 skip=3 delims=. " %%f in ('tracert -d -h 5 -w 50 1.1.1.1') do @if %%f NEQ 192 (@if %%f NEQ 10 (@if %%f NEQ 172 (@echo %%f.%%g.%%h.%%i & goto :eof)))
Replace @echo with 'set publicip=' and you now have a variable you can process further..
Handy for navigating back to your EWA, you could email ip to yourself when it changes..Wink
Enjoy
Hardware: HDHR Prime, HDPVR 1212, Raspberry pi2, VFD display w/LCDSmartie
pBS
Offline

Posting Freak

Posts: 4,829
Threads: 182
Joined: Aug 2005
#12
2012-04-03, 12:09 PM (This post was last modified: 2012-10-26, 11:02 AM by pBS.)
Use a Variable within a for loop or if() statement without using enabledelayedexpansion! [by using call]
'call'ing a function externalizes it..evaluating variables on the fly like enabledelayedexpansion does..
just remember that when 'calling' variables need 2 %% instead of just one on each end

for example:
Code:
if 1==1 (
@set test=1
@echo %test%
)
will output:
Echo is on

whereas:
Code:
if 1==1 (
@set test=1
@[color=#FF0000]call[/color] echo [color=#FF0000]%[/color]%test%[color=#FF0000]%[/color]
)
will output:
1

same as for loops..
Code:
for %%f in (test) do (
set var1=%%f
@set var1=%var1:es=oo%
@echo %var1%
)
@echo %var1%
will output:
Echo is on..
es=oo

but:
Code:
for %%f in (test) do (
set var1=%%f
@call set var1=[color=#FF0000]%[/color]%var1:es=oo%[color=#FF0000]%[/color]
@[color=#FF0000]call[/color] echo [color=#FF0000]%[/color]%var1%[color=#FF0000]%[/color]
)
@echo %var1%
will output:
toot
toot
[i changed var1, replacing es with oo]
Hardware: HDHR Prime, HDPVR 1212, Raspberry pi2, VFD display w/LCDSmartie
pBS
Offline

Posting Freak

Posts: 4,829
Threads: 182
Joined: Aug 2005
#13
2013-02-13, 02:46 AM (This post was last modified: 2013-09-03, 06:32 AM by pBS.)
here's how to detect os verion from batch, as small as i could get it..Smile

Code:
@echo off
REM Check Windows Version
ver | findstr /i "5\.0\." > nul && set osver=2000
ver | findstr /i "5\.1\." > nul && set osver=XP
ver | findstr /i "5\.2\." > nul && set osver=2003
ver | findstr /i "6\.0\." > nul && set osver=Vista
ver | findstr /i "6\.1\." > nul && set osver=Win7
@echo %osver%
pause

you can substitute any command for 'set osver=xxxxx' and just use one line if looking for a certain version..
note: && only runs what's after if the preceding command was successful..



[INDENT][INDENT][INDENT]Detect 32/64bit-ness from batch[/INDENT][/INDENT][/INDENT]

Code:
@IF DEFINED ProgramFiles(x86) (set software=Software\Wow6432Node) else (set software=Software)

basically if there is a variable called ProgramFiles(x86) then you're on 64 bit...32 otherwise always...
[the set software part is my shortcut for registry entries from batch, 64bit things are in Software\Wow6432Node instead of just Software]

Or......
This also works...
Code:
@IF EXIST %SystemRoot%\SysWOW64 (set software=Software\Wow6432Node) else (set software=Software)
Hardware: HDHR Prime, HDPVR 1212, Raspberry pi2, VFD display w/LCDSmartie
pBS
Offline

Posting Freak

Posts: 4,829
Threads: 182
Joined: Aug 2005
#14
2013-02-13, 03:01 AM (This post was last modified: 2013-11-05, 12:11 PM by pBS.)
here's a reg query that cleans up the output and only gives the info you want..[so it can be used in a batch command]
Code:
@for /f "skip=2 tokens=* delims=" %%A in ('[color=#0000FF]reg query "HKLM\software\devnz" /v "GBPVR InstallDir"[/color]') do @set reg=%%A

[b]@rem  These lines remove anything before a TAB [WinXP]
@set  reg=%reg:*    =%
@set  reg=%reg:*    =%

@rem These lines remove anything before a set of 4 spaces [Vista+]
@set reg=%reg:*    REG_=%
@set reg=%reg:*    =%[/b]

@echo "%reg%"
@pause
Had to use a little magic to make it work on xp thru win8...[dang changes to reg.exe output...xp uses tabs, vista+ uses spaces]

of course it's needs more processing for multi line reg entries [REG_MUTLI_SZ, treat \0 as newline]

Use by substituting 'Reg query "HKLM\ etc.' with your query string like: "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CurrentVersion
variable %reg% will have value you requested..use how you like Big Grin

Use it as a function:
Code:
@call :readreg "HKLM\software\devnz" /v "GBPVR InstallDir"
@echo "%reg%"
@pause
goto :eof

:readreg
[COLOR="#0000CD"]@for /f "skip=2 tokens=* delims=" %%A in ('reg query %*') do @set reg=%%A
@set  reg=%reg:*    =%
@set  reg=%reg:*    =%
@set  reg=%reg:*    REG_=%
@set  reg=%reg:*    =%[/COLOR]
this way you can call it inside same batch for many different uses, minimizing code, or save it as a batch file and call it from another batch file..
Code:
call [color=#0000CD]readreg.cmd[/color] "HKLM\software\devnz" /v "GBPVR InstallDir"
@echo %reg%

[EDIT}fixed it for vista+ changes in reg.exe output..
Hardware: HDHR Prime, HDPVR 1212, Raspberry pi2, VFD display w/LCDSmartie
martint123
Offline

Posting Freak

UK, East Yorkshire
Posts: 4,658
Threads: 208
Joined: Nov 2005
#15
2013-02-13, 12:18 PM
My word, haven't things moved on from DOS days ;(
Since giving up working for a living I haven't been getting any of the books or technet stuff as freebies and am well out of touch with all the devious tricks that exist.
pBS
Offline

Posting Freak

Posts: 4,829
Threads: 182
Joined: Aug 2005
#16
2013-08-27, 12:34 AM (This post was last modified: 2013-11-05, 11:46 AM by pBS.)
Here's a useful one, check for admin access! display messages either way..
Works on xp thru win8 Big Grin

Code:
@rem         Check for admin rights and echo msg and exit if none.....
net session >nul 2>&1
    if %errorLevel% == 0 (
        @echo Success: Administrative permissions confirmed.
    ) else (
        @echo Failure: Current permissions inadequate. This script needs to be run with Admin priviledges..
        @echo          Right click on batch file, and select 'run as administrator'
      pause
exit
)
Short version:
Code:
@net session >nul 2>&1 & @if errorlevel 1 @echo NOT Admin!!! & Exit /b
Hardware: HDHR Prime, HDPVR 1212, Raspberry pi2, VFD display w/LCDSmartie
pBS
Offline

Posting Freak

Posts: 4,829
Threads: 182
Joined: Aug 2005
#17
2013-11-05, 11:06 AM (This post was last modified: 2013-11-05, 11:43 AM by pBS.)
here's a handy one for creating complex shortcuts, etc.

to set and use a variable within the same line, like say a 'smart' shortcut, just use 'call' to reference the new variable in subsequent uses..eg:
Code:
%windir%\system32\cmd.exe /c set today=%date:/=-% [b]&[/b] [color=#FF0000]call[/color] set today=%today:~4% [b]&[/b] [color=#FF0000]call[/color] echo The date is:%today% [b]&[/b] @pause

stick that in a shortcut to get a nicely formatted date string displayed... Wink
runs 4 commands involving variables from one line..Big Grin

'call' creates a new thread for a command, thereby forcing it to re-read environment, allowing expanding the variable on the fly..
[the first 'call' needs to be there as it's reading %today:~4% to set a variable]

this specific trick only works for cmdline areas, not in batch files...[no need silly! it's a batch file!]
But 'call' does some interesting things if you play with it..
Hardware: HDHR Prime, HDPVR 1212, Raspberry pi2, VFD display w/LCDSmartie
pBS
Offline

Posting Freak

Posts: 4,829
Threads: 182
Joined: Aug 2005
#18
2013-11-05, 12:03 PM (This post was last modified: 2013-11-05, 12:35 PM by pBS.)
here's a couple of nice sleep cmds i cooked up...
place in your path[like in %windir%] and call it from YOur batch file like: "call sleep 7" to sleep 7 seconds.
shows a nice countdown like: sleep 7 6 5 4 3 2 1
Code:
@echo off
set delay=%1
if not defined delay set delay=1
echo|set /p=Sleep
for /L %%f in (%delay%,-1,1) do (echo|set /p=%%f
ping 1.1.1.1 -w 1000 -n 1 >NUL)
echo.

or short version
Code:
@ping 1.1.1.1 -w 1000 -n [color=#0000FF]7[/color] >NUL
Pings 1.1.1.1 with a wait of 1 second [-w 1000] 7 times [-n 7] = 7 seconds Big Grin
[change the 7 for the amount of seconds you want to delay...
Hardware: HDHR Prime, HDPVR 1212, Raspberry pi2, VFD display w/LCDSmartie
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)

Pages (2): « Previous 1 2


Possibly Related Threads…
Thread Author Replies Views Last Post
  VidImport not working tesla1886 36 10,066 2023-01-24, 06:29 PM
Last Post: mvallevand
  Comskip config file spudjg1 0 2,033 2019-08-26, 02:49 PM
Last Post: spudjg1
  TS and PART file? Download/recording tv streams joeijm 5 3,722 2018-03-25, 01:53 AM
Last Post: joeijm
  download button not working momofterrors 0 1,581 2016-06-20, 11:16 PM
Last Post: momofterrors
  Not saving in s01e01 file format jeflatt 4 2,964 2015-09-30, 08:26 PM
Last Post: mvallevand
  Replace video file without windows telling apps the original was deleted? ATHiker 0 1,641 2013-11-25, 09:23 PM
Last Post: ATHiker
  Working on Server 2012 darrenmunday 3 3,632 2013-10-31, 09:47 PM
Last Post: jyan_osu
  <Enter> to drop a line in forum posting screen no loger works? jksmurf 3 2,349 2013-09-28, 09:44 AM
Last Post: whurlston
  H/W Quick sync transcoding from the command line. mvallevand 2 3,504 2013-03-23, 08:25 AM
Last Post: pBS
  Need Help With Video File Types bdgbill 8 3,976 2012-12-30, 11:43 PM
Last Post: Reddwarf

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode