Replacing 2 files using a script.
Hi there,
I've searched this amazing forum for the script i need, but finally i decdided to ask my question here, and hope for a little help.
Wer'e using SAP in our organisation, and i need to distribute 2 files which will Replace old files of sap in our systems.
The users don't need event to know that this script is running, and this script should override the 2 files WITHOUT asking the user permission.
I don't mind if it'll be batch file, or vb script...
Hope to here from you soon,
Best regards,
Nahum.
October 30th, 2010 4:12am
Hi Nahum,
This script will copy (and overwrite) the specified file. You can use the script and modify it to your needs.
Dim objFSO,ObjNet
Dim strUsername,strDestfile, strScriptLocation
strFileName = "blank.potx"
strScriptLocation = Replace(WScript.ScriptFullName,WScript.ScriptName,"")
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strAppData = objShell.ExpandEnvironmentStrings("%AppDATA%")
strDestFolder = strAppData & "\Microsoft\Skabeloner"
If Not objFSO.FolderExists(strDestFolder) Then
objFSO.CreateFolder strDestFolder
End If
objFSO.Copyfile strScriptLocation & strFileName,strDestFolder&"\",True
Kent Agerlund | http://scug.dk/ | The Danish community for System Center products
Free Windows Admin Tool Kit Click here and download it now
October 30th, 2010 8:08am
Hi kent,
First of all, thank you very much for your answer.
I still don't know where the originated files will be, i'm guessing that the source will be in a specific server, and the destination files which will be, replaced will probably will be located in: c:\program files\sap\ (the
files we need to replace are for the sap business one application).
The script needs to overwrite two files, not one...sorry for didn't mentioning it earlier.
Where do i modify and type the path of the original files, i thought about something like that....correct me if i'm wrong.
strAppData = objShell.ExpandEnvironmentStrings("\\servername\sharename\123new.dll")
strAppData = objShell.ExpandEnvironmentStrings(\\servername\sharename\456new.dll)
strDestFolder = strAppData & "c:\program files\sap" (i'm assuming that the Destfolder is something that i wrote ok, right?)
Once again, i hope i'm correct with what i wrote, i'll be happy if you'll help me out here.
Best regards,
Nahum.
October 30th, 2010 2:30pm
Hi,
I hope I understood your question right. Why not just use xcopy with /Y switch.
For example to copy fileA.dll and fileB.dll in a package to C:\Program files\SAP and replace any existing ones without prompting, run following batch file in a package:
xcopy "%~dp0fileA.dll" "%programfiles%\SAP\" /Y
xcopy "%~dp0fileB.dll" "%programfiles%\SAP\" /Y
You could do this with one line as well by using wildcards if file names have similar pattern. For example, if there are two files in a package and they both have DLL extension, use this:
xcopy "%~dp0*.dll" "%programfiles%\SAP\" /Y
Free Windows Admin Tool Kit Click here and download it now
October 30th, 2010 8:13pm
Since ,you posted this in SCCM Forum, may you can refer this thread from
windows-noob how you can do it with SCCM TS.
This will show you how you can copy the files to destination computers instead you can edit it and use it for copy and overwrite the files :)
//Eswar Koneti @ http://eskonr.wordpress.com/
October 31st, 2010 6:17am