EddardStark Posted March 6, 2009 Posted March 6, 2009 Hi, I'm working on writing a login script for my company, so we can run multiple login scripts. Basically this script will go out to a text file in the domain controller's netlogon directory, and then read line by line what the next script it has to run is. I tried doing this in AutoIt V2 since that is what I am most familiar with, but I've always had some trouble with getting networking syntax correct. I could get it to read the file, but it wasn't executing the path specified in the file correctly. Since I can't get syntax help with that version, I figured I'd move on to V3. I can't even get it to read the file though. It fails on the fileopen command. Any help is appreciated Here is what I have (the msgbox commands will be taken out later. they are just there, so I know where the script failed): ; Initialize installation ; Opens the file needed to check login scripts $LoginScripts = FileOpen ( "%logonserver%\netlogon\LoginScripts.txt", 0 ) ;Checks to see if file openned alright for reading If $LoginScripts = -1 Then MsgBox (0, "Error", "Unable to open file." ) Exit EndIf ;Reads the lines from the file $Script1 = FileReadLine ( $LoginScripts, 1 ) ;If this fails, then the script will back out If @error = -1 Then MsgBox (0, "Error", "Unable to Read File" ) Exit EndIf ;If the line read has the end of file marker (NoMoreScripts), then it will close If $Scripts1 = NoMoreScripts Then MsgBox (0, "Error", "Reached End of the Script Text File" ) Exit EndIf ;Now onto running the scripts that it reads RunWait ( "%logonserver%\netlogon\$Script1" ) Exit ----- A quick note about the RunWait command. It reads the variable like say "Test1.exe" from the text file. It then tries to run it by using that variable. (eg "%logonserver%\netlogon\$script1" should actually run "\\<my domain controller>\netlogon\test1.exe")
TerarinK Posted March 6, 2009 Posted March 6, 2009 Where do you got %logonserver% specificied, aren't you suppose to be using @LogonDomain or @LogonServer 0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E
KaFu Posted March 6, 2009 Posted March 6, 2009 (edited) $LoginScripts = FileOpen(@LogonServer & "\netlogon\LoginScripts.txt", 0 ) ... RunWait(@LogonServer & "\netlogon\" & $Script1) might work... Edited March 6, 2009 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
EddardStark Posted March 6, 2009 Author Posted March 6, 2009 TerarinK said: Where do you got %logonserver% specificied, aren't you suppose to be using @LogonDomain or @LogonServerIt's a system variable like %systempath% and so on. It's the same on every windows box. Version 2 had no problems using ingrained system variables like this.
EddardStark Posted March 6, 2009 Author Posted March 6, 2009 (edited) KaFu said: $LoginScripts = FileOpen(@LogonServer & "\netlogon\LoginScripts.txt", 0 ) ... RunWait(@LogonServer & "\netlogon\" & $Script1) might work... Cool, KaFu. I'll give it a whirl and try variations on that theme. Thanks. Edited March 6, 2009 by EddardStark
AdmiralAlkex Posted March 6, 2009 Posted March 6, 2009 To use environment variables like that you need Opt("ExpandVarStrings", 1) .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
EddardStark Posted March 6, 2009 Author Posted March 6, 2009 AdmiralAlkex said: To use environment variables like that you need Opt("ExpandVarStrings", 1) Thanks. The correct command is Opt("ExpandEnvStrings", 1) But your reply led me to it. Well it can open the file now it seems, but now it is erroring out on that check here: If $Script1 = NoMoreScripts Then MsgBox (0, "Error", "Reached End of the Script Text File" ) Exit EndIf It throws up a windows error: If $Script1 = NoMoreScripts Then If $Script1= ^ ERROR Error: Error parsing function call
EddardStark Posted March 6, 2009 Author Posted March 6, 2009 Sorry. I should probably explain that command in there. I want to use the RunWait command so these scripts don't run on top of each other. The problem with that is that I'm not always going to control that text file it is reading from, so somebody may end up putting a blank line at the end of that file. With the way it is now, it would try to "Runwait, %logonserver%\netlogon\" because of that blank line. I was worried it would just hang the script at the runwait command if that happenned. I wanted the last line of the text file to have the text "NoMoreScripts" there, so if the filelineread saw that there, then it would bail out. Is that possible? Is there a better way to do it? Thank you!
AdmiralAlkex Posted March 6, 2009 Posted March 6, 2009 Quote Thanks. The correct command is Opt("ExpandEnvStrings", 1) But your reply led me to it. Well it can open the file now it seems, but now it is erroring out on that check here:Oops, I copied the wrong line, lol. Good you found the right one Quote If $Script1 = NoMoreScripts Then MsgBox (0, "Error", "Reached End of the Script Text File" ) Exit EndIf It throws up a windows error: If $Script1 = NoMoreScripts Then If $Script1= ^ ERROR Error: Error parsing function call If NoMoreScripts is supposed to be a string it should be "NoMoreScripts" (notice the bold part, that makes it a string). You can read about this in the helpfile if you go to AutoIt>Language Reference>Datatypes .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
EddardStark Posted March 6, 2009 Author Posted March 6, 2009 Yup. It is supposed to be a string, and sure enough the quotes fixed that part. However when I ran the script, it wouldn't run the script from the text file. I then tried a variation of KaFu's earlier suggestion, and now it's working like a charm. I guess now that it's working, I'm going to see if there is a way to make it loop, so that it continues to run through lines of that text file until it gets to the "NoMoreScripts" line. If you have any suggestions, I'm all ears. The current code looks like: ; Initialize installation ;Allow the use of environmental variables Opt("ExpandEnvStrings", 1) ; Opens the file needed to check login scripts $LoginScripts = FileOpen ( "%logonserver%\netlogon\LoginScripts.txt", 0 ) ;Checks to see if file openned alright for reading If $LoginScripts = -1 Then MsgBox (0, "Error", "Unable to open file." ) Exit EndIf ;Reads the lines from the file $Script1 = FileReadLine ( $LoginScripts, 1 ) ;If this fails, then the script will back out If @error = -1 Then MsgBox (0, "Error", "Unable to Read File" ) Exit EndIf ;If the line read has the end of file marker (NoMoreScripts), then it will close If $Script1 = "NoMoreScripts" Then MsgBox (0, "Error", "Reached End of the Script Text File" ) Exit EndIf ;Now onto running the scripts that it reads RunWait ( "%logonserver%\netlogon\" & $Script1 ) Exit
JSThePatriot Posted March 6, 2009 Posted March 6, 2009 I would recommend the following...#include <file.au3> For $i = 0 To _FileCountLines("%logonserver%\netlogon\LoginScripts.txt") - 1 Step 1 ; Do your stuff here. NextoÝ÷ Ø è¶«ëa¡Ü(ºW[y«¢+Ù¼(ì¼å½ÕÈÍÑաɸ)U¹Ñ¥°¥±I1¥¹ ÀÌØí¥±¤ôôÅÕ½Ðí9½5½ÉMÉ¥ÁÑÌÅÕ½ÐìoÝ÷ ØéÞ«-ëa¡Ü(ºW[y«¢+Ù]¡¥±¥±I1¥¹ ÀÌØí¥±¤±ÐìÐìÅÕ½Ðí9½5½ÉMÉ¥ÁÑÌÅÕ½Ðì(ì¼å½ÕÈÍÑաɸ)]¹ I hope this helps some, Jarvis AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)
EddardStark Posted March 6, 2009 Author Posted March 6, 2009 Wow. This is a great forum. I'll check those out.
JSThePatriot Posted March 6, 2009 Posted March 6, 2009 You could also use _FileReadToArray() look it up in the helpfile. It may be quite useful for you. Thanks, Jarvis AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)
EddardStark Posted March 9, 2009 Author Posted March 9, 2009 Thanks again, all. I got this working like a charm earlier today. I figured I'd post the final code here. I removed the message boxes since troubleshooting was complete: ; Initialize installation ;Allow the use of environmental variables Opt("ExpandEnvStrings", 1) ;Opens the file needed to check login scripts $LoginScripts = FileOpen ( "%logonserver%\netlogon\LoginScripts.txt", 0 ) ;Checks to see if file openned alright for reading If $LoginScripts = -1 Then Exit EndIf ;Begins loop and reads the lines from the file Do $Script = FileReadLine ( $LoginScripts ) ;If this fails, then the script will back out If @error = -1 Then Exit EndIf ;Now onto running the scripts that it reads RunWait ( "%logonserver%\netlogon\" & $Script ) Until $Script = "NoMoreScripts" Exit
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now