For F/ Tokens query computer and and use information

May 16, 2014 at 12:46:11
Specs: Windows 7
need to get first two letters of computer name and then use that information to create powerpoint default presentation based on that information using existing LTR and A4 paper size presentations in each user's profile.
have batch file to copy presentations into each profile but need a way to copy/rename LTR or A4 into blank.potx depending on computer name.

See More: For F/ Tokens query computer and and use information

Report •


#1
May 17, 2014 at 21:40:26
I'm clueless as to the logistics. The mechanics I may be able to help. Maybe a somewhat more "nuts and bolts" description, and a couple of examples of Input material and Output desired from it?

Report •

#2
May 18, 2014 at 12:36:08
You don't specify the script language, but consider the following:

Batch script:

echo %computername:~0,2%

VBScript:

WScript.Echo Left(CreateObject("WScript.Shell").Environment("Process")("ComputerName"), 2)

VBA:

MsgBox Left(Environ("ComputerName"), 2)

PowerShell:

-join $env:ComputerName[0..1]

How To Ask Questions The Smart Way


Report •

#3
May 19, 2014 at 04:18:30
Razor2.3 - looking for batch file, I have the first two chararacters of computer but need to use that information to rename powerpoint.potx file to blank.potx depending on result of computer name.
In other words, NY computer name would get LTR.potx renamed to blank.potx so paper size for default presentation is 8 1/2 x 11 while LN computer would get A4.potx renamed to blank.potx so paper size would be A4.
But need it to go through ALL profiles as my copy batch copies the multiple firm templates (A4, LTR, WideScreen) to ALL profiles on box.
Suggestions on how to accomplish in batch?

Report •

Related Solutions

#4
May 19, 2014 at 06:19:16
My VBScript uses Select Case to see city name of computer and will then use that information to rename the correct paper size presentation to blank.potx depending on the country/city the computer used in. I have a batch file that uses FOR /f "tokens=*" to copy firms templates to ALL profiles on machine so I would like to more or less get one batch file to do everything. Batch file MUST run with elevated rights since it is copying to ALL profiles as well as to C:\Program Files (x86) folders. Running Windows 7 Enterprise N OS.

VBscript:

Dim WSHShell, bKey, c, ret
Dim nReturnCode
dim city, env, exe, server
Dim objNetwork
Dim fso

Set WSHShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = Wscript.CreateObject("Wscript.Network")
Set env = WSHShell.Environment("PROCESS")
Set WshNetwork = Wscript.CreateObject("Wscript.Network")
Set WshShell = WScript.CreateObject("WScript.Shell")

'Get user login name
User = objnetwork.username

'msgbox User


' *******************************************************
' BE SURE TO RUN SCRIPT AS USER THAT HAS THE FOLLOWING
' ENVIRONMENTAL VARIABLE SET IN THE LOGON SCRIPT
' *******************************************************

city = Left(env("COMPUTERNAME"), 2)

'msgbox city

Select case city
case "NY", "PL", "SF", "TR", "DC", "SP"

server="LTR"

case "AD", "BJ", "BR", "FR", "LN", "MI", "MU", "SI", "SH", "PA", "RO", "TK"

server="A4"

End Select

If server = "LTR" then
objFSO.CopyFile "C:\Users\" & User & "\AppData\Roaming\Microsoft\Templates\LTR.potx", "C:\Users\" & User & "\AppData\Roaming\Microsoft\Templates\Blank.potx"
ElseIf server = "A4" then
objFSO.CopyFile "C:\Users\" & User & "\AppData\Roaming\Microsoft\Templates\A4.potx", "C:\Users\" & User & "\AppData\Roaming\Microsoft\Templates\Blank.potx"
End If


set wshshell = Nothing
set FSO = Nothing

'Quit the Script
wscript.quit(0)


Report •

#5
May 19, 2014 at 06:26:20
Here is the batch file that does the file copies and moves and runs with elevated rights.
If I run the batch with elevated rights and have it call the VBscript, it doesn't do as expected since it will only copy to the account it is being run as and not ALL profiles.

