Jump to content

Pull info from a text file and set as variable


Recommended Posts

I've been reading and have found a few threads that mention this, but the text file is where the variables are defined and is standard.  I work in IT for a small company and I am working on a process to run some maintenance scripts on machines each night.  I need to run these as administrator.  The tricky part is that some of the machines use our domain admin and others use a local admin.  There are 3 different options that it could be.  Once I create the text file with the users, search the text file for the known users, if the either both exist or the local admin only exists set it as a variable to use in my runas, otherwise use the domain admin.  I'm very new to scripting and a beginner with AutoIT so please forgive me if I ask questions that may be very obvious.

Link to comment
Share on other sites

You could use an INI file and make it very simple.


[ComputerName1]

AdminAcct=Domain

[ComputerName2]

AdminAcct=Local

.

.

.[ComputerNameN]

AdminAcct=Local

Then you could use IniRead to find the ComputerNameX (section), and from there check if the AdminAcct to use is either Domain or Local depending on how you set it up.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Hi,

Welcome to the autoit forum :)

How are the users stored in your text file? The best would to use the Ini* functions OR if there is only this data in the file then separate them by the same character (line feed for example).

To retreive the users :

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
 
$strComputer = "localhost"
 
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_UserAccount", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
 
For $objItem In $colItems
    ConsoleWrite($objItem.Name & @CrLf)
Next

You can store the users in an array and use the _ArraySearch function to know if a certain user exists.

Br, FireFox.

Link to comment
Share on other sites

Thank you guys very much for the responses.  I've never done anything with INI files, I will start looking into that right now.  Currently I am actually just pushing the output of 'net localgroup administrators' to a text file to get the info to see which is there.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...