Jump to content
OMGWTFLOLBBQ

Text to Array

Recommended Posts

OMGWTFLOLBBQ

Hello!

 I've been going through all of the help files and examples, but I feel lost. I can't seem to find what I need. Essentially, what I'm doing is simple(in my head).

Create a file based on the information needed, select a line in that file, then put that line back in DOS. My code is below, I know it's messy, but I'll take the heat if you can help.

 

;BitlockerUpdate
;2016.05.24

HotKeySet("{ESC}", "Terminate")

Run("C:\Windows\System32\CMD.exe") ;open command prompt
Sleep(500) ;sleep half second
if ProcessExists("cmd.exe") Then
   winactivate("Administrator: C:\Windows\System32\CMD.exe") ;refocus command prompt
   Send("C:")
   Send("{ENTER}")
   send("CD{SPACE}%windir%\sysnative\")
   send("{ENTER}")
EndIf

;create file with Bitlocker Protectors
Send("manage-bde.exe{SPACE}-protectors{SPACE}-get{space}c:{space}>{Space}%userprofile%\Desktop\protectors.txt") ;send code "manage-bde -protectors -get c: > %userprofile%\Desktop\protectors.txt"
Send("{ENTER}") ;send enter key to create text file on desktop with protectors
Sleep(1000) ;sleep one second(1s)


;edit txt file/create array, pull line and paste into new file, copy text then paste into cmd window below


;update data
if ProcessExists("cmd.exe") Then
   winactivate("Administrator: C:\Windows\System32\CMD.exe") ;refocus command prompt
   Send("manage-bde.exe{SPACE}-protectors{SPACE}-adbackup{SPACE}c:{SPACE}-id{SPACE}{COPIEDINFORMATIONGOESHERE}")
   Send("{ENTER}")
   ;don't forget to delete temp file if you create one created.
EndIf

;remove files
if ProcessExists("cmd.exe") Then
   winactivate("Administrator: C:\Windows\System32\CMD.exe") ;refocus command prompt
   Send("DEL{SPACE}%userprofile%\Desktop\protectors.txt") ;send code to delete protectors.txt
   Send("{ENTER}")
   ;don't forget to delete temp file if you create one created.
EndIf

MsgBox(0,"Done","Copy and upload are done. Please check Computer in AD.")

Func Terminate()
    Exit 0
EndFunc

 

The protectors.txt file looks like this:

BitLocker Drive Encryption: Configuration Tool version 6.1.7601
Copyright (C) Microsoft Corporation. All rights reserved.

Volume C: [OSDisk]
All Key Protectors

    TPM:
      ID: {0000000-0000-0000-0000-0000000}

    Numerical Password:
      ID: {1000000-1000-1000-1000-1000000}
      Password:
        000000-000000-000000-000000-000000-000000-000000

    Data Recovery Agent (Certificate Based):
      ID: {2000000-2000-2000-2000-2000000}
      Certificate Thumbprint:
        1111111a1aa1a1aa1a1a1a1aaaaaa1aaa1

I would specifically need the line after Numerical Password. 

Original line:      ID: {1000000-1000-1000-1000-1000000}

Needed information: -ID: {1000000-1000-1000-1000-1000000}

 

I apologize in advance for inconveniencing anyone with my silly issues. Hopefully this can stand as a great learning experience for both me and anyone else looking.

 

Share this post


Link to post
Share on other sites
JLogan3o13

@OMGWTFLOLBBQ I have moved your question to the appropriate forum, the Developers forum specifically states it is not for AutoIt-related questions. Please be mindful of where you post ;)

 


√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
OMGWTFLOLBBQ
Just now, JLogan3o13 said:

@OMGWTFLOLBBQ I have moved your question to the appropriate forum, the Developers forum specifically states it is not for AutoIt-related questions. Please be mindful of where you post ;)

 

Apologies for the mistake, I'll be more careful in the future.

Share this post


Link to post
Share on other sites
JLogan3o13

In answer to your question: First, have you tried using just Run or ShellExecute with the appropriate switches, rather than all the Sends? Something like so?

ShellExecute("manage-bde.exe", "-protectors -get " & @DesktopDir & "\protectors.txt")

 

Second: You could read the file to an array, and parse through it that way. Something like this:

#include <File.au3>

$sFile = @DesktopDir & "\Protectors.txt"
$aFile = FileReadToArray($sFile)


For $i = 0 To UBound($aFile)
    If StringInStr($aFile[$i], "Numerical Password:") Then MsgBox($MB_OK, "", $aFile[$i + 1])
Next

One of our RegEx gurus will come along and do that more quickly, I am sure, but that should get you started :)


