Sign in to follow this  
Followers 0
pjw73nh

_RunDos need help. Missing EndIF ?

10 posts in this topic

Greetings,

Please take a quick look at my code. I have two questions regarding it.

I want my script to test a machine for an IP address in a specific range, and then run a command if any of the conditions are true. The script functions OK as it is written. However,

1. If I remove the ";" before the #include <process.au3>... IE (un-rem) the line, I will get a "missing EndIf" error and I am not sure why.

I have only put the DIR C: command in, because I want to test THIS DOS command before I put my actual command in there. The MsgBox commands are just for testing.

2. Is there a better way to tighten up the code? I was thing of using a boolean OR instead of the multiple ElseIf commands, but I couldn't find the right syntax.

Thank you in advance.

Paul...

Verifies if OS is Windows XP, exits script if not.
If @OSVersion <> "WIN_XP" Then
    Exit
EndIf
;  Checks to see if IP address falls in the DHCP range for the EH site. Exits if not.
$IP1 = StringLeft(@IPAddress1, 7)

If $IP1 = "1.1.1.40" Then
    MsgBox(0, "The program will run", "40 Leftmost 7 characters of IP Address are: " & $IP1)
;   #include <Process.au3>_RunDOS("dir c:\")
    Exit
ElseIf $IP1 = "1.1.41." Then
    MsgBox(0, "The program will run", "41 Leftmost 7 characters of IP Address are: " & $IP1)
    Exit
ElseIf $IP1 = "1.1.42." Then
    MsgBox(0, "The program will run", "42 Leftmost 7 characters of IP Address are: " & $IP1)
    Exit
ElseIf $IP1 = "1.1.43." Then
    MsgBox(0, "The program will run", "43 Leftmost 7 characters of IP Address are: " & $IP1)
    Exit
ElseIf $IP1 = "1.1.44." Then
    MsgBox(0, "The program will run", "44Leftmost 7 characters of IP Address are: " & $IP1)
    Exit
Else
    MsgBox(0, "The program will NOT run", "Leftmost 7 characters of IP Address are: " & $IP1)
EndIf


$IP2 = StringLeft(@IPAddress1, 3)
If $IP2 = "10." Then
    MsgBox(0, "The program will run", "IP2 Leftmost 3 characters of IP Address are: " & $IP2)
    Exit
Else
    MsgBox(0, "The program will NOT run", "IP2 Leftmost 3 characters of IP Address are: " & $IP2)
    Exit
EndIf

Share this post


Link to post
Share on other sites



your problem is in your first line, you need to add a semicolon to make that a comment or else it takes it as code (including the if)

So this:

Verifies if OS is Windows XP, exits script if not.

becomes this:

;Verifies if OS is Windows XP, exits script if not.

---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Share this post


Link to post
Share on other sites

your problem is in your first line, you need to add a semicolon to make that a comment or else it takes it as code (including the if)

So this:

Verifies if OS is Windows XP, exits script if not.

becomes this:

;Verifies if OS is Windows XP, exits script if not.

Sorry about that. I just didn't get the first semi-colon when I selected the text with the copy/paste into the forum post. The semi is acutally in my script. So I think the problem is elsewhere. Thanks for the reply though. Paul...

Share this post


Link to post
Share on other sites

_RunDos will not work with "dir c:\" try

