MitsuMan Posted December 30, 2012 Posted December 30, 2012 Helloi would like to know hot it is possbile to copy a file to all users in windows 7I have found one on the net but it dont work '==========================================================================' AUTHOR: Eshwar' DATE : 12/12/2008' COMMENT: This script will copy source files/folders to each user profile on the machine '=========================================================================='On Error Resume Next'DECLARE VARIABLES HEREDim fso Dim oFolder1, objFolder, oFolderDim pathDim WSHShellDim colFoldersDim sDocsAndSettings Dim strComputerstrComputer = "."Set WSHShell = CreateObject("WScript.Shell")Set fso = createobject("Scripting.FileSystemObject")'SPECIFY THE PATH OF THE FOLDER IN WHICH SOURCE FILES RESIDESet oFolder1 = fso.GetFolder("c:\MyFolder")'COPY FILES TO USER PROFILESsDocsAndSettings = "C:\Users\" Set colFolders = fso.GetFolder(sDocsAndSettings) For Each oFolder In colFolders.SubFolders Select Case LCase(oFolder.Name) Case "admin", "administrator", "newuser", "all users", "default user.original", "localservice", "networkservice" 'LEAVE THE DEFAULT PROFILES ON THE MACHINE Case Else ' Check for the path If fso.FolderExists(sDocsAndSettings & oFolder.Name & "\AppData") Then 'COPY FOLDER TO USER PROFILE fso.CopyFolder oFolder1, sDocsAndSettings & oFolder.Name & "\AppData\Roaming\IDMComp\UltraEdit" ,True End If End Select NextSet fso = NothingSet WSHShell = Nothing
MitsuMan Posted December 30, 2012 Author Posted December 30, 2012 COPY MyFile.ext %PUBLIC%So you mean if i do this it should workCOPY MyFile.ext C:\Users\%PUBLIC%\AppData\Roaming\IDMComp\UltraEditSo then it will copy to 3 diffrent user.C:\Users\Test 1\AppData\Roaming\IDMComp\UltraEditC:\Users\Test 2\AppData\Roaming\IDMComp\UltraEditC:\Users\Test3\AppData\Roaming\IDMComp\UltraEdit
Yzöwl Posted December 30, 2012 Posted December 30, 2012 I don't think that the response I provided is suitable for the example you've now provided.The following untested powershell script may work for you.$PathToMyFile = "MyFile.ext"$UserProfiles = GWmi Win32_UserProfile -filter "LocalPath Like '%\\Users\\%'" | Select-Object -ExpandProperty LocalPathForEach ($Profile in $UserProfiles) { Copy-Item $PathToMyFile -Destination "$Profile\AppData\Roaming\IDMComp\UltraEdit"}
MitsuMan Posted December 30, 2012 Author Posted December 30, 2012 (edited) I don't think that the response I provided is suitable for the example you've now provided.The following untested powershell script may work for you.$PathToMyFile = "MyFile.ext"$UserProfiles = GWmi Win32_UserProfile -filter "LocalPath Like '%\\Users\\%'" | Select-Object -ExpandProperty LocalPathForEach ($Profile in $UserProfiles) { Copy-Item $PathToMyFile -Destination "$Profile\AppData\Roaming\IDMComp\UltraEdit"}HelloI have try to make it now but it dont work or copy anything.i try to attach the script to herebut i am not allow to attach these type of files even with winrarPS C:\test> test.ps1The term 'test.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.At line:1 char:9+ test.ps1 <<<< + CategoryInfo : ObjectNotFound: (test.ps1:String) [], CommandNot FoundException + FullyQualifiedErrorId : CommandNotFoundExceptionSuggestion [3,General]: The command test.ps1 was not found, but does exist in the current location. Windows PowerShell doesn't load commands from the current location by default. If you trust this command, instead type ".\test.ps1". See "get-help about_Command_Precedence" for more details.PS C:\test>Thank you very much for helping. Edited December 30, 2012 by MitsuMan
MitsuMan Posted December 30, 2012 Author Posted December 30, 2012 C:\test> .\test.ps1Then i get this$PathToMyFile = "Uedit32.ini"$UserProfiles = GWmi Win32_UserProfile -filter "LocalPath Like '%\\Users\\%'" | Select-Object -ExpandProperty LocalPathForEach ($Profile in $UserProfiles) { Copy-Item $PathToMyFile -Destination "$Profile\AppData\Roaming\IDMComp\UltraEdit\"}
Yzöwl Posted December 30, 2012 Posted December 30, 2012 (edited) Open Powershell as AdministratorType/Enter Set-ExecutionPolicy UnrestrictedTry again!<Edit>You may find that an ExecutionPolicy of RemoteSigned is better for you.<Edit> Edited December 30, 2012 by Yzöwl See <Edit />
MitsuMan Posted December 31, 2012 Author Posted December 31, 2012 Hellothe script seems to work nowCan you make so in the script it auto makes this alsoOpen Powershell as AdministratorType/Enter Set-ExecutionPolicy Unrestrictedso i dont need to do it. i would like to try the script with wpi and see if it works there but the script dont work before i have set the policy.
Yzöwl Posted December 31, 2012 Posted December 31, 2012 The setting of the execution policy is a one time only deal in normal use.You have decided however to now incorporarte this script as part of a WPI install; That is not something which necessitates the editing of my script.WPI can utilise the running of powershell scripts, you can set the execution policy to unrestricted prior to running this script. Search the WPI Forum for more information on how to do this.Are you sure that you are using WPI to install on an already running system with several users already configured with the application data directories you're intending to add to?
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now