√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
OMGWTFLOLBBQ
23 minutes ago, JLogan3o13 said:

In answer to your question: First, have you tried using just Run or ShellExecute with the appropriate switches, rather than all the Sends? Something like so?

ShellExecute("manage-bde.exe", "-protectors -get " & @DesktopDir & "\protectors.txt")

 

Second: You could read the file to an array, and parse through it that way. Something like this:

#include <File.au3>

$sFile = @DesktopDir & "\Protectors.txt"
$aFile = FileReadToArray($sFile)


For $i = 0 To UBound($aFile)
    If StringInStr($aFile[$i], "Numerical Password:") Then MsgBox($MB_OK, "", $aFile[$i + 1])
Next

One of our RegEx gurus will come along and do that more quickly, I am sure, but that should get you started :)

Thanks for the suggestions! Definitely got a few gears running. As for the first, I attempted ShellExecute, but it kept giving an error about "windows cannot find "manage-bde.exe". I know it's messy, but it seems to work...for now. After I get this working, I'll definitely work on streamlining it for the future.

 

Second, I've edited code based off of what you've suggested. 

$sFile = "%userprofile%\Desktop\protectors.txt"
$aFile = FileReadToArray($sFile)

For $i = 0 To UBound($aFile)
    If StringInStr($aFile[$i], "Numerical Password:") Then _ArrayToClip($MB_OK, "", $aFile[$i + 1])
Next

if ProcessExists("cmd.exe") Then
   winactivate("Administrator: C:\Windows\System32\CMD.exe") ;refocus command prompt
EndIf

;update data
if ProcessExists("cmd.exe") Then
   winactivate("Administrator: C:\Windows\System32\CMD.exe") ;refocus command prompt
   Send("manage-bde.exe{SPACE}-protectors{SPACE}-adbackup{SPACE}c:{SPACE}")
   Send("^v")
   Send("{ENTER}")
   ;don't forget to delete temp file if you create one created.
EndIf

I put that right in the middle, thinking I could skip the message box(which does appear to be showing the correct data), but nothing is pasting in with the Send("^V") command.... 

I appreciate the suggestions and I'll think this through for a bit tonight.

Share this post


Link to post
Share on other sites
JLogan3o13

I am guessing you don't want the entire array on the clipboard, just the one line right? Instead of _ArrayClip, do something like:

Local $sFile = "%userprofile%\Desktop\protectors.txt"
Local $aFile = FileReadToArray($sFile)
Local $sInfo

For $i = 0 To UBound($aFile)
    If StringInStr($aFile[$i], "Numerical Password:") Then $sInfo = $aFile[$i + 1]
Next

if ProcessExists("cmd.exe") Then
   winactivate("Administrator: C:\Windows\System32\CMD.exe") ;refocus command prompt
EndIf

;update data
if ProcessExists("cmd.exe") Then
   winactivate("Administrator: C:\Windows\System32\CMD.exe") ;refocus command prompt
   Send("manage-bde.exe{SPACE}-protectors{SPACE}-adbackup{SPACE}c:{SPACE}")
   Send($sInfo)
   Send("{ENTER}")
   ;don't forget to delete temp file if you create one created.
EndIf

 

  • Like 1

√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
mikell

This gets the needed info

