Sign in to follow this  
Followers 0
3deepu

Batch script within Autoit script does not run on certain models

18 posts in this topic

Hi there,

This is my first post on the forum and has only recently starting using Autoit. I have created fairly simple script that gets the model no of the machine the script is running on using wni_computersytem and then runs the corresponding batch script to dump a ghost image. it seems to run on all the machines except 2 dell machines where it go through the first part but then does not do the second part. i have copied a sample of the script below, could you please advise why is this happening.

The problem is with the model E6400 and D630. It works fine till Choose Drive part and after that when the corresponding button is selected it just exits. Appreciate if someone could advise why this is happening.

Thanks

forum.txt

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I suggest do add some error checking:

Global $objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!" & $strcomputer & "rootcimv2")
If @error or Not IsObj($objWMIService) Then Exit MsgBox(16, "ERROR", "Error " & @error & " accessing WMI!")
Global $colSettings = $objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
If @error or Not IsObj($colSettings) Then Exit MsgBox(16, "ERROR", "Error " & @error & " querying WMI!")
MsgBox(64, "Count", "Records found: " & $colSettings.count)
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Hi Water,

I did as you suggested but it did not give me any errors.

Share this post


Link to post
Share on other sites

I modified my post above to output the number of records found. What do you get?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

it says records found:1

Share this post


Link to post
Share on other sites

Then you need to insert some debugging statements into your PART and FULL functions to make sure the returned results are what you expect. Something like:

ConsoleWrite(">" & $CompName & "<" & @CRLF & ">" & $CompModel & "<" & @CRLF)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

after the above line is added to the functions, the script outputs the machine name and model on other machines but there is no output on D630. Is there a way we can do line wise execution of the script like we get for Autoexec file.

Thanks

Edited by 3deepu

Share this post


Link to post
Share on other sites

No output at all or just

><
><

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Is there a way we can do line wise execution of the script like we get for Autoexec file.

To see which statements are executed add
#AutoIt3Wrapper_Run_Debug_Mode=Y
at the top of your script and run the script from SciTE.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

No, there is no output at all.

Share this post


Link to post
Share on other sites

what will the statement do. because when run under SciTE, it just runs as normal script.

Share this post


Link to post
Share on other sites

If you run the Script in Debug mode you get this on the Scite console pane:

>Running:(3.3.8.1):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Temp\test.au3"
!> Starting in DebugMode..
Line: @error-@extended: Line syntax
0001: 0-0: #AutoIt3Wrapper_Run_Debug_Mode=Y
0002: 0-0: Dim $strcomputer = "."
0003: 0-0: Dim $objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strcomputer & "\root\cimv2")
0004: 0-0: Dim $colSettings = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
0006: 0-0: $var = MsgBox(4, "Choose Drive", "Select YES to choose C Drive Imaging")
0007: 0-0: If $var = 6 Then PART()
0008: 0-0: If $var = 7 Then FULL()
0029: 0-0: For $objComputer In $colSettings
0030: 0-0: $CompName = $objComputer.Name
0031: 0-0: $CompModel = $objComputer.Model
0032: 0-0: Next
0033: 0-0: ConsoleWrite(">" & $CompName & "<" & @CRLF & ">" & $CompModel & "<" & @CRLF)
>Cxxxx<
>HP Compaq dc5800 Microtower<
0039: 0-0: If $CompModel = "Latitude E6420" Then RunWait(@ScriptDir & "\6420F.bat", @ScriptDir, @SW_MAXIMIZE)
0040: 0-0: If $CompModel = "Latitude E6410" Then RunWait(@ScriptDir & "\6410F.bat", @ScriptDir, @SW_MAXIMIZE)
0041: 0-0: If $CompModel = "Latitude E6400" Then RunWait(@ScriptDir & "\6400F.bat", @ScriptDir, @SW_MAXIMIZE)
0042: 0-0: If $CompModel = "Latitude D630" Then RunWait(@ScriptDir & "\D630F.bat", @ScriptDir, @SW_MAXIMIZE)
0044: 0-0: EndFunc ;==>FULL
0010: 0-0: Func PART()
0028: 0-0: Func FULL()
0045: 0-0: #cs
+>09:56:57 AutoIT3.exe ended.rc:0
>Exit code: 0 Time: 3.175

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I found the problem, what happens is that when the computer model is read from the system by the script, it outputs it as >Latitude D630 < instead of >Latitutde D630<. this extra space is causing the problem. any way of removing this when it outputs or else will have to copy the exact no of spaces into the script.

thanks

Share this post


Link to post
Share on other sites

Use

$CompModel = StringStripWS($CompModel, 3)
to remove leading and trailing spaces.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thanks Water, the script is working fine. i had another little query, what if I need to put a wildcard on the CompModel.

Share this post


Link to post
Share on other sites

You could use functions StringLeft, StringMid, StringInStr or even Regular Expressions to check for a substring. Wildcards can only be used with regular expressions (as far as I know).

Do you have an example what you want to look for?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

for e.g. i have a model 6974WDX and 6974WWN the ghost images for both models are the same , so I was wondering if I could use "6474*" instead of the specific models. Another question, can i have all these models listed in a db along with their respective scripts and not enter these specific lines in the script itself.

e.g. it will check for the model against the list of models in a db and then apply the appropriate script. sorry to bombard you with these querries but the more I am using Autoit the more I am liking it. also I am impressed with your response.

Share this post


Link to post
Share on other sites

Ad 1) Something like

If StringLeft($CompModel, 4) = "6974" Then ...

Ad 2) It's possible but needs more work. You need to access the DB and extract the data. You need another script to maintain the data in the DB. A DB only makes sense when a lot of people/PCs should access the same data that changes often.

You could use INI files and read the content to an array.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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