Jump to content
Sign in to follow this  
EddardStark

Trying to run something in %logonserver%. Help please.

Recommended Posts

EddardStark

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")

Share this post


Link to post
Share on other sites
TerarinK

Where do you got %logonserver% specificied, aren't you suppose to be using @LogonDomain or @LogonServer


0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

Share this post


Link to post
Share on other sites
KaFu

$LoginScripts = FileOpen(@LogonServer  & "\netlogon\LoginScripts.txt", 0 )
...
RunWait(@LogonServer  & "\netlogon\" & $Script1)

might work...

Edited by KaFu

Share this post


Link to post
Share on other sites
EddardStark

Where do you got %logonserver% specificied, aren't you suppose to be using @LogonDomain or @LogonServer

It'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.

Share this post


Link to post
Share on other sites
EddardStark

$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 by EddardStark

Share this post


Link to post
Share on other sites
EddardStark

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

Share this post


Link to post
Share on other sites
EddardStark

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!

Share this post


Link to post
Share on other sites
AdmiralAlkex

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 :P

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

Share this post


Link to post
Share on other sites
EddardStark

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

Share this post


Link to post
Share on other sites
JSThePatriot

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)

Share this post


Link to post
Share on other sites
EddardStark

Wow. This is a great forum. :P I'll check those out.

Share this post


Link to post
Share on other sites
JSThePatriot

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)

Share this post


Link to post
Share on other sites
EddardStark

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

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.