$stxt = FileRead("@desktopdir & "\protectors.txt")
$sInfo = StringRegExp($stxt, 'Numerical Password:\s*(\N+)', 1)[0] 
Msgbox(0,"", $sInfo)

 

Share this post


Link to post
Share on other sites
OMGWTFLOLBBQ
18 hours ago, JLogan3o13 said:

I am guessing you don't want the entire array on the clipboard, just the one line right? Instead of _ArrayClip, do something like:

Local $sFile = "%userprofile%\Desktop\protectors.txt"
Local $aFile = FileReadToArray($sFile)
Local $sInfo

For $i = 0 To UBound($aFile)
    If StringInStr($aFile[$i], "Numerical Password:") Then $sInfo = $aFile[$i + 1]
Next

if ProcessExists("cmd.exe") Then
   winactivate("Administrator: C:\Windows\System32\CMD.exe") ;refocus command prompt
EndIf

;update data
if ProcessExists("cmd.exe") Then
   winactivate("Administrator: C:\Windows\System32\CMD.exe") ;refocus command prompt
   Send("manage-bde.exe{SPACE}-protectors{SPACE}-adbackup{SPACE}c:{SPACE}")
   Send($sInfo)
   Send("{ENTER}")
   ;don't forget to delete temp file if you create one created.
EndIf

 

Edited the whole bit... see below.

;BitlockerUpdate
;2016.05.25

#include <AutoItConstants.au3>
#include <Array.au3>
#include <File.au3>

;definitions
Local $pro = @DesktopDir & "\Protectors.txt" ;"%userprofile%\Desktop\protectors.txt" operating txt directory
Local $act =  WinActivate("Administrator: C:\Windows\System32\CMD.exe") ;refocus command prompt
Local $bde = "manage-bde.exe{SPACE}"
Local $arr = FileReadToArray($pro)
Local $inf

;open command and enter proper directory for use
Run("C:\Windows\System32\CMD.exe") ;open command prompt
Sleep(250) ;sleep quarter second
if ProcessExists("cmd.exe") Then
   $act ;refocus command prompt
   Send("C:" & "{ENTER}") ;send code "c:" then press enter
   Send("CD{SPACE}%windir%\sysnative\" & "{ENTER}") ;send code "CD %windir%\sysnative\" then press enter
   Send($bde & "-protectors{SPACE}-get{space}c:{space}>{Space}" & $pro & "{ENTER}") ;create protectors.txt on current desktop
  ;Sleep(250) ;sleep quarter second(.25s)
EndIf

;Needs Work
For $i = 0 To UBound($arr)
    If StringInStr($arr, "Numerical Password:") Then $inf = $arr[$i + 1]
Next

;update data
if ProcessExists("cmd.exe") Then
   winactivate("Administrator: C:\Windows\System32\CMD.exe") ;refocus command prompt
   Send($bde & "-protectors{SPACE}-adbackup{SPACE}c:{SPACE}")
   Send($inf & "{ENTER}")
   ;don't forget to delete temp file if you create one created.
EndIf
;remove files
if ProcessExists("cmd.exe") Then
   winactivate("Administrator: C:\Windows\System32\CMD.exe") ;refocus command prompt
   Send("DEL{SPACE}" & $pro & "{ENTER}") ;delete protectors.txt from current desktop
EndIf
;completed & confirm message box
MsgBox(0,"Done","Copy and upload are done. Please check Computer in AD.")

When I run the code, no errors appear...but nothing is pasted in after the " Send($inf  & "{Enter}") " code is applied after collecting the info from the array. Please see the attached image.

The line that should appear is: manage-bde.exe -protectors -adbackup c: -ID {1000000-1000-1000-1000-1000000} 

{1000000-1000-1000-1000-1000000}  is the variable though, it should be pulling the information from within protectors.txt from that line. 

I appreciate what you've assisted me with creating. Is it possible to get a simple definition of what you've done?

output.PNG

Share this post


Link to post
Share on other sites
JLogan3o13

Your For Loop is incorrect. Look at how I have mine written again. You need to look at $arr[$i] in your StringInStr command, not all of $arr.


√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
AdamUL

Here is an example script with a function that will return a PC's Numerical Password without having to automate the command prompt.  This function returns an array with the Numerical Password ID and Password.  I wrote it while working on a project to harvest BitLocker Numerical Passwords from our PCs.  You could use this function to as a template for creating a function to backup protectors to AD.  

#RequireAdmin
#include <WinAPIFiles.au3>

;Turn off redirection for a 32-bit script on 64-bit system.
If @OSArch = "X64" And Not @AutoItX64 Then _WinAPI_Wow64EnableWow64FsRedirection(False)

Global $vBitLockerProtectors = _BitLockerGetNumericalPassword()
If @error Then Exit MsgBox(16, "ERROR", StringReplace($vBitLockerProtectors, "  ", @CRLF))

If IsArray($vBitLockerProtectors) Then 
    MsgBox(0, "Numerical Password", "ID: " & $vBitLockerProtectors[0] & @CRLF & "Password: " & $vBitLockerProtectors[1])
EndIf


Func _BitLockerGetNumericalPassword($sComputerName = @ComputerName, $sDrive = "C:")

    Local $sManageBdeCmd = "manage-bde -protectors -get " & $sDrive & " -cn " & $sComputerName

    Local $iPIDMangeBde = Run($sManageBdeCmd, @SystemDir, @SW_HIDE, $STDERR_MERGED)
    ProcessWaitClose($iPIDMangeBde)

    Local $sManageBdeOutput = StringStripWS(StdoutRead($iPIDMangeBde), 3)
;~  ConsoleWrite($sManageBdeOutput & @CRLF & @CRLF) ;For testing.
;~  ConsoleWrite(StringReplace($sManageBdeOutput, @CRLF, "  ") & @CRLF & @CRLF) ;For testing.

    Local $aManageBdeOutput = StringRegExp($sManageBdeOutput, "(?s)Numerical Password:.+ID:\s+{(.+)}.+Password:\s+([-0-9]+)", $STR_REGEXPARRAYGLOBALMATCH)
    If @error Then
        Local $aManageBdeOutput[2] = ["", ""]
        Local $iError = 1
        If StringInStr($sManageBdeOutput, "ERROR: No key protectors found.") Then $iError = 2 ;Fail test, PC not encrypted.
        If StringInStr($sManageBdeOutput, "ERROR: An error occurred while connecting to the BitLocker management" & @CRLF & "interface.") Then $iError = 3 ;Fail test, PC does not exist or inaccessible.
        If StringInStr($sManageBdeOutput, "ERROR: An error occurred (code 0x80070057)") Then $iError = 4 ;Fail test, drive does not exist.
        If StringInStr($sManageBdeOutput, "ERROR: An attempt to access a required resource was denied.") Then $iError = 5 ;An attempt to access a required resource was denied.
;~      Return SetError($iError, 0, $aManageBdeOutput) ;Comment the next line, and uncomment this line to get a blank array output on error.  
        Return SetError($iError, 0, StringReplace($sManageBdeOutput, @CRLF, "  ")) ;Error text returned by manage-bde.  
    EndIf
;~  _ArrayDisplay($aManageBdeOutput) ;For Testing.

    Return $aManageBdeOutput
EndFunc

If you have any questions, please let me know.  

 

Adam

 

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

  • Similar Content

    • Burgs
      By Burgs
      Greetings,
        I seem to be having a problem trying to insert values into an array in excess of the size of the array (its Ubound value).  I thought the command would simply 'ReDim' the array in order to add another value...however that does not seem to be happening.  My code is as below:
       
      ;**SET DYNAMIC ARRAY DIMENSIONS... $vValue = Int($_STRUCTURE_LEVEL - 1) ;seek the '$_HIERARCHY' level that is one 'previous' to the 'current' value...! $iStart = 0 ;set to begin search from element "0" in array... Do $_Files_Located = _Arraysearch($_HIERARCHY, $vValue, $iStart) if Int($_Files_Located) <> -1 Then $iEnd = 1 For $_RIGGING = 0 to Ubound($_LINE_DETAIL3) - 1 _ArrayInsert($_STRUCTURES, $_Files_Located + $iEnd, String($_LINE_DETAIL3[$_RIGGING])) _ArrayInsert($_HIERARCHY, $_Files_Located + $iEnd, Int($_STRUCTURE_LEVEL)) _ArrayInsert($_INFERIOR_TMPLS, $_Files_Located + $iEnd, Int(-1)) $iEnd += 1 ;increment EACH ITERATION... Next ;Next $_RIGGING EndIf ;'$_Files_Located' NOT "-1"...value for previous '$_STRUCTURE_LEVEL' ;was located in '$_HIERARCHY' array... $iStart += (Ubound($_LINE_DETAIL3) + 1) ;increment the offset index element position to begin the next search... ;"+ 1" to INCLUDE the 'parent' ('searched') UNIT...! Until $_Files_Located == -1 ;end loop when previous '$_STRUCTURE_LEVEL' is NOT found in '$_HIERARCHY' array... ;**  
        This code routine works perfectly fine except when the 'searched' value ($_Files_Located) happens to be the final element position in the searched array...how can I modify this routine so that the final additions at the end of the array(s) are made?  I thank in advance for any replies. 
       
    • nooneclose
      By nooneclose
      I forgot an important and needed aspect of my code. I need to be able to check for people who work every other week. Is it possible to write the dates that they work (every other week) between two date ranges? 
      Example:  Bob Smith has a Start date of 8-26-2018 (that is the date he is hired) And He stops working on 12-12-18 (that's the day he goes on vacation or whatever) However his work shift is every other Saturday from 7:30 AM to 6:00 Pm.  I need to calculate every other Saturday between 8-26-18 and 12-12-18 (is this clear?)
       
      here is the code I have so far. I am just missing this last part:
      ; Step 7 Func SendData() ;******************************************************************************* ; Sends all collected data to the Excel file in correct order for Upload ;******************************************************************************* MsgBox($MB_ICONINFORMATION, "Scheduler_Bot", "Sending Data", 2) ; Loop Counters $LoopCount = 0 $Array_Index = 0 $DayIndex = 0 $dataIndex = 0 ; Counter for the day of the week Local $dCount = 2 ; Counter for the numbers of Ys Local $yesCount = 0 ; Excel Write Counter (VERY IMPORTANT!) Local $EWriteCount = 2 ; Declare the global shift arrays (Sunday - Saturday) Global $ShiftDaySU[100][600] Global $ShiftDayM[100][600] Global $ShiftDayT[100][600] Global $ShiftDayW[100][600] Global $ShiftDayR[100][600] Global $ShiftDayF[100][600] Global $ShiftDayS[100][600] Global $sDates[400] While $Formatted_Names[$dataIndex] <> $Formatted_Names[$IndexRows] ; $LoopCount < $IndexRows $ACounter = 0 ; Array counter ; Gets the Start date from the array $Temp = $StartDate[$Array_Index] $TempStart = StringLeft($Temp, 8) $StartTempYear = StringLeft($TempStart, 4) $StartTempMonth = StringMid($TempStart, 5, 2) $StartTempDay = StringRight($TempStart, 2) ; Gets the End date from the array $Temp = $EndDate[$Array_Index] $TempEnd = StringLeft($Temp, 8) $EndTempYear = StringLeft($TempEnd, 4) $EndTempMonth = StringMid($TempEnd, 5, 2) $EndTempDay = StringRight($TempEnd, 2) ; The starting date (in value form) $sdate = _DateToDayValue($StartTempYear, $StartTempMonth, $StartTempDay) ;_DateToDayValue(2019,1,9) ;ConsoleWrite(@CRLF & "$start date " & $sdate & @CRLF & @CRLF) ; The ending date (in value form) $edate = _DateToDayValue($EndTempYear, $EndTempMonth, $EndTempDay) ;_DateToDayValue(2019,4,9) ;ConsoleWrite(@CRLF & "$end date " & $edate & @CRLF & @CRLF) ; Variables for readability Local $iYear, $iMonth, $iDay ;Stores what day of the week that shift lands on Local $tSU = _Excel_RangeRead($OpenWorkbook, Default, "I" & $dCount) If $tSU = "Y" Then $yesCount = 1 EndIf Local $tM = _Excel_RangeRead($OpenWorkbook, Default, "J" & $dCount) If $tM = "Y" Then $yesCount += 1 EndIf Local $tT = _Excel_RangeRead($OpenWorkbook, Default, "K" & $dCount) If $tT = "Y" Then $yesCount += 1 EndIf Local $tW = _Excel_RangeRead($OpenWorkbook, Default, "L" & $dCount) If $tW = "Y" Then $yesCount += 1 EndIf Local $tR = _Excel_RangeRead($OpenWorkbook, Default, "M" & $dCount) If $tR = "Y" Then $yesCount += 1 EndIf Local $tF = _Excel_RangeRead($OpenWorkbook, Default, "N" & $dCount) If $tF = "Y" Then $yesCount += 1 EndIf Local $tS = _Excel_RangeRead($OpenWorkbook, Default, "O" & $dCount) If $tS = "Y" Then $yesCount += 1 EndIf ConsoleWrite(@CRLF & @CRLF) ConsoleWrite($tSU & @CRLF) ConsoleWrite($tM & @CRLF) ConsoleWrite($tT & @CRLF) ConsoleWrite($tW & @CRLF) ConsoleWrite($tR & @CRLF) ConsoleWrite($tF & @CRLF) ConsoleWrite($tS & @CRLF) ConsoleWrite(@CRLF & @CRLF) ; Check to see if they work every other week Local $rotationWeek = _Excel_RangeRead($OpenWorkbook, Default, "U" & $dCount) If $rotationWeek = "0" Then ; Do nothing Else If $rotationWeek = 1 ; Do something Else ; $rotationWeek = 2 ; Do something EndIf EndIf Local $repeatWeek = _Excel_RangeRead($OpenWorkbook, Default, "V" & $dCount) If $rotationWeek = "0" Then ; Do nothing Else If $rotationWeek = 1 ; Do something Else ; $rotationWeek = 2 ; Do something EndIf EndIf While $yesCount > 0 If $tSU = "Y" Then For $Index = $sdate To $edate _DayValueToDate($Index, $iYear, $iMonth, $iDay) ; Finds the day based on its numerical value (1 = Sunday) If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 1 Then $Temp = $iYear & "-" & $iMonth & "-" & $iDay & "T" & "00" & ":" & "00" & ":" & "00" & ":" & "000" $ShiftDaySU[$ACounter][$DayIndex] = $Temp _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $ShiftDaySU[$ACounter][$DayIndex], "AI" & $EWriteCount) ; Send Name _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Formatted_Names[$dataIndex], "AA" & $EWriteCount) ; Send Start Time _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $StartTimes[$dataIndex], "AB" & $EWriteCount) ; Send End Time _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $EndTimes[$dataIndex], "AC" & $EWriteCount) ; Send Work Hours _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $HoursWorked[$dataIndex], "AD" & $EWriteCount) ; Send Work Group _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkGroup[$dataIndex], "AE" & $EWriteCount) ; Send Department _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkDepartment, "AF" & $EWriteCount) ; Send Supervisor _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Supervisors[$dataIndex], "AG" & $EWriteCount) ; Send Notes _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkNotes[$dataIndex], "AH" & $EWriteCount) ; Send Shift Number $tempStime = StringReplace($StartTimes[$dataIndex], ":", "") $tempEtime = StringReplace($EndTimes[$dataIndex], ":", "") _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, "SU " & $tempStime & "-" & $tempEtime, "AJ" & $EWriteCount) $ACounter += 1 $EWriteCount += 1 ConsoleWrite(@CRLF & "Sunday " & $Temp & @CRLF) EndIf Next $yesCount -= 1 $tSU = "N" ElseIf $tM = "Y" Then For $Index = $sdate To $edate _DayValueToDate($Index, $iYear, $iMonth, $iDay) ; Finds the day based on its numerical value (1 = Sunday) If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 2 Then $Temp = $iYear & "-" & $iMonth & "-" & $iDay & "T" & "00" & ":" & "00" & ":" & "00" & ":" & "000" $ShiftDayM[$ACounter][$DayIndex] = $Temp _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $ShiftDayM[$ACounter][$DayIndex], "AI" & $EWriteCount) ; Send Name _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Formatted_Names[$dataIndex], "AA" & $EWriteCount) ; Send Start Time _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $StartTimes[$dataIndex], "AB" & $EWriteCount) ; Send End Time _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $EndTimes[$dataIndex], "AC" & $EWriteCount) ; Send Work Hours _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $HoursWorked[$dataIndex], "AD" & $EWriteCount) ; Send Work Group _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkGroup[$dataIndex], "AE" & $EWriteCount) ; Send Department _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkDepartment, "AF" & $EWriteCount) ; Send Supervisor _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Supervisors[$dataIndex], "AG" & $EWriteCount) ; Send Notes _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkNotes[$dataIndex], "AH" & $EWriteCount) ; Send Shift Number $tempStime = StringReplace($StartTimes[$dataIndex], ":", "") $tempEtime = StringReplace($EndTimes[$dataIndex], ":", "") _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, "M " & $tempStime & "-" & $tempEtime, "AJ" & $EWriteCount) $ACounter += 1 $EWriteCount += 1 ConsoleWrite(@CRLF & "Monday " & $Temp & @CRLF) EndIf Next $yesCount -= 1 $tM = "N" ElseIf $tT = "Y" Then For $Index = $sdate To $edate _DayValueToDate($Index, $iYear, $iMonth, $iDay) ; Finds the day based on its numerical value (1 = Sunday) If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 3 Then $Temp = $iYear & "-" & $iMonth & "-" & $iDay & "T" & "00" & ":" & "00" & ":" & "00" & ":" & "000" $ShiftDayT[$ACounter][$DayIndex] = $Temp _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $ShiftDayT[$ACounter][$DayIndex], "AI" & $EWriteCount) ; Send Name _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Formatted_Names[$dataIndex], "AA" & $EWriteCount) ; Send Start Time _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $StartTimes[$dataIndex], "AB" & $EWriteCount) ; Send End Time _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $EndTimes[$dataIndex], "AC" & $EWriteCount) ; Send Work Hours _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $HoursWorked[$dataIndex], "AD" & $EWriteCount) ; Send Work Group _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkGroup[$dataIndex], "AE" & $EWriteCount) ; Send Department _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkDepartment, "AF" & $EWriteCount) ; Send Supervisor _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Supervisors[$dataIndex], "AG" & $EWriteCount) ; Send Notes _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkNotes[$dataIndex], "AH" & $EWriteCount) ; Send Shift Number $tempStime = StringReplace($StartTimes[$dataIndex], ":", "") $tempEtime = StringReplace($EndTimes[$dataIndex], ":", "") _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, "T " & $tempStime & "-" & $tempEtime, "AJ" & $EWriteCount) $ACounter += 1 $EWriteCount += 1 ConsoleWrite(@CRLF & "Tuesday " & $Temp & @CRLF) EndIf Next $yesCount -= 1 $tT = "N" ElseIf $tW = "Y" Then For $Index = $sdate To $edate _DayValueToDate($Index, $iYear, $iMonth, $iDay) ; Finds the day based on its numerical value (1 = Sunday) If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 4 Then $Temp = $iYear & "-" & $iMonth & "-" & $iDay & "T" & "00" & ":" & "00" & ":" & "00" & ":" & "000" $ShiftDayW[$ACounter][$DayIndex] = $Temp _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $ShiftDayW[$ACounter][$DayIndex], "AI" & $EWriteCount) ; Send Name _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Formatted_Names[$dataIndex], "AA" & $EWriteCount) ; Send Start Time _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $StartTimes[$dataIndex], "AB" & $EWriteCount) ; Send End Time _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $EndTimes[$dataIndex], "AC" & $EWriteCount) ; Send Work Hours _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $HoursWorked[$dataIndex], "AD" & $EWriteCount) ; Send Work Group _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkGroup[$dataIndex], "AE" & $EWriteCount) ; Send Department _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkDepartment, "AF" & $EWriteCount) ; Send Supervisor _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Supervisors[$dataIndex], "AG" & $EWriteCount) ; Send Notes _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkNotes[$dataIndex], "AH" & $EWriteCount) ; Send Shift Number $tempStime = StringReplace($StartTimes[$dataIndex], ":", "") $tempEtime = StringReplace($EndTimes[$dataIndex], ":", "") _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, "W " & $tempStime & "-" & $tempEtime, "AJ" & $EWriteCount) $ACounter += 1 $EWriteCount += 1 ConsoleWrite(@CRLF & "Wednesday " & $Temp & @CRLF) EndIf Next $yesCount -= 1 $tW = "N" ElseIf $tR = "Y" Then For $Index = $sdate To $edate _DayValueToDate($Index, $iYear, $iMonth, $iDay) ; Finds the day based on its numerical value (1 = Sunday) If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 5 Then $Temp = $iYear & "-" & $iMonth & "-" & $iDay & "T" & "00" & ":" & "00" & ":" & "00" & ":" & "000" $ShiftDayR[$ACounter][$DayIndex] = $Temp _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $ShiftDayR[$ACounter][$DayIndex], "AI" & $EWriteCount) ; Send Name _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Formatted_Names[$dataIndex], "AA" & $EWriteCount) ; Send Start Time _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $StartTimes[$dataIndex], "AB" & $EWriteCount) ; Send End Time _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $EndTimes[$dataIndex], "AC" & $EWriteCount) ; Send Work Hours _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $HoursWorked[$dataIndex], "AD" & $EWriteCount) ; Send Work Group _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkGroup[$dataIndex], "AE" & $EWriteCount) ; Send Department _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkDepartment, "AF" & $EWriteCount) ; Send Supervisor _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Supervisors[$dataIndex], "AG" & $EWriteCount) ; Send Notes _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkNotes[$dataIndex], "AH" & $EWriteCount) ; Send Shift Number $tempStime = StringReplace($StartTimes[$dataIndex], ":", "") $tempEtime = StringReplace($EndTimes[$dataIndex], ":", "") _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, "R " & $tempStime & "-" & $tempEtime, "AJ" & $EWriteCount) $ACounter += 1 $EWriteCount += 1 ConsoleWrite(@CRLF & "Thursday " & $Temp & @CRLF) EndIf Next $yesCount -= 1 $tR = "N" ElseIf $tF = "Y" Then For $Index = $sdate To $edate _DayValueToDate($Index, $iYear, $iMonth, $iDay) ; Finds the day based on its numerical value (1 = Sunday) If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 6 Then $Temp = $iYear & "-" & $iMonth & "-" & $iDay & "T" & "00" & ":" & "00" & ":" & "00" & ":" & "000" $ShiftDayF[$ACounter][$DayIndex] = $Temp _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $ShiftDayF[$ACounter][$DayIndex], "AI" & $EWriteCount) ; Send Name _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Formatted_Names[$dataIndex], "AA" & $EWriteCount) ; Send Start Time _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $StartTimes[$dataIndex], "AB" & $EWriteCount) ; Send End Time _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $EndTimes[$dataIndex], "AC" & $EWriteCount) ; Send Work Hours _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $HoursWorked[$dataIndex], "AD" & $EWriteCount) ; Send Work Group _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkGroup[$dataIndex], "AE" & $EWriteCount) ; Send Department _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkDepartment, "AF" & $EWriteCount) ; Send Supervisor _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Supervisors[$dataIndex], "AG" & $EWriteCount) ; Send Notes _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkNotes[$dataIndex], "AH" & $EWriteCount) ; Send Shift Number $tempStime = StringReplace($StartTimes[$dataIndex], ":", "") $tempEtime = StringReplace($EndTimes[$dataIndex], ":", "") _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, "F " & $tempStime & "-" & $tempEtime, "AJ" & $EWriteCount) $ACounter += 1 $EWriteCount += 1 ConsoleWrite(@CRLF & "Friday " & $Temp & @CRLF) EndIf Next $yesCount -= 1 $tF = "N" ElseIf $tS = "Y" Then For $Index = $sdate To $edate _DayValueToDate($Index, $iYear, $iMonth, $iDay) ; Finds the day based on its numerical value (1 = Sunday) If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 7 Then $Temp = $iYear & "-" & $iMonth & "-" & $iDay & "T" & "00" & ":" & "00" & ":" & "00" & ":" & "000" $ShiftDayS[$ACounter][$DayIndex] = $Temp _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $ShiftDayS[$ACounter][$DayIndex], "AI" & $EWriteCount) ; Send Name _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Formatted_Names[$dataIndex], "AA" & $EWriteCount) ; Send Start Time _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $StartTimes[$dataIndex], "AB" & $EWriteCount) ; Send End Time _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $EndTimes[$dataIndex], "AC" & $EWriteCount) ; Send Work Hours _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $HoursWorked[$dataIndex], "AD" & $EWriteCount) ; Send Work Group _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkGroup[$dataIndex], "AE" & $EWriteCount) ; Send Department _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkDepartment, "AF" & $EWriteCount) ; Send Supervisor _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Supervisors[$dataIndex], "AG" & $EWriteCount) ; Send Notes _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkNotes[$dataIndex], "AH" & $EWriteCount) ; Send Shift Number $tempStime = StringReplace($StartTimes[$dataIndex], ":", "") $tempEtime = StringReplace($EndTimes[$dataIndex], ":", "") _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, "S " & $tempStime & "-" & $tempEtime, "AJ" & $EWriteCount) $ACounter += 1 $EWriteCount += 1 ConsoleWrite(@CRLF & "Saturday " & $Temp & @CRLF) EndIf Next $yesCount -= 1 $tS = "N" Else ;Error Nothing equals "Y" ConsoleWrite(@CRLF & "Error Nothing equals 'Y'" & @CRLF) EndIf $DayIndex += 1 $LoopCount += 1 WEnd $Array_Index += 1 $dataIndex += 1 $dCount += 1 WEnd MsgBox($MB_ICONINFORMATION, "Scheduler_Bot", "Finished Sending Data", 2) EndFunc  
    • gahhon
      By gahhon
      Is there any resource/sample to generating a fancy report?
      I was downloaded this resource and try the example, but it failed to execution due to function not define. PDF
      My simple idea of generating the report would be like this:-
      Read data from excel instead of database, then generate PDF report based on my custom design.
      Any better ideas is much appreciate to share with me here
      Thanks.
    • gahhon
      By gahhon
      While Not _Login() _Login() WEnd _Initial_Check() GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE, $GUI_CLOSE_BUTTON, $BTN_EXIT _GUIDisable($GUI_MAIN, 0, 30) _Close_Application() EndSwitch WEnd ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Password_Check ; Description ...: To check against the input with the password file ; =============================================================================================================================== Func _Password_Check() Local $IN_PASSWORD = _Metro_InputBox("Please Enter Your Password:" , 11, "", True, True) If @error Then Return SetError(1, 0, "") ElseIf $PASSWORD <> $IN_PASSWORD Then Return SetError(2, 0, "Access Denied!") Else Return True EndIf EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Login ; Description ...: Login ; =============================================================================================================================== Func _Login() Local $FLAG_LOGIN = _Password_Check() If @error = 1 Then _Close_Application() ElseIf @error = 2 Then _Metro_MsgBox(0, "", $FLAG_LOGIN) Return False Else _Metro_MsgBox(0, "", "Access Granted!") Return True EndIf EndFunc When the application start, it will prompt for password for login.
      I entered several wrong password, it shows "Access Denied!" and re-prompt for password for login.
      Then I entered the correct one, it shows "Access Granted!" but it still re-prompt for password for login.
      Any idea what's wrong? Thanks
    • DarkFingers1337
      By DarkFingers1337
      Hey,
      what is more efficient, using multiple arrays or one multidimensional array?
       
      ; Hamster data structure using multiple arrays Global $HamsterCount = 6 Global $HamsterX[$HamsterCount] Global $HamsterY[$HamsterCount] ;giving each hamster an x and y position For $i=0 To $HamsterCount-1 $HamsterX[$i] = 0 $HamsterY[$i] = 0 Next ; The same hamster data structure using one multidimensional array Global $HAMSTER_COUNT = 6 Global Enum $HAMSTER_X, _ $HAMSTER_Y, _ $HAMSTER_MAX Global $Hamsters[$HAMSTER_COUNT][$HAMSTER_MAX] ;giving each hamster an x and y position For $i=0 To $HAMSTER_COUNT-1 $Hamsters[$i][$HAMSTER_X] = 0 $Hamsters[$i][$HAMSTER_Y] = 0 Next  
×