Jump to content

script-expanding variable to drive letter


 Share

Recommended Posts

Just a little thought.

Wouldn't it be easier to skip the whole "delims" thing and use:

FOR /F "TOKENS=15" %%A IN ('IPCONFIG /ALL^|FIND "DHCP Server"') DO @SET DHCPSERVER=%%A

or if you insist in using delims use this:

FOR /F "TOKENS=2,* DELIMS=:. " %%A IN ('IPCONFIG /ALL ^| FIND "DHCP Server"') DO @SET DHCPSERVER=%%B

BTW: Delims doesn't treat an uppercase and lowercase character the same way.

Edited by jjvs
Link to comment
Share on other sites


Just a little thought.

Wouldn't it be easier to skip the whole "delims" thing and use:

FOR /F "TOKENS=15" %%A IN ('IPCONFIG /ALL^|FIND "DHCP Server"') DO @SET DHCPSERVER=%%A

Yes you could also forget the counting too!

FOR /F "TOKENS=*" %%# IN ('IPCONFIG /ALL^|FIND "DHCP Server"') DO SET "DHCPSERVER=%%#" & CALL SET "DHCPSERVER=%%DHCPSERVER:*: =%%"

Link to comment
Share on other sites

the last part doesn't seem to work. I get that DHCPSERVER equals with %DHCPSERVER:*: =%

CALL SET "DHCPSERVER=%%DHCPSERVER:*: =%%"

It works fine on all of my operating systems!

Try the following exactly as is, (as a verification check):

@ECHO OFF & SETLOCAL ENABLEEXTENSIONS
FOR /F "TOKENS=*" %%# IN ('IPCONFIG /ALL^|FIND "DHCP Server"') DO (
SET "DHCPSERVER=%%#" & CALL SET "DHCPSERVER=%%DHCPSERVER:*: =%%")
ECHO=[%DHCPSERVER%]
PING -n 6 127.0.0.1 1>NUL

Link to comment
Share on other sites

Yes you could also forget the counting too!

FOR /F "TOKENS=*" %%# IN ('IPCONFIG /ALL^|FIND "DHCP Server"') DO SET "DHCPSERVER=%%#" & CALL SET "DHCPSERVER=%%DHCPSERVER:*: =%%"

Also:

SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F "TOKENS=2 DELIMS=:" %%# IN ('IPCONFIG /ALL^|FIND "DHCP Server"') DO SET DHCPSERVER=%%#&SET DHCPSERVER=!DHCPSERVER:~1!

But we are using the & :ph34r:

;)

jaclaz

Link to comment
Share on other sites

thank you jaclaz for the guides. I'll read them tomorrow. Right now I have another problem. Stupid comma or something :D Tomorrow I'll read those guides and if I can't find a solution I'll post here :)

Link to comment
Share on other sites

didnt' found a solution for the other problem.

start "%temp%\rd\1\update\update.exe" /q /n /z

this is the command. I get invalid switch - "/q"

if I run this command from a path that contains no spaces there is no problem. but I wanted to run it from temporary folder so I have to use quotes but doing so it won't recognize the parameters. so how to use those switches when I have quotes?

Link to comment
Share on other sites

didnt' found a solution for the other problem.

start "%temp%\rd\1\update\update.exe" /q /n /z

this is the command. I get invalid switch - "/q"

if I run this command from a path that contains no spaces there is no problem. but I wanted to run it from temporary folder so I have to use quotes but doing so it won't recognize the parameters. so how to use those switches when I have quotes?

Try putting a TITLE to it:

http://ss64.com/nt/start.html

Try putting the parameters inside the quotes, i.e.:

start "MyWindow" /WAIT "%temp%\rd\1\update\update.exe /q /n /z"

jaclaz

Link to comment
Share on other sites

It doesn't even require a title, (just the quotes for one):

START "" /wait "%TEMP%\RD\UPDATE\UPDATE.EXE" /q /n /z

In fact it's very likely that you dont even need to use start at all!

"%TEMP%\RD\UPDATE\UPDATE.EXE" /q /n /z

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.


×
×
  • Create New...