"Anthony Humphreys" <ahumphreys1980@xxxxxx> wrote in message
news:dbe16a43-54a4-495c-bb6b-fa98956a7dd0@xxxxxx
> Dim objFSO
> Dim objShell
> Dim objSourceFolder
> Dim intSourceFileCount
> Dim intFileCount
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objShell = CreateObject("WScript.Shell")
>
> objITXLogoDirectory = objShell.ExpandEnvironmentStrings("%WinDir%") &
> "\system32\oobe\info\backgrounds"
> objITXLogoSource = objShell.ExpandEnvironmentStrings("%LogonServer%")
> & "\sysvol\<domain name>\scripts\ITX_Backgrounds"
>
> '<domain name> is an actual value, has been replaced with a variable.
>
> Set objSourceFolder = objFSO.GetFolder(objITXLogoSource)
>
> For Each objFile In objSourceFolder.Files
> intSourceFileCount = intSourceFileCount + 1
> Next
>
> With objFSO
> If .FolderExists(objITXLogoDirectory) = True Then
> 'Folder Exists - Let's check if the files Exist
> Set objDestinationFolder = objFSO.GetFolder(objITXLogoDirectory)
> For Each objFile In objDestinationFolder.Files
> intFileCount = intFileCount + 1
> Next
> If intFileCount <> intSourceFileCount Then
> 'Remove the Files from the Directory
> For Each objFile In objDestinationFolder.Files
> objFile.Delete
> Next
>
> 'Replace the Files in the directory
> For Each objFile In objSourceFolder.Files
> WScript.Echo objFile & " to " & objITXLogoDirectory & "\" &
> objFile.Name
> objFSO.CopyFile objFile, objITXLogoDirectory & "\" & objFile.Name
> Next
> End IF
> Else
> 'Folder doesn't exist, So Create Folder, then Copy Images
> 'Need to check each level of the directory Structure
> If .FolderExists(objShell.ExpandEnvironmentStrings("%Windir%") &
> "\system32\oobe") = False Then objFSO.CreateFolder
> (objShell.ExpandEnvironmentStrings("%Windir%") & "\system32\oobe\")
> If .FolderExists(objShell.ExpandEnvironmentStrings("%Windir%") &
> "\system32\oobe\info") = False Then objFSO.CreateFolder
> (objShell.ExpandEnvironmentStrings("%Windir%") & "\system32\oobe\info
> \")
> If .FolderExists(objShell.ExpandEnvironmentStrings("%Windir%") &
> "\system32\oobe\info\backgrounds") = False Then objFSO.CreateFolder
> (objShell.ExpandEnvironmentStrings("%Windir%") & "\system32\oobe\info
> \backgrounds\")
> Set objSourceFolder = objFSO.GetFolder(objITXLogoSource)
> For Each objFile In objSourceFolder.Files
> Wscript.echo objFile
> objFSO.CopyFile objITXLogoSource & "\" & objFile,
> objITXLogoDirectory & "\" & objFile.Name
> Next
> End If
> End With
>
> With objShell
> .RegWrite "HKLM\Software\Microsoft\Windows\CurrentVersion
> \Authentication\LogonUI\Background", 1, "REG_DWORD"
> End With
>
> 'Set the correct Registry Value if it hasn't been set by the Login
> Script yet
> 'HKLM\Software\Microsoft\Windows\CurrentVersion\Authentication\LogonUI
> \Background Here are a few points about your issue:
- If there is a possibility of your script encountering a problem then you
must include code to trap the problem, e.g. like so:
On Error Resume Next
Err.Clear
oFSO.CopyFile oFile, "e:\system volume information\test.txt"
if err.number > 0 then WScript.Echo Err.Description
On Error Goto 0
- It looks like you have a spelling problem in your code. The line
%Windir%\system32\oobe\info \
should probably read
%Windir%\system32\oobe\info\
(extra space after "info")
- You can increase the readability of your VB Script a lot by indenting your
code so that its structures are clearly visible.
- What you're trying to do is really very simple: Copy some files from here
to there if the file counts of two folders do not agree. This task can be
performed with a few lines of batch file code because batch files are made
precisely for this purpose. In VB Script this gets very chatty. The batch
file below (untested) performs the same task as your VB Script file, with
error testing included, yet is less than a third of the size of the VB
Script and a lot more readable. As an example: To copy all files from one
folder to another you need to write this in VB Script:
Set objSourceFolder = objFSO.GetFolder(objITXLogoSource)
For Each objFile In objSourceFolder.Files
objFSO.CopyFile objITXLogoSource & "\" & objFile, objITXLogoDirectory & "\"
& objFile.Name
Next
In a batch file this code becomes:
xcopy /y "ITXLogoSource\*.*" "ITXLogoDirectory"
[01] @echo off
[02] set objITXLogoDirectory=%WinDir%\system32\oobe\info\backgrounds
[03] set
objITXLogoSource=%LogonServer%\sysvol\MyDomain\scripts\ITX_Backgrounds
[04] set IntFileCount=0
[05] for %%a in ('dir /a-d "%ObjITXLogoSource%" ^| find /c ":"') do set
SourceFileCount=%%a
[06] if exist %objITXLogoDirectory% for %%a in ('dir /a-d
"%objITXLogoDirectory%" ^| find /c ":"') do set IntFileCount=%%a
[07] if not %SourceFileCount% EQU %IntFileCount% (
[08] del /q "%objITXLogoDirectory%\*.*"
[09] ) else (
[10] If not exist %Windir%\system32\oobe\info\backgrounds md
%Windir%\system32\oobe\info\backgrounds
[11] )
[12] xcopy /d /c "%objITXLogoSource%" "%objITXLogoDirectory%" 1>>c:\test.txt
2>>&1
[13] echo > "%Temp%\temp.reg" REGEDIT4
[14] echo >>"%Temp%\temp.reg"
[HKey_Local_Machine\Software\Microsoft\Windows\CurrentVersion\Authentication\LogonUI]
[15] echo >>"%Temp%\temp.reg" "Background"=dword:1
[16] regedit /s "%Temp%\temp.reg"