Announcement

Collapse
No announcement yet.

Help! Fixed drives to checkboxes?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • syahendra
    replied
    This example in combobox, can be implemented into listbox

    function fListOfFixedDisks()

    tblDrives = Drive.Enumerate();

    if (tblDrives) then
    for i, strDrive in pairs(tblDrives) do
    nType = Drive.GetType(strDrive);
    if (nType == 3) then
    mydrive = String.Left(strDrive, 1);
    ComboBox.AddItem("ComboBox1", ""..mydrive.." ", "FIXED");
    end
    ComboBox.SetSelected("ComboBox1", 1);
    end
    end
    end

    --The actual Function call
    fListOfFixedDisks()

    Leave a comment:


  • Shadow91
    replied
    Again, sorted it. My problem was me trying to trim the last two characters - took a different approach and selected the first character instead...

    Code below if anyone is interested:

    local tChecked = ListBox.GetChecked("DriveChoice", BST_CHECKED);
    if (tChecked ~= nil) then
    for i,v in pairs (tChecked) do
    --Stip the :\ from the value so just the drive letter can be used in PowerShell script
    drive = ListBox.GetItemText("DriveChoice", v);
    driveletter = String.Mid(drive, 1, 1);
    --Create the PowerShell script
    TextFile.WriteFromString("C:\\Defrag\\Defrag.ps1", "optimize-volume " ..driveletter.. " -Defrag -verbose 4>C:\\Defrag\\Defrag" ..driveletter.. ".txt \r\n", true);
    end
    else
    --Alert if no drives were selected
    Dialog.Message("info", "No drives selected");
    end

    Leave a comment:


  • Shadow91
    replied
    Ok, so I did manage to work this out eventually, by outputting the drives to a listbox with checkboxes using the code below to run on preload:

    drives = Drive.Enumerate();
    for j,k in pairs (drives) do
    drive_type = Drive.GetType (k)
    if drive_type == 3 then
    result = ListBox.AddItem("DriveChoice", k .. "");
    end
    end

    This outputs the drives correctly but it does include a ":" after each drive letter.

    Could somebody help me strip that so it is just the letter, as I then need to extract this and insert it into a PowerShell script and I am struggling to make this work... I have it extracting the value and writing the script correctly, but it is inserting the ":" which doesn't work - this is how I am achieving that:

    local tChecked = ListBox.GetChecked("DriveChoice", BST_CHECKED);
    if (tChecked ~= nil) then

    for i,v in pairs (tChecked) do
    TextFile.WriteFromString("C:\\Defrag\\Defrag.ps1", "optimize-volume " .. ListBox.GetItemText("DriveChoice", v).. " -Defrag -verbose 4>C:\Defrag\Defrag.txt \r\n", true);

    end
    else
    Dialog.Message("info", "No drives selected");
    end

    Leave a comment:


  • Shadow91
    started a topic Help! Fixed drives to checkboxes?

    Help! Fixed drives to checkboxes?

    Hi, I have tried a few snippets from a search of the forum but to no avail to what I am trying to achieve - so if anyone can help that'd be much appreciated.

    I am trying to create a custom script which will set a scheduled task to defragmet the local fixed hard drives based on the configuration determined by the application I am making in AMS 8.5.

    I have most of it sorted, but what I'd like to do is, either at the click of a button, or better yet, pre-load, have a list of local fixed hard drives with a checkbox next to each one, so that a user can "tick" the drives they wish to include in the defrag schedule.

    I would like it to automate the amount of checkboxes (could be a checkbox selectable listbox, whatever works and looks good really) it creates, so if a user just has 2 drives (C and D), then only 2 show, if they just have 1, then just it shows, and if they have 10, then these all show - but it must only show fixed drives.

    Thanks in advance...
Working...
X