• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1131
  • Last Modified:

VBScribt to copy and overwrite .ini files

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%?
0
seaquist1
Asked:
seaquist1
1 Solution
 
NARobertsCommented:
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.
0
 
NARobertsCommented:
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.
0
 
NARobertsCommented:
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"
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
seaquist1Author 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?
0
 
NARobertsCommented:
Hmmm....not sure about that.  I would have thought that the local system could make that update.  
0
 
NARobertsCommented:
Found this.  May work but looks rather involved!

http://www.tek-tips.com/faqs.cfm?fid=2760
0
 
seaquist1Author 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
0
 
seaquist1Author 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
0
 
NARobertsCommented:
Sorry my suggestions couldn't be of any help to you.  Glad you fixed it.
0
 
GranModCommented:
PAQed with points refunded (500)

GranMod
Community Support Moderator
0
 
maximal81Commented:
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,
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now