Sign in to follow this  
Followers 0
munsen70

Pull info from a text file and set as variable

5 posts in this topic

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.

Share this post


Link to post
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

Share this post


Link to post
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.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

I should mention that some of the machines have both local and domain.  Unfortunately I am not allowed to change that at this time as I am the low man on the totem pole so to speak.

Share this post


Link to post
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
Sign in to follow this  
Followers 0