We help IT Professionals succeed at work.

VBScribt to copy and overwrite .ini files

seaquist1
seaquist1 asked
on
Medium Priority
1,144 Views
Last Modified: 2008-08-05
I am getting ready to make a system change that will require updates to 3 different .ini files on about 400 PC's. Since nobody on my network has local admin rights, the users can't make the changes. I thought a login script would be the best way to do it. Can someone help me out with a VBScript that would take the new .ini files from a share and overwrite the existing .ini files located in C:\%systemroot%?
Comment
Watch Question

If I'm correct, a login script would run as the users rights (still not able to do the change).  You may need to do an Active Directory "Startup" script.  This should then run as the local system.  ini files are just simple text files.  You should be able to just use a easy write.  Let me see what I got.
Try this.  

Dim fso, MyFile
Dim Input
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("c:\testfile.txt", True)
Input = InputBox("Enter text to be written to testfile.txt")
MyFile.WriteLine(input)
MyFile.Close

Should overwrite anything existing I think.
Oh wait, this may be better.  It will actually copy a file over (should be less code!).

Dim FSO, WSH, WSHNetwork

   
   Set FSO = CreateObject("Scripting.FileSystemObject")
   Set WSH = CreateObject("WScript.Shell")
'copy notes data to pc
   FSO.CopyFile "P:\lotus\notes.ini","c:\lotus\notes\notes.ini"
   FSO.CopyFile "P:\lotus\data\names.nsf","c:\lotus\notes\data\names.nsf"

Author

Commented:
The script is trying to work,but I am getting a permissions error. I am using Active Direcory to run andI have it set as a startup script under, I have even tried as a logon script under User settings. Is there a way to have it run with elevated privelages?
Hmmm....not sure about that.  I would have thought that the local system could make that update.  
Found this.  May work but looks rather involved!

http://www.tek-tips.com/faqs.cfm?fid=2760

Author

Commented:
I was able to aswer my own question. Here is the script I used. Please leave this posted for future reference.


Option Explicit

Dim objFSO, objFileCopy, objFileDelete
Dim strFilePath1, strDestination1, strFilePath2, strDestination2


strFilePath1 = "\\Domain Controller\sysvol\domainname.local\scripts\saplogon.ini"
strFilePath2 = "\\Domain Controller\sysvol\domainname.local\scripts\services"
strDestination1 ="C:\WINDOWS\saplogon.ini"
strDestination2 ="C:\WINDOWS\system32\drivers\etc\services"

Set objFSO = CreateObject("Scripting.FileSystemObject")

'******************************************************************
'*         This section deletes the existing saplogon.ini         *
'*               and then copies the new one down                 *
'******************************************************************

' Deleting
Set objFileCopy = objFSO.GetFile(strDestination1)
objFileCopy.Delete ()

'Getting the file
Set objFileCopy = objFSO.GetFile(strFilePath1)

' Copying
objFileCopy.Copy (strDestination1)

'******************************************************************
'*         This section deletes the existing services file        *
'*               and then copies the new one down                 *
'******************************************************************

'Deleting
Set objFileCopy = objFSO.GetFile(strDestination2)
objFileCopy.Delete ()

'Getting the FIle
Set objFileCopy = objFSO.GetFile(strFilePath2)

' Copying
objFileCopy.Copy (strDestination2)
' End of example Script

Author

Commented:
PAQ it. I posted this request when I answered my own question (right above the admin comment). Sorry I did this in the wrong spot.


I was able to aswer my own question. Here is the script I used. Please leave this posted for future reference.


Option Explicit

Dim objFSO, objFileCopy, objFileDelete
Dim strFilePath1, strDestination1, strFilePath2, strDestination2


strFilePath1 = "\\Domain Controller\sysvol\domainname.local\scripts\saplogon.ini"
strFilePath2 = "\\Domain Controller\sysvol\domainname.local\scripts\services"
strDestination1 ="C:\WINDOWS\saplogon.ini"
strDestination2 ="C:\WINDOWS\system32\drivers\etc\services"

Set objFSO = CreateObject("Scripting.FileSystemObject")

'******************************************************************
'*         This section deletes the existing saplogon.ini         *
'*               and then copies the new one down                 *
'******************************************************************

' Deleting
Set objFileCopy = objFSO.GetFile(strDestination1)
objFileCopy.Delete ()

'Getting the file
Set objFileCopy = objFSO.GetFile(strFilePath1)

' Copying
objFileCopy.Copy (strDestination1)

'******************************************************************
'*         This section deletes the existing services file        *
'*               and then copies the new one down                 *
'******************************************************************

'Deleting
Set objFileCopy = objFSO.GetFile(strDestination2)
objFileCopy.Delete ()

'Getting the FIle
Set objFileCopy = objFSO.GetFile(strFilePath2)

' Copying
objFileCopy.Copy (strDestination2)
' End of example Script
Sorry my suggestions couldn't be of any help to you.  Glad you fixed it.
Commented:
PAQed with points refunded (500)

GranMod
Community Support Moderator

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Oke i had everything done ok, but i think it was not possible to get a file from a normal share (is this true?), it is only possible from the sysvol share of AD where the scripts are posted \Domain name\\sysvol\domainname.local\scripts\

Thanx for the nice script,
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.