Windows Vista Forums

VBScript Windows 7 / Windows Vista
  1. #1


    Anthony Humphreys Guest

    VBScript Windows 7 / Windows Vista

    I am trying to write a script that will copy files to the Windows
    Directory (Company Background Images)
    This is to be deployed and run via group policy as a machine (Startup)
    Script.



    However, I believe this is the reason, the files / folders are not
    being created as required because Vista / Windows 7 protects the C:
    \Windows Directory (and Program Files Directory as well)

    Has anyone here have a work around for this?
    THe script works fine if I run it as Administrator after I have logged
    in.
    The Script is copying files from the SBS Server via full FQDN UNC
    Path.

    Any help in narrowing this down would be greatly appreciated.

      My System SpecsSystem Spec

  2. #2


    Pegasus [MVP] Guest

    Re: VBScript Windows 7 / Windows Vista


    "Anthony Humphreys" <ahumphreys1980@xxxxxx> wrote in message
    news:2a03ee6f-ba3a-4003-b0f0-5d6a53943caf@xxxxxx

    >I am trying to write a script that will copy files to the Windows
    > Directory (Company Background Images)
    > This is to be deployed and run via group policy as a machine (Startup)
    > Script.
    >
    > However, I believe this is the reason, the files / folders are not
    > being created as required because Vista / Windows 7 protects the C:
    > \Windows Directory (and Program Files Directory as well)
    >
    > Has anyone here have a work around for this?
    > THe script works fine if I run it as Administrator after I have logged
    > in.
    > The Script is copying files from the SBS Server via full FQDN UNC
    > Path.
    >
    > Any help in narrowing this down would be greatly appreciated.
    If your script works fine while you're logged on as Administrator then
    you're dealing with a permissions issue, not a scripting issue. Your first
    step should be to capture the error messages, either from within your script
    (which you did not post) or by including a humble "copy" command in your
    group policy startup batch file like so:

    xcopy /s /d /c "%SystemRoot%\Some Folder\*.jpg"
    \\SomeServer\SomeShare\SomeFolder\ 1>>c:\test.txt 2>>&1

    Once you know what the security issue is you can repost your question in an
    SBS newsgroup. Remember that no amount of scripting will get you around
    security issues.



      My System SpecsSystem Spec

  3. #3


    Anthony Humphreys Guest

    Re: VBScript Windows 7 / Windows Vista

    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

      My System SpecsSystem Spec

  4. #4


    Pegasus [MVP] Guest

    Re: VBScript Windows 7 / Windows Vista


    "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"



      My System SpecsSystem Spec

VBScript Windows 7 / Windows Vista problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
are VBscript on Windows server 2003 and VBscript on WS2008 compatible? Francois Lafont VB Script 9 26 Apr 2010
Re: VBscript works normally on Windows XP/Win2003 but not on Win Vista -> "Invalid class" error Richard Mueller [MVP] VB Script 2 25 Sep 2009
Windows VBscript 5.6 DC Vista installation & setup 8 16 Jun 2009
VBScript to exe with Windows Méta-MCI \(MVP\) VB Script 6 02 Nov 2008
reference / manage application windows with vbscript Firewalker82 VB Script 1 08 Jul 2008