akourafas
asked on
How do I use the FOR /f statement to remove unwanted characters and set an enviroment variable
Step1
for /f "eol=; tokens=6 delims=\ " %%i in ("%TEMP%") do set TSSID=%%i
(This works properly & TSSID= the users terminal ID fine)
Test1
'REGfree.EXE -listvalue "HKCU\Software\Microsoft\W indows NT\CurrentVersion\Windows\ Device
(this generates the value "HP Laserjet 4000 Series/BOB/Session 3,winspool,TS007)
Step2
for /f "Tokens=2 Delims=, " %%i in ('REGfree.EXE -listvalue "HKCU\Software\Microsoft\W indows NT\CurrentVersion\Windows\ Device"') do set prt=%%i
(this generatesthe value "HP 3") Thats not what I was trying to do :-)
I would like to retrive the "HP Laserjet 4000 Series/BOB/Session 3" portion of the query
for /f "eol=; tokens=6 delims=\ " %%i in ("%TEMP%") do set TSSID=%%i
(This works properly & TSSID= the users terminal ID fine)
Test1
'REGfree.EXE -listvalue "HKCU\Software\Microsoft\W
(this generates the value "HP Laserjet 4000 Series/BOB/Session 3,winspool,TS007)
Step2
for /f "Tokens=2 Delims=, " %%i in ('REGfree.EXE -listvalue "HKCU\Software\Microsoft\W
(this generatesthe value "HP 3") Thats not what I was trying to do :-)
I would like to retrive the "HP Laserjet 4000 Series/BOB/Session 3" portion of the query
ASKER
When i run this:
'REGfree.EXE -listvalue "HKCU\Software\Microsoft\W indows NT\CurrentVersion\Windows\ Device
I get:
REG_SZ HP Laserjet 4000 Series/RKM/Session 3,winspool,TS007
when trying to get:
HP Laserjet 4000 Series/RKM/Session 3
this part: "For /f "Tokens=2........."
extracted th HP
The number 3 was the script value extracted using:
for /f "eol=; tokens=6 delims=\ " %%i in ("%TEMP%") do set TSSID=%%i
Thanks for the quick response
'REGfree.EXE -listvalue "HKCU\Software\Microsoft\W
I get:
REG_SZ HP Laserjet 4000 Series/RKM/Session 3,winspool,TS007
when trying to get:
HP Laserjet 4000 Series/RKM/Session 3
this part: "For /f "Tokens=2........."
extracted th HP
The number 3 was the script value extracted using:
for /f "eol=; tokens=6 delims=\ " %%i in ("%TEMP%") do set TSSID=%%i
Thanks for the quick response
ASKER
Heres the script:
net use lpt1: /delete /y
for /f "eol=; tokens=6 delims=\ " %%i in ("%TEMP%") do set TSSID=%%i
for /f "Tokens=2 Delims=, " %%i in ('REGfree.EXE -listvalue "HKCU\Software\Microsoft\W indows NT\CurrentVersion\Windows\ Device"') do set prt=%%i
set TSPrinterName=%prt% %TSSID%
rundll32 printui.dll,PrintUIEntry /Xs /n "%TSPrinterName%" sharename "TSPrinter%TSSID%" attributes +Shared
net use lpt1: \\127.0.0.1\TSPrinter%TSSI D% /y
:end
net use lpt1: /delete /y
for /f "eol=; tokens=6 delims=\ " %%i in ("%TEMP%") do set TSSID=%%i
for /f "Tokens=2 Delims=, " %%i in ('REGfree.EXE -listvalue "HKCU\Software\Microsoft\W
set TSPrinterName=%prt% %TSSID%
rundll32 printui.dll,PrintUIEntry /Xs /n "%TSPrinterName%" sharename "TSPrinter%TSSID%" attributes +Shared
net use lpt1: \\127.0.0.1\TSPrinter%TSSI
:end
aah, ok. In which case, I'd do it like this :
for /f "tokens=2* eol=," %%i in ('REGfree.EXE -listvalue "HKCU\Software\Microsoft\W indows NT\CurrentVersion\Windows\ Device"') do set prt=%%i
for /f "tokens=2* eol=," %%i in ('REGfree.EXE -listvalue "HKCU\Software\Microsoft\W
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
for /f "tokens=2 delims=," %%i in ('REGfree.EXE -listvalue "HKCU\Software\Microsoft\W