Jump to content

Syntax Help With Variables


Recommended Posts

Group,

I'm working on a script to manage OS Hotfixes and I need some help with a line of syntax. Basically I have the different types of hotfixes in subfolders from where the script is ran (i.e. OS folder for standard Security Hotfixes, IE folder for Internet Explorer hotfixes, etc.). The snippet of code I'm having trouble with is listed below:

$Hotfix = 'KB828028'; The Hotfix number and Sub-folder of $FixDir
$FileName = 'WindowsXP-KB828028-x86-ENU.exe'; File to be executed
$CmdLine = '/u /q /z'; any command line parameters
$FixDir = '\OS\'; The first sub-folder, specifies type of hotfix
    PatchChk ( )

Func PatchChk ( )
SplashTextOn("HotFix Check", "Checking for HotFix " & $Hotfix, 450, 90)
Sleep (500)
SplashOff ( )
$Patch = RegRead ( 'HKEY_LOCAL_MACHINE\' & 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Hotfix\'& $Hotfix, 'Installed' )
If NOT $Patch = '1' then
    NoFix ( )
Else
    FixOK ( )
EndIf
EndFunc

Func NoFix ( )
    SplashTextOn("Hot Fix Not Installed", "Installing " & $HotFix & " Please Wait", 450, 90)
    Sleep (1000)
    SplashOff ( )
    RunWait(@WorkingDir & $FixDir & $HotFix & "\" & $FileName & $CmdLine, "C:\WINDOWS", @SW_MAXIMIZE)
EndFunc

Func FixOk ( )
    SplashTextOn("Hot Fix Installed", "Hot Fix " & $HotFix & " Is Installed", 450, 90)
    Sleep (1000)
    SplashOff ( )
EndFunc

When I run the script I receive the following error Line 23 (Where 'RunWait' starts above)

RunWait(@WorkingDir & "\OS\" & $HotFix & "\" & $FileName & $CmdLine, "C:\WINDOWS", @SW_MAXIMIZE)

Error: Unable to execute the external program.

The system cannot find the file specified.

I Assume that it is a simple syntax error with how I'm trying to use/insert variables when calling the external hotfix file, but I have tried multiple combinations and I must be missing the right one :whistle: .

Any help would be appreciated.

Thanks,

ZK

Edited by ZenKensei
Link to comment
Share on other sites

I believe @WorkingDir is the problem. Make sure it has the value you think is has by inserting the following before line 23: MsgBox(4096,"", @WorkingDir)

Look at "FileChangeDir" in the help file for more information.

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

CyberSlug,

Thanks for the quick reply, I did as you suggested and it brought back the actual current directory the script is running in (which it should). The sub-folders where the hotfixes lie all reside under the directory the script is running from.

This folder setup will exist on sharepoints on various servers throughout the Enterprise, so when a user runs the script from their workstation the folder structure is always the same.

Example:

Windows XP Professional SP1 (Root of the shared patch folder & Script resides here)

----- OS (Standard OS Hotfixes sub-folder = $FixDir)

---------- KB111111 (individual Hotfixes sub-folder = $HotFix)

----------------KB111111.Exe (actual Hotfix file = $FileName

-------------------- /q /z (command line params = $CmdLine)

So, I'm using $FixDir for the type of folder that specific KB article deals with, mostly using the OS sub-folder.

Using $Hotfix as the specific Hotfix to call as well as the sub-folder residing below the $FixDir folder.

Using the $FileName for the actual Hotfix executable to run.

Using the $CmdLine as the parameters to pass along to $FileName.

So I'm looking to do 'RunWait ($Fixdir\$Hotfix\$FileName $Cmdline)

I assume that I need the @workingdir to specify that the folders I will running the Hotfixes from are located within sub-folders from where the script is actually ran.

Any other possible suggestions on what might be the issue? The reason I'm using the variables for all the path's is because I'm chaining the patches and calling the function routine to cut down lines of code. As new patches are released I simply add the

$Hotfix = 'KB New Patch'

$FileName = 'WindowsXP-KB New Patch-x86-ENU.exe'

$CmdLine = '/u /q /z'

$FixDir = '\OS\'

PatchChk ( )

Let me know what you think

Link to comment
Share on other sites

Ah, I might see it....

@WorkingDir & $FixDir & $HotFix & "\" & $FileName & $CmdLine

Three potential problems

1) the command line parameters might be runing in to the file name

2) the full path might contain spaces, so it needs to be in quotes

3) if the file is an MSI installer instead of an EXE, then see Question #6 in the help file FAQ

Try this:

$path = @WorkingDir & $FixDir & $HotFix & "\" & $FileName
 RunWait('"' & $path & '" ' & $CmdLine, "C:\WINDOWS", @SW_MAXIMIZE)

You can use either '"', as I do, to insert a double quote; or you can use """"

Hope that helps

Edited by CyberSlug
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

Cyberslug,

Thank you so much for the help, and yes you were correct. :whistle: Once I added the appropriate spaces everything started working as I had hoped. It always seems to be the little things that trip me up and nothing helps to teach the fundamentals like a good code example. So, thanks again for your help and the MS Security Patch script I've been working on is coming right along, I have completed the Windows XP part of the script, now working on the Windows 2000, etc.

Z/K

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...