Welcome to Scripting Forums Sign in | Join | Help
in Search

update computers from text file

Last post 11-01-2007, 3:27 PM by AbqBill. 5 replies.
Sort Posts: Previous Next
  •  09-27-2007, 8:16 AM 28575

    update computers from text file

    I’m new to scripting and currently the IT admin over a domain controller with several other companies set up in their own OU. In an effort to restate our company’s computer use policy I am trying to update the registry’s “LegalNoticeText” for each PC (85). I found the following script (fig 1) and ran it locally for my PC and it worked fine. I then needed a way to do this over the network on each PC. I first attempted to add this to the GroupPolicy startup/shutdown, but it did not work and I’m not sure why. So I then thought a script would work to update each pc remotely and I found this script fig (2) and inserted the first script into it at the required location. I set up a .txt file with all of our computer names and saved it in the folder as indicated in the script. However when I ran the script it did not use the file at all and it started updating computers that were not in my OU. I quickly stopped it and corrected the computers that were updated. I also realized that I need admin permissions to update the registry.

    Why didn't the script use the file at the location indicated?

    How can I make this work using Administrator Permissions remotely? Thanks in advance

    Thanks in Advance 

    Fig (1)
    Const HKEY_LOCAL_MACHINE = &H80000002
    strComputer = "."
     Set objReg=GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
    strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
    strValueName = "LegalNoticeCaption"
    strValue = "Legal Notice"
    objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
     strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
    strValueName = "LegalNoticeText"
    strValue = "By logging on to this computer you agree to abide by the "
    strValue = strValue & "computer usage rules and regulations of this company."
    strValue = strValue & vbCrLf & vbCrLf
    strValue = strValue & "Permissible Use"
    strValue = strValue & vbCrLf & vbCrLf
    strValue = strValue & "E-Mail –Computer information systems are prohibited from using Electronic mail to pass jokes, chain letters, general advertisement postings, etc. and should discourage receipt of the same from people outside of the company."
    strValue = strValue & vbCrLf & vbCrLf
    strValue = strValue & "Internet Usage – All employees have access to the Internet for business-related activities during business hours.  Non-business usage is allowed, but with no exception during business hours.  Please remember that inappropriate use of the Internet will not be tolerated at any time."
    strValue = strValue & vbCrLf & vbCrLf
    strValue = strValue & "Content – Any inappropriate content sent or received by an employee either through the Internet or electronic mail is prohibited.  Remember that all content is logged on a daily basis."
    strValue = strValue & vbCrLf & vbCrLf
    objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

    fig (2)

    On Error Resume Next
    Const ForReading = 1
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.OpenTextFile("c:\scripts\computers.txt", ForReading)
    Do Until objTextFile.AtEndOfStream
        strComputer = objTextFile.Readline

        ' =====================================================================
        '     Insert script here
        ' =====================================================================

        Set objComputer = GetObject("WinNT://" & strComputer & "")
        objComputer.Filter = Array("User")
        For Each objUser in objComputer
            Wscript.Echo objUser.Name
        Next
        ' =====================================================================
        ' End
        ' =====================================================================
    Loop
    objTextFile.Close

     

  •  10-02-2007, 7:34 PM 28592 in reply to 28575

    Re: update computers from text file

    Hi jlspencer@rmfnooter.com,

    Any reason you're trying to script this, rather than just updating the appropriate GPO?

    Bill
     

  •  10-03-2007, 5:59 PM 28597 in reply to 28575

    Re: update computers from text file

    In order to run this from one machine and access several remote boxes you will need to modify your GetObject call to use SBemLocator.

     You are using the following to connect to the machine:

     Set objComputer = GetObject("WinNT://" & strComputer & "")

     What you should use instead (assuming the script is accessing a remote machine) is:

    strComputer = <computer>
    strUsername = <User Name>
    strPassword = <password>

    Set objWMIService = Nothing
    Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
    Set objWMIService = objSWbemLocator.ConnectServer _
         (strComputer, "root\cimv2", strUsername, strPassword)
    objWMIServices.Security_.ImpersonationLevel = 3

    This will now allow you to alias as the other machine under the credentials you provided.

    Also, when accessing the registry, make sure to use impersonation with GetObject. This should allow for proper registry authentication:

    Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
           strComputer & "\root\default:StdRegProv")

  •  10-11-2007, 6:17 AM 28635 in reply to 28592

    Re: update computers from text file

    Bill,

     

    I am under the corporate GPO and any local GPO on my server is ignored.

  •  10-11-2007, 6:20 AM 28636 in reply to 28597

    Re: update computers from text file

    arztje

    I don't see where this script picks up the computer name from a file. As I have 87 -100 to configure at any given time it would help to  read the Pc names from a file.

     

  •  11-01-2007, 3:27 PM 28760 in reply to 28635

    Re: update computers from text file

    Hi jlspencer,

    You mean that they've selected Enforced (aka No Override) in the GPO console for this setting higher up in the GPO hierarchy?

    Bill

View as RSS news feed in XML
SPONSORED LINKS FEATURED LINKS

Maximize speed, performance and reliablity of your PCs and servers—automatically!Speed Up Your PC! Try Diskeeper 2008 with InvisiTasking Free Now! Microsoft Learning Snack - Green IT Through Virtualization Many organizations face rising operating costs caused by excessive energy consumption. Virtualization and "Green IT" can help cut these costs. Get the information you need to bring Green IT savings to your business. Order Your Fundamentals CD Today!Register today for your in-depth copy of one of three Fundamental CDs on the following topics – Exchange, SQL, and SharePoint. Microsoft Learning Snack - Virtualization With Windows Server 2008Windows Server 2008 includes virtualization technology that allows many operating systems - including open source - to run on a single host. Come learn the basics of implementing these features. Microsoft Learning Snack - Virtualization BasicsWith virtualization, computing components essentially become on-demand services, freeing each element of a system from the others. This short video explains the needs, benefits, and technologies behind virtualization. Microsoft Learning Snack - Virtualization BasicsWith virtualization, computing components essentially become on-demand services, freeing each element of a system from the others. This short video explains the needs, benefits, and technologies behind virtualization. Microsoft Learning Snack - Virtualization With Windows Server 2008Windows Server 2008 includes virtualization technology that allows many operating systems - including open source - to run on a single host. Come learn the basics of implementing these features. Empower Your Processes with PowerShell 201Paul Robichaux delves deep into PowerShell how-tos in 3 informative lessons, each followed by live Q&A—all on your own computer! Register today! Microsoft Learning Snack - Green IT Through VirtualizationMany organizations face rising operating costs caused by excessive energy consumption. Virtualization and "Green IT" can help cut these costs. Get the information you need to bring Green IT savings to your business. New Release: Windows IT Pro Master CD13 years of content archives, fast answers with advanced search tools, and full access to WindowsITPro.com—order today!

 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing