MSFN Forum: Copy file to all users - MSFN Forum

Jump to content


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Copy file to all users Rate Topic: -----

#1 User is offline   MitsuMan 

  • Member
  • PipPip
  • Group: Members
  • Posts: 146
  • Joined: 12-March 06

Posted 30 December 2012 - 09:31 AM

Hello

i would like to know hot it is possbile to copy a file to all users in windows 7

I have found one on the net but it dont work

Quote

'==========================================================================
' 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 HERE

Dim fso
Dim oFolder1, objFolder, oFolder
Dim path
Dim WSHShell
Dim colFolders
Dim sDocsAndSettings
Dim strComputer

strComputer = "."

Set WSHShell = CreateObject("WScript.Shell")
Set fso = createobject("Scripting.FileSystemObject")

'SPECIFY THE PATH OF THE FOLDER IN WHICH SOURCE FILES RESIDE
Set oFolder1 = fso.GetFolder("c:\MyFolder")

'COPY FILES TO USER PROFILES
sDocsAndSettings = "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
Next

Set fso = Nothing
Set WSHShell = Nothing



#2 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,363
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 30 December 2012 - 10:24 AM

COPY MyFile.ext %PUBLIC%


#3 User is offline   MitsuMan 

  • Member
  • PipPip
  • Group: Members
  • Posts: 146
  • Joined: 12-March 06

Posted 30 December 2012 - 11:42 AM

View PostYzöwl, on 30 December 2012 - 10:24 AM, said:

COPY MyFile.ext %PUBLIC%



So you mean if i do this it should work

COPY MyFile.ext C:\Users\%PUBLIC%\AppData\Roaming\IDMComp\UltraEdit

So then it will copy to 3 diffrent user.

C:\Users\Test 1\AppData\Roaming\IDMComp\UltraEdit
C:\Users\Test 2\AppData\Roaming\IDMComp\UltraEdit
C:\Users\Test3\AppData\Roaming\IDMComp\UltraEdit

#4 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,363
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 30 December 2012 - 12:20 PM

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 LocalPath
ForEach ($Profile in $UserProfiles) {
	Copy-Item $PathToMyFile -Destination "$Profile\AppData\Roaming\IDMComp\UltraEdit"
}


#5 User is offline   MitsuMan 

  • Member
  • PipPip
  • Group: Members
  • Posts: 146
  • Joined: 12-March 06

Posted 30 December 2012 - 01:29 PM

View PostYzöwl, on 30 December 2012 - 12:20 PM, said:

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 LocalPath
ForEach ($Profile in $UserProfiles) {
	Copy-Item $PathToMyFile -Destination "$Profile\AppData\Roaming\IDMComp\UltraEdit"
}




Hello

I have try to make it now but it dont work or copy anything.i try to attach the script to here
but i am not allow to attach these type of files even with winrar

Quote

PS C:\test> test.ps1
The 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 in
cluded, verify that the path is correct and try again.
At line:1 char:9
+ test.ps1 <<<<
+ CategoryInfo : ObjectNotFound: (test.ps1:String) [], CommandNot
FoundException
+ FullyQualifiedErrorId : CommandNotFoundException


Suggestion [3,General]: The command test.ps1 was not found, but does exist in th
e current location. Windows PowerShell doesn't load commands from the current lo
cation by default. If you trust this command, instead type ".\test.ps1". See "ge
t-help about_Command_Precedence" for more details.
PS C:\test>



Thank you very much for helping.

This post has been edited by MitsuMan: 30 December 2012 - 01:34 PM


#6 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,363
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 30 December 2012 - 02:05 PM

Quote

C:\test> .\test.ps1


#7 User is offline   MitsuMan 

  • Member
  • PipPip
  • Group: Members
  • Posts: 146
  • Joined: 12-March 06

Posted 30 December 2012 - 02:50 PM

View PostYzöwl, on 30 December 2012 - 02:05 PM, said:

Quote

C:\test> .\test.ps1




Then i get this

Quote

$PathToMyFile = "Uedit32.ini"
$UserProfiles = GWmi Win32_UserProfile -filter "LocalPath Like '%\\Users\\%'" | Select-Object -ExpandProperty LocalPath
ForEach ($Profile in $UserProfiles) {
Copy-Item $PathToMyFile -Destination "$Profile\AppData\Roaming\IDMComp\UltraEdit\"
}


#8 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,363
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 30 December 2012 - 03:41 PM

  • Open Powershell as Administrator
  • Type/Enter Set-ExecutionPolicy Unrestricted
  • Try again!

<Edit>You may find that an ExecutionPolicy of RemoteSigned is better for you.<Edit>

This post has been edited by Yzöwl: 30 December 2012 - 04:23 PM
Reason for edit: See <Edit />


#9 User is offline   MitsuMan 

  • Member
  • PipPip
  • Group: Members
  • Posts: 146
  • Joined: 12-March 06

Posted 31 December 2012 - 05:35 AM

Hello

the script seems to work now

Can you make so in the script it auto makes this also

Open Powershell as Administrator
Type/Enter Set-ExecutionPolicy Unrestricted

so 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.

#10 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,363
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 31 December 2012 - 06:49 AM

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?

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy