![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | Re: VBScript Windows 7 / Windows Vista "Anthony Humphreys" <ahumphreys1980@xxxxxx> wrote in message news:2a03ee6f-ba3a-4003-b0f0-5d6a53943caf@xxxxxx Quote: >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. 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | Re: VBScript Windows 7 / Windows Vista "Anthony Humphreys" <ahumphreys1980@xxxxxx> wrote in message news:dbe16a43-54a4-495c-bb6b-fa98956a7dd0@xxxxxx Quote: > 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 - 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 Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Re: VBscript works normally on Windows XP/Win2003 but not on Win Vista -> "Invalid class" error | VB Script | |||
| Windows VBscript 5.6 | Vista installation & setup | |||
| VBScript to exe with Windows | VB Script | |||
| reference / manage application windows with vbscript | VB Script | |||
| GUI interface - use powershell framework windows or vbscript HTA ? | PowerShell | |||