@ECHO OFF
SETLOCAL

:: Setup Environment
SET LOGFILE=c:\Windows\Logs\Firm\OfficeThemesFilesMove.log


ECHO Checking for GenericThemesFiles folder...
ECHO Checking for GenericThemesFiles folder... >> "%LOGFILE%"
IF NOT EXIST "C:\Program Files (x86)\Microsoft Office\Document Themes 14\GenericThemesFiles" (
MD "C:\Program Files (x86)\Microsoft Office\Document Themes 14\GenericThemesFiles" > NUl 2>&1
ECHO Checking for GenericThemesFiles folder - %ERRORLEVEL% >> "%LOGFILE%"
)


MOVE /Y "C:\Program Files (x86)\Microsoft Office\Document Themes 14\*.thmx" "C:\Program Files (x86)\Microsoft Office\Document Themes 14\GenericThemesFiles\"

ECHO Checking for GenericFontsFiles folder...
ECHO Checking for GenericFontsFiles folder... >> "%LOGFILE%"
IF NOT EXIST "C:\Program Files (x86)\Microsoft Office\Document Themes 14\Theme Fonts\GenericFontFiles" (
MD "C:\Program Files (x86)\Microsoft Office\Document Themes 14\Theme Fonts\GenericFontFiles" > NUl 2>&1
ECHO Checking for GenericFongFiles folder - %ERRORLEVEL% >> "%LOGFILE%"
)


MOVE /Y "C:\Program Files (x86)\Microsoft Office\Document Themes 14\Theme Fonts\*.xml" "C:\Program Files (x86)\Microsoft Office\Document Themes 14\Theme Fonts\GenericFontFiles\"

ECHO Checking for GenericColorFiles folder...
ECHO Checking for GenericColorFiles folder... >> "%LOGFILE%"
IF NOT EXIST "C:\Program Files (x86)\Microsoft Office\Document Themes 14\Theme Colors\GenericColorFiles" (
MD "C:\Program Files (x86)\Microsoft Office\Document Themes 14\Theme Colors\GenericColorFiles" > NUl 2>&1
ECHO Checking for GenericColorFiles folder - %ERRORLEVEL% >> "%LOGFILE%"
)


MOVE /Y "C:\Program Files (x86)\Microsoft Office\Document Themes 14\Theme Colors\*.xml" "C:\Program Files (x86)\Microsoft Office\Document Themes 14\Theme Colors\GenericColorFiles\"


ECHO Finished - %DATE% - %TIME% >> "%LOGFILE%"

@ECHO OFF
SETLOCAL

:: Setup Environment
SET LOGFILE=c:\Windows\Logs\Firm\June2014-PowerPointTemplates.log

ECHO Checking for templates folder...
ECHO Checking for templates folder... >> "%LOGFILE%"
IF NOT EXIST "c:\users\default\appdata\Roaming\Microsoft\templates" (
MD "c:\users\default\appdata\Roaming\Microsoft\Templates" > NUl 2>&1
ECHO Checking for templates folder in %%a user profile - %ERRORLEVEL% >> "%LOGFILE%"
)

ECHO Copying Template files to each user profile...
ECHO Copying Template files to each user profile... >> "%LOGFILE%"
FOR /f "tokens=*" %%a in ('dir /ad "c:\Users" /b') DO (
XCOPY "%~DP0*.potx" "c:\users\%%a\appdata\roaming\microsoft\templates\*.*" /y /c /e /r /h /v >> "%LOGFILE%" 2>&1
)


xcopy "%~DP0*color.xml" C:\"Program Files (x86)"\"Microsoft Office"\"Document Themes 14"\"Theme Colors"\*.* /y/c >> c:\Windows\Logs\Firm\June2014-PowerPointTemplates.log

