1) When you get to the second gui, the user can select which partition letter they want to perform a directory listing of. When they push the button, it generates a directory listing log for that partition and of only the files containing the extensions. I want the user to be able to select one partition, push the button to create the listing, and then select another partition, and click the button again to generate a listing of that partition (spawning another gui with the progress). For this to happen, I don't think I can have gui3 and need it to be dynamic in some way where it spawns a new gui. How do I do that and how to I replace the various gui3 references in the current code to make those other features of the script work. It seems to work if I go from one selected drop down partition letter to the next, but if I go from one to the next and then retry another one that was previous run, it doesn't work.
Also, the FileAppend,[Directory Listing Exited Before Finishing!!]`n,%OutputFolder%\%FileListing%(%PartitionLetter%_Partition)-%DirectoryListingTime%.txt doesn't work on additional spawned guis.
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
AppName = ABCD_Script v1.0
;output directory for all logs will always be in a folder within the script's directory
;;;;;;;;;;;;;;;;;;MUST RUN AS ADMIN
if not A_IsAdmin = 1
{
Msgbox You must run with admin rights
ExitApp
}
else
{
;;;;;;;;;;;;;;;;;;;;;;Pull info from INI file
IfExist, extensions_config.ini
{
FileRead,config_extensions, extensions_config.ini
;msgbox,%config_extensions%
;;;;;;;;;;;;;;;;;;;;;;
}
}
;;;;;;;;;;;;;;;;;;END-------MUST RUN AS ADMIN
SECTION1:
Start_Time_Local = %A_Now%
Start_Time_UTC = %A_NowUTC%
pull_make_model_SN() ;pulls the info and stores it in the variables
checkavailabledriveletters() ; pull list of partition letters
Gui, 1:Add, Text, x12 y29 w170 h30 , ABCD_Tech (Last_First):
Gui, 1:Add, Edit, x192 y29 w320 h20 vtech,TECH_BOB
Gui, 1:Add, Text, x12 y79 w170 h30 , Custodian Name (Last_First):
Gui, 1:Add, Edit, x192 y79 w320 h20 vcustodian,Doe_John
Gui, 1:Add, Text, x12 y119 w170 h30 , Make:
Gui, 1:Add, Text, x12 y159 w170 h30 , Model:
Gui, 1:Add, Text, x12 y199 w170 h30 , Serial Number:
Gui, 1:Add, Edit, x192 y119 w320 h20 vMake, %Make%
Gui, 1:Add, Edit, x192 y159 w320 h20 vModel, %Model%
Gui, 1:Add, Edit, x192 y199 w320 h20 vSN, %SN%
Gui, 1:Add, Button, x412 y229 w100 h30 gGo, Next
; Generated using SmartGUI Creator 4.0
Gui, 1:Show, x127 y72 h280 w533,%AppName%
Return
1GuiClose:
ExitApp
Go:
Gui, 1: Submit,nohide ; Save the input from the user to each control's associated variable.
emptyfields := [custodian,make,model,sn,tech]
for i,a in emptyfields
{
If !a
{
MsgBox, 48, Warning, All fields are required! ;show error message
return
}
}
Gui,1:Destroy
;=========================OUTPUTS AND FILES===================================
OutputFolder = %Custodian%-%Make%(%SN%)-%Start_Time_Local%
ProcessLog = %Custodian%-%Make%(%SN%)-%Start_Time_Local%_ProcessLog
FileListing = %Custodian%-%Make%(%SN%)-%Start_Time_Local%_FileListing
FileCreateDir,%OutputFolder%
FileCreateDir,%OutputFolder%\Screenshots
ScreenshotFolder = %OutputFolder%\Screenshots
gui_number = 3
;=============================================================================
FileAppend,%AppName%`n`n,%OutputFolder%\%ProcessLog%.txt
FileAppend,Time (Local): %Start_Time_Local%`n,%OutputFolder%\%ProcessLog%.txt
FileAppend,Time (UTC): %Start_Time_UTC%`n,%OutputFolder%\%ProcessLog%.txt
FileAppend,=====================================================`n,%OutputFolder%\%ProcessLog%.txt
FileAppend,ABCD_Tech: %tech%`n,%OutputFolder%\%ProcessLog%.txt
FileAppend,Custodian: %custodian%`n,%OutputFolder%\%ProcessLog%.txt
FileAppend,=====================================================`n,%OutputFolder%\%ProcessLog%.txt
FileAppend,WORKSTATION_INFO:`n,%OutputFolder%\%ProcessLog%.txt
FileAppend,Make: %Make%`n,%OutputFolder%\%ProcessLog%.txt
FileAppend,Model: %Model%`n,%OutputFolder%\%ProcessLog%.txt
FileAppend,SN: %SN%`n,%OutputFolder%\%ProcessLog%.txt
FileAppend,Computer Name: %A_ComputerName%`n,%OutputFolder%\%ProcessLog%.txt
FileAppend,Current Logged In User: %A_UserName%`n,%OutputFolder%\%ProcessLog%.txt
RegRead, OSName, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows NT\CurrentVersion, ProductName
RegRead, BuildNum, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows NT\CurrentVersion, CurrentBuild
FileAppend,OSName (Registry): %OSName%`n,%OutputFolder%\%ProcessLog%.txt
FileAppend,BuildNum: %BuildNum%`n,%OutputFolder%\%ProcessLog%.txt
FileAppend,Operating System Build (AHK): %A_OSVersion%`n,%OutputFolder%\%ProcessLog%.txt
FileAppend,=====================================================`n,%OutputFolder%\%ProcessLog%.txt
Gui, 2:Add, Text, x12 y9 w90 h20 , Source Partition:
Gui, 2:Add, DropDownList, x102 y9 w80 h500 vPartitionLetter, %list%
Gui, 2:Add, Button, x192 y9 w190 h20 gDiskManagement, Open Disk Management
Gui, 2:Add, Text, x12 y49 w190 h20 ,File Extensions To Log (one per line)
Gui, 2:Add, Edit, x12 y79 w380 h140 vextensions,%config_extensions%
Gui, 2:Add, Button, x12 y229 w120 h30 gListFiles, Create File Listing
Gui, 2:Add, Text, x422 y9 w110 h20 gIndexStatus, Check Indexing Status
Gui, 2:Add, Button, x532 y-1 w110 h30 gIndexStatus, Open
Gui, 2:Add, Text, x422 y39 w110 h20 , Screenshot (F11)
Gui, 2:Add, Button, x532 y29 w110 h30 gScreenshot , Screenshot
Gui, 2:Add, Text, x422 y69 w190 h20 , Log Comments:
Gui, 2:Add, Edit, x422 y89 w360 h130 vcomment ,nope
Gui, 2:Add, Button, x662 y219 w120 h30 gLogComment, Add Comment
; Generated using SmartGUI Creator 4.0
Gui, 2:Show, x477 y581 h289 w807,%AppName%
Return
2GuiClose:
ExitApp
DiskManagement:
Run, DiskMgmt.msc
return
Screenshot:
screenshot_timestamp = %A_Now%
Run,"nircmd.exe" savescreenshot "%ScreenshotFolder%\screenshot(%screenshot_timestamp%).png"
sleep,1000
run,"%ScreenshotFolder%\screenshot(%screenshot_timestamp%).png"
return
F11::
IfExist,%ScreenshotFolder%
{
screenshot_timestamp = %A_Now%
Run,"nircmd.exe" savescreenshot "%ScreenshotFolder%\screenshot(%screenshot_timestamp%).png"
sleep,1000
run,"%ScreenshotFolder%\screenshot(%screenshot_timestamp%).png"
}
return
LogComment:
Gui,2:Submit,nohide
FileAppend,COMMENT:%comment%`n,%OutputFolder%\%ProcessLog%.txt
Msgbox,Comment added to process log. You can add more.
GuiControl,2:,comment,
return
IndexStatus:
Run, control.exe srchadmin.dll
;Run, rundll32.exe shell32.dll,Control_RunDLL srchadmin.dll
;Run, control /name Microsoft.IndexingOptions
return
ListFiles:
Gui,2:Submit,nohide
DirectoryListingTime = %A_Now%
run,%OutputFolder%
emptyfields := [PartitionLetter]
for i,a in emptyfields
{
If !a
{
MsgBox, 48,Warning,You must select a partition letter! ;show error message
return
}
}
;;;;;;;;;;;;The following will parse the edit box of extensions and concatenate the extensions on each row with a comma
;msgbox,%extensions%
loop, parse,extensions, "`n"
{
new_extensions .= A_loopfield . ","
}
StringTrimRight, new_extensions, new_extensions, 1
;msgbox,%new_extensions%
;;;;;;;;;;;;;;;;;
FormatTime,TimeString,,yyyy-MM-dd hh:mm:ss tt
FileAppend,Filename|Extension|Size|Modified|Accessed|Created|FullPath`n,%OutputFolder%\%FileListing%(%PartitionLetter%_Partition)-%DirectoryListingTime%.txt
Gui,3:Add, Text, x12 y9 w690 h30 +Center, Generating a listing of the provided extensions on the following partition: %PartitionLetter%:
Gui,3:Add, Text, x12 y79 w690 h130 vVar, %Var%
Gui,3:Add, Text, x12 y49 w690 h20 , Current Location Scanned:
Gui,3:Show, x127 y87 h229 w728,%AppName%
Loop, %PartitionLetter%:\*.* ,0,1 ;0 means only files are retrieved and 1 means subfolders are recursed.
{
GuiControl,3:,Var,%A_LoopFileFullPath%
if A_LoopFileExt in %new_extensions%
{
FileAppend,%A_LoopFileName%|%A_LoopFileExt%|%A_LoopFileSize%|%A_LoopFileTimeModified%|%A_LoopFileTimeAccessed%|%A_LoopFileTimeAccessed%|%A_LoopFileFullPath%`n,%OutputFolder%\%FileListing%(%PartitionLetter%_Partition)-%DirectoryListingTime%.txt
}
}
FileAppend,[DIRECTORY LISTING FINISHED]`n,%OutputFolder%\%FileListing%(%PartitionLetter%_Partition)-%DirectoryListingTime%.txt
Gui,3:Destroy
MsgBox, 262208, %AppName% - Directory Listing, Directory listing of the following partition is complete!`n`nPartition: %PartitionLetter%:
Return
3GuiClose:
FileAppend,[Directory Listing Exited Before Finishing!!]`n,%OutputFolder%\%FileListing%(%PartitionLetter%_Partition)-%DirectoryListingTime%.txt
Gui,3: destroy
return
;========================METHODS================================================
checkavailabledriveletters()
{
global
List := ""
Alphabet = A.B.C.D.E.F.G.H.I.J.K.L.M.N.O.P.Q.R.S.T.U.V.W.X.Y.Z ; check all the possible drive letters
Loop, Parse, Alphabet, .
{
IfExist, %A_LoopField%:\
{
;msgbox, drive letter exists %A_LoopField%:\
List .= A_LoopField "|"
}
IfNotExist, %A_LoopField%:\
{
;msgbox, drive letter DOES NOT EXIST: %A_LoopField%:\
}
continue
}
}
pull_make_model_SN()
{
global
strComputer := "."
objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" strComputer "\root\cimv2")
colSettings := objWMIService.ExecQuery("Select * from Win32_DiskDrive")._NewEnum
while colSettings[strCSItem]
{
;WMI get info
strComputer := "."
objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" strComputer "\root\cimv2")
colSettings := objWMIService.ExecQuery("Select * from Win32_ComputerSystemProduct")._NewEnum
vList := "Vendor,Name,IdentifyingNumber"
Loop, Parse, vList, % ","
{
source_flag = 0 ; set flag to 0 to start with before the check
while colSettings[strCSItem]
{
Make := strCSItem.Vendor ; create variable with one of the items from the list
Model := strCSItem.Name ; create variable with one of the items from the list
SN := strCSItem.IdentifyingNumber ; create variable with one of the items from the list
;~ msgbox, %Make%
;~ msgbox, %Model%
;~ msgbox, %SN%
}
}
}
objWMIService := colSettings := strCSItem := ""
}