Sign in to follow this  
Followers 0
Boss007

Help needed with script for working out o/s and free drivespace

3 posts in this topic

Hi all,I'm trying to write a script with routine's that need to

1.work out o/s version

2.work out the o/s architecture

3. calculates free hard drive space for all connected hard drives ,

4. deliver software to the home drive,

5. deliver folders to the first available hard drive with enougth space that does not

contain the operating system,if there is no other hard drive connected the routine must deliver folders to the

homedrive's user area instead.

I am a novice and I know this code dosen't have to be so long and cumbersome if the main body could some how be incorporated in the very first routine to find hard drives connected it would be great! I have marked the areas with problems by making comments just before the problem area as you go down the script. I know my scripting is awful but any help would be appreciated. many thanks

freespacecalculator.au3

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Next time I would suggest adding the code to the post in code blocks as opposed to attaching it.

Here's an alternate implmentation:

Local $aDrives, $iHomeDrive, $iFolderDrive = 0, $sMsg = ""

$aDrives = DriveGetDrive("FIXED")
If @error Then
    MsgBox(0, "Error", "Could not get drive information.")
    Exit
EndIf

Dim $aDriveInfo[$aDrives[0] + 1][2]
$aDriveInfo[0][0] = $aDrives[0]
For $i=1 to $aDrives[0]
    $aDriveInfo[$i][0] = StringUpper($aDrives[$i])
    $aDriveInfo[$i][1] = DriveSpaceFree($aDrives[$i] & "")
    If $aDriveInfo[$i][0] = @HomeDrive Then
        $iHomeDriveFreeSpace = $aDriveInfo[$i][1]
        $iHomeDrive = $i
    Else
        If $iFolderDrive == 0 And $aDriveInfo[$i][1] >= 1024 Then $iFolderDrive = $i
    EndIf
    $sMsg &= StringFormat("%s (%.2f MB)n", $aDriveInfo[$i][0], $aDriveInfo[$i][1])
Next
MsgBox(0, "", $sMsg)

If $aDriveInfo[$iHomeDrive][1] < 1024 Then
    MsgBox(0,"Cannot Install","Not enough space or Operating System on wrong Drive"&@OSVersion&@OSArch)
    Exit
ElseIf $iFolderDrive == 0 And $aDriveInfo[$iHomeDrive][1] < 2048 Then
    MsgBox(0,"Cannot Install","Not enough space for folders"&@OSVersion&@OSArch)
    Exit
Else
    $sMsg = ""
    If $iFolderDrive == 0 Then $iFolderDrive = $iHomeDrive
    Switch @OSVersion
        Case "WIN_7"
            Switch @OSArch
                Case "X86"
                    $sMsg = StringFormat("Installing 32 bit Software to Drive %s and Folders to Drive %s [%s %s]", _
                        $aDriveInfo[$iHomeDrive][0], $aDriveInfo[$iFolderDrive][0], @OSVersion, @OSArch)
                Case "IA64", "X64"
                    $sMsg = StringFormat("Installing 64 bit Software to Drive %s and Folders to Drive %s [%s %s]", _
                        $aDriveInfo[$iHomeDrive][0], $aDriveInfo[$iFolderDrive][0], @OSVersion, @OSArch)
            EndSwitch
            MsgBox(0, "", $sMsg)
        Case "WIN_XP"
            ; same thing
    EndSwitch
EndIf
Edited by zorphnog

Share this post


Link to post
Share on other sites

Next time I would suggest adding the code to the post in code blocks as opposed to attaching it.

Here's an alternate implmentation:

Local $aDrives, $iHomeDrive, $iFolderDrive = 0, $sMsg = ""

$aDrives = DriveGetDrive("FIXED")
If @error Then
MsgBox(0, "Error", "Could not get drive information.")
Exit
EndIf

Dim $aDriveInfo[$aDrives[0] + 1][2]
$aDriveInfo[0][0] = $aDrives[0]
For $i=1 to $aDrives[0]
$aDriveInfo[$i][0] = StringUpper($aDrives[$i])
$aDriveInfo[$i][1] = DriveSpaceFree($aDrives[$i] & "")
If $aDriveInfo[$i][0] = @HomeDrive Then
$iHomeDriveFreeSpace = $aDriveInfo[$i][1]
$iHomeDrive = $i
Else
If $iFolderDrive == 0 And $aDriveInfo[$i][1] >= 1024 Then $iFolderDrive = $i
EndIf
$sMsg &= StringFormat("%s (%.2f MB)n", $aDriveInfo[$i][0], $aDriveInfo[$i][1])
Next
MsgBox(0, "", $sMsg)

If $aDriveInfo[$iHomeDrive][1] < 1024 Then
MsgBox(0,"Cannot Install","Not enough space or Operating System on wrong Drive"&@OSVersion&@OSArch)
Exit
ElseIf $iFolderDrive == 0 And $aDriveInfo[$iHomeDrive][1] < 2048 Then
MsgBox(0,"Cannot Install","Not enough space for folders"&@OSVersion&@OSArch)
Exit
Else
$sMsg = ""
If $iFolderDrive == 0 Then $iFolderDrive = $iHomeDrive
Switch @OSVersion
Case "WIN_7"
Switch @OSArch
Case "X86"
$sMsg = StringFormat("Installing 32 bit Software to Drive %s and Folders to Drive %s [%s %s]", _
$aDriveInfo[$iHomeDrive][0], $aDriveInfo[$iFolderDrive][0], @OSVersion, @OSArch)
Case "IA64", "X64"
$sMsg = StringFormat("Installing 64 bit Software to Drive %s and Folders to Drive %s [%s %s]", _
$aDriveInfo[$iHomeDrive][0], $aDriveInfo[$iFolderDrive][0], @OSVersion, @OSArch)
EndSwitch
MsgBox(0, "", $sMsg)
Case "WIN_XP"
; same thing
EndSwitch
EndIf

Thanks very much your a genius! made me realise how out of my depth I was. I don't even know how to post properly,but I'm taking it all in slowly,I have looked at your implementation and abandoned mine instantly. I understood yours and It made sence straight away ,much more streamline and manageable.I am going back to school to look up courses in this subject ,once again many thanks! if I ever make it I won't forget you!!!

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