xcopy "%~DP0*Font.xml" C:\"Program Files (x86)"\"Microsoft Office"\"Document Themes 14"\"Theme Fonts"\*.* /y/c >> c:\Windows\Logs\Firm\June2014-PowerPointTemplates.log

xcopy "%~DP0*.thmx" C:\"Program Files (x86)"\"Microsoft Office"\"Document Themes 14"\*.* /y/c >> c:\Windows\Logs\Firm\June2014-PowerPointTemplates.log

ECHO Finished - %DATE% - %TIME% >> "%LOGFILE%"
ENDLOCAL


Report •

#6
May 19, 2014 at 06:56:46
Question: How does this batch run? Manually, part of a startup script, or part of a logon script? I'm assuming manually because GPO startup scripts run elevated by default, and logon scripts wouldn't need to elevate.

SET CN="%ComputerName:~0,2%"

SET server=NUL
ECHO NY,PL,SF,TR,DC,SP | FIND /I %CN% > NUL && SET server=LTR.potx
ECHO AD,BJ,BR,FR,LN,MI,MU,SI,SH,PA,RO,TK | FIND /I %CN% > NUL && SET server=A4.potx

FOR /f "tokens=*" %%a in ('dir /ad "c:\Users" /b') DO (
XCOPY "%~DP0%server%" "c:\users\%%a\appdata\roaming\microsoft\templates\*.*" /y /c /e /r /h /v >> "%LOGFILE%" 2>&1

How To Ask Questions The Smart Way


Report •

#7
May 19, 2014 at 06:59:55
We use Altiris (similar to SCCM) to run the batch file. Altiris has its own built-in admin/system account that runs things in elevated rights.

Report •

#8
May 19, 2014 at 09:36:35
Razor2.3 - you batch copies the LTR to my pc which is NY however what I need to do is rename a copy of that LTR to Blank.potx so when we launch PowerPoint I get the firm lettersize default presentation. Have to have the same behavior for the A4 computers.

Report •

#9
May 19, 2014 at 09:42:18
Okay.
XCOPY "%~DP0%server%" "c:\users\%%a\appdata\roaming\microsoft\templates\Blank.potx" /y /c /e /r /h /v >> "%LOGFILE%" 2>&1

How To Ask Questions The Smart Way


Report •

#10
May 19, 2014 at 09:58:16
I tried that line earlier and figured I had made a mistake.
It appears to hang because the batch files is stuck not knowing whether or not it is a file or directory.

Log states:

Does C:\users\Administrator\appdata\roaming\microsoft\templates\Blank,potx specify a file name
or directory name on the target
(F = file, D = directory)?

I've tried adding a /i switch but no difference.


Report •

#11
May 19, 2014 at 10:28:49
You have "Blank"-comma-"potx".
You need "Blank"-period-"potx"

How To Ask Questions The Smart Way


Report •

#12
May 19, 2014 at 10:29:37
I fixed that after I posted - get same results.

Report •

#13
May 19, 2014 at 10:51:09
Then it's a problem with your switches. Remove them all, except /y. /v can stay, too.

How To Ask Questions The Smart Way


Report •

#14
May 19, 2014 at 11:29:19
Same results. Even with no switches same result. Doesn't know that %server% is a file to be copied to blank.potx.

Report •

#15
May 19, 2014 at 12:18:03
Oh, it knows. XCOPY historically didn't care, so it can't care now. Because doing so would break someone's script somewhere. That's why MS just creates a new scripting language every decade or so instead of improving the old one.

I'd have to see the final rendered line to see what's actually happening. Normally our batch scripts start out:

@IF "%~1"=="" "%~f0" 1 > lastRun.log 2>&1
ECHO ON
That saves all commands and their output to the log. No fuss, no muss.

How To Ask Questions The Smart Way


Report •

#16
May 19, 2014 at 18:53:04
That's been a notorious issue with xcopy that's never been fixed. If I know in advance, I usually just send the answer, inside the bat:
echo D | xcopy ... ... ...
or F, as the case may be.

Report •


Ask Question