Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

Copy file to all users

- - - - -

  • Please log in to reply
9 replies to this topic

#1
MitsuMan

MitsuMan

    Member

  • Member
  • PipPip
  • 135 posts
  • Joined 12-March 06
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

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




How to remove advertisement from MSFN

#2
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,078 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

COPY MyFile.ext %PUBLIC%


#3
MitsuMan

MitsuMan

    Member

  • Member
  • PipPip
  • 135 posts
  • Joined 12-March 06

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
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,078 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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
MitsuMan

MitsuMan

    Member

  • Member
  • PipPip
  • 135 posts
  • Joined 12-March 06

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

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.

Edited by MitsuMan, 30 December 2012 - 01:34 PM.


#6
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,078 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

C:\test> .\test.ps1



#7
MitsuMan

MitsuMan

    Member

  • Member
  • PipPip
  • 135 posts
  • Joined 12-March 06

C:\test> .\test.ps1



Then i get this

$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
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,078 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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

Edited by Yzöwl, 30 December 2012 - 04:23 PM.
See <Edit />


#9
MitsuMan

MitsuMan

    Member

  • Member
  • PipPip
  • 135 posts
  • Joined 12-March 06
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
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,078 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users