Run(@ComSpec & " /c " & 'dir c:\', "")


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

The reason why your script not work is because you have this line all together #include <Process.au3>_RunDOS("dir c:\") you should put #include<Process.au3> at the begining of your script

I short your script a little. I hope this will help you....

#include <Process.au3>

;Verifies if OS is Windows XP, exits script if not.
If @OSVersion <> "WIN_XP" Then
   Exit
EndIf
;  Checks to see if IP address falls in the DHCP range for the EH site. Exits if not.
$IP1 = StringLeft(@IPAddress1, 7)
$IP2 = StringLeft(@IPAddress1, 3)

If $IP1 = "1.1.1.40" Then
    MsgBox(0, "The program will run", "40 Leftmost 7 characters of IP Address are: " & $IP1)
    _RunDOS("dir c:\")
    Exit
ElseIf $IP1 = "1.1.41." Or $IP1 = "1.1.42." Or $IP1 = "1.1.43." Or $IP1 = "1.1.44." Then
    MsgBox(0, "The program will run", StringMid($IP1, 5,2) & " Leftmost 7 characters of IP Address are: " & $IP1)
    Exit
ElseIf $IP2 = "10." Then
    MsgBox(0, "The program will run", "IP2 Leftmost 3 characters of IP Address are: " & $IP2)
    Exit
Else
    MsgBox(0, "The program will NOT run", "Leftmost 7 characters of IP Address are: " & $IP1 & @CRLF & @CRLF & "IP2 Leftmost 3 characters of IP Address are: " & $IP2)
EndIf
Keep in mind that _RunDos will work with "dir c:\" but the command window is hiden so you will not be able to see anything I will try "dir c:\ > c:\Dir.Log" after the script is done check the log file at the C: drive. Edited by Danny35d

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

The reason why your script not work is because you have this line all together #include <Process.au3>_RunDOS("dir c:\") you should put #include<Process.au3> at the begining of your script

I short your script a little. I hope this will help you....

#include <Process.au3>

;Verifies if OS is Windows XP, exits script if not.
If @OSVersion <> "WIN_XP" Then
   Exit
EndIf
;  Checks to see if IP address falls in the DHCP range for the EH site. Exits if not.
$IP1 = StringLeft(@IPAddress1, 7)
$IP2 = StringLeft(@IPAddress1, 3)

If $IP1 = "1.1.1.40" Then
    MsgBox(0, "The program will run", "40 Leftmost 7 characters of IP Address are: " & $IP1)
    _RunDOS("dir c:\")
    Exit
ElseIf $IP1 = "1.1.41." Or $IP1 = "1.1.42." Or $IP1 = "1.1.43." Or $IP1 = "1.1.44." Then
    MsgBox(0, "The program will run", StringMid($IP1, 5,2) & " Leftmost 7 characters of IP Address are: " & $IP1)
    Exit
ElseIf $IP2 = "10." Then
    MsgBox(0, "The program will run", "IP2 Leftmost 3 characters of IP Address are: " & $IP2)
    Exit
Else
    MsgBox(0, "The program will NOT run", "Leftmost 7 characters of IP Address are: " & $IP1 & @CRLF & @CRLF & "IP2 Leftmost 3 characters of IP Address are: " & $IP2)
EndIf
Keep in mind that _RunDos will work with "dir c:\" but the command window is hiden so you will not be able to see anything I will try "dir c:\ > c:\Dir.Log" after the script is done check the log file at the C: drive.

Thanks folks. Both of those ideas solved the issue. Thanks for tightening up my code for me. That is exactly the syntax I was looking for.

Paul...

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

_RunDos will not work with "dir c:\" try

Run(@ComSpec & " /c " & 'dir c:\', "")

uhm whats the real diffence and when doesn't rundos work??

my _rundos I found in the include directory was made for running commands like that

Func _RunDOS($sCommand)
    Return RunWait(@ComSpec & " /C " & $sCommand, "", @SW_HIDE)
EndFunc;==>_RunDOS

So it does work, and like the other pointed out you cannot see the output

Edited by MrSpacely

Share this post


Link to post
Share on other sites

So it does work, and like the other pointed out you cannot see the output

That is what I meant to say but did not word it correctly. He stated in the original post that the _rundos command was there so that he could see if it worked. What I meant to say was that the _rundos command he was using would not let him see if it was working.

Thanks for pointing out my error.



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

That is what I meant to say but did not word it correctly. He stated in the original post that the _rundos command was there so that he could see if it worked. What I meant to say was that the _rundos command he was using would not let him see if it was working.

Thanks for pointing out my error.

Thanks for reacting :P

Share this post


Link to post
Share on other sites

There's a small logic error here:

···
$IP1 = StringLeft(@IPAddress1, 7)
If $IP1 = "1.1.1.40" Then
···

As you are comparing a 7-character string to an 8-character one, that test will always fail. If you would like to check whether one string begins with another, then you could do this:

If StringInStr('this is my long string', 'this is my') = 1 Then
    MsgBox(0x40, '', 'The first string begins with the second.')
EndIf

Also, as you are basically doing comparison of numbers you could split the IP address into four separate numbers and look at them that way. Here's another approach to what you're going for:

; Only continue under XP
If @OSVersion <> 'WIN_XP' Then
    MsgBox(0x10, 'Error', 'This utility can only be called under Windows XP.')
    Exit
EndIf

; Determine if the IP address falls in the DHCP range for the EH site
$IP = StringSplit(@IPAddress1, '.')

; $IP is now an array where $IP[1] is the first octet, etc.

; If the IP address is in the form 1.1.[40-44].x or 10.x.x.x then
If ($IP[1] = 1 And $IP[2] = 1 And $IP[3] >= 40 And $IP[3] <= 44) Or ($IP[1] = 10) Then
    $Message = 'The program will run.'
Else
    $Message = 'The program will NOT run.'
EndIf

MsgBox(0x40, 'IP address: ' & @IPAddress1, $Message)

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