Sign in to follow this  
Followers 0
triodz

Calling several functions and help with simple progress bar, please

7 posts in this topic

Firstly, please let me apologise for the huge block of code, but it's so you can see what I am trying to do.

Code here:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <progressconstants.au3>
#include <GuiStatusBar.au3>
#Include <File.au3>
#Include <Array.au3>
#include <Constants.au3>
;INITIAL FORM
$Form1_1 = GUICreate("Form1", 396, 181, 192, 114)
GUISetBkColor(0xA6CAF0)
$Label3 = GUICtrlCreateLabel("Enter Users ADM Number", 38, 17, 126, 17)
$useradm = GUICtrlCreateInput("EG: ADM1234", 185, 14, 177, 21)
$useradm2 = GUICtrlRead($useradm)
$Label4 = GUICtrlCreateLabel("Enter Users PC Number", 45, 61, 116, 17)
$userpc = GUICtrlCreateInput("EG: PCH1234", 186, 55, 177, 21)
$userpc2 = GUICtrlRead($userpc)
$MyButton1 = GUICtrlCreateButton("COPY!", 224, 96, 100, 30, BitOR($BS_NOTIFY,$BS_FLAT))
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0x00FF00)
GUICtrlSetOnEvent($MyButton1, "rename")  ;CALLS FIRST FUNCTION
$MyButton2 = GUICtrlCreateButton("EXIT", 40, 96, 100, 30, BitOR($BS_NOTIFY,$BS_FLAT))
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xFF0000)
GUICtrlSetOnEvent($MyButton2, "cancel")  ;CLOSES GUI
GUISetState(@SW_SHOW)
OPT("GUIOnEventMode",1)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
EndSwitch
WEnd
  ;RENAMES USERS PROFILE FOLDER
func rename ()
$owner = @Username
$userpc2 = GUICtrlRead($userpc)
$useradm2 = GUICtrlRead($useradm)
  call("progress1")  ;CALLS PROGRESS BAR
run("\\server\filepath\Admin Support.bat")
sleep(500)
WinSetState("cmd /k net use x: \\server\filepath && x: (running as domain\"&$owner&"_a)","",@SW_RESTORE)
sleep(1000)
ControlSend("cmd /k net use x: \\server\filepath&& x: (running as domain\"&$owner&"_a)","","","title Administrator")
ControlSend("cmd /k net use x: \\server\filepath && x: (running as domain\"&$owner&"_a)","","","{enter}")
sleep(1000)
ControlSend("Administrator","","","psexec \\"&$userpc2&": cmd","","","cd\")
ControlSend("\\"&$userpc2&": cmd","","","cd ""documents and settings""")
ControlSend("\\"&$userpc2&": cmd","","","rename "&$useradm2&" old."&$useradm2&"")
ControlSend("\\"&$userpc2&": cmd")
  while 1
   if FileExists ("\\"&$userpc2&"\c$\Documents and Settings\old."&$useradm2&"") Then
    Call("end1")  ;CALLS END OF PROGRESS BAR
   EndIf
   sleep(100)
  WEnd
EndFunc
Func progress1 ()
$g = GUICreate("test",200,50,-1,-1,$WS_POPUP)
global $l = GUICtrlCreateLabel("Running", 20, 35, 120, 21)
GUISetBkColor(0x00BFFF)
GUISetState()
global $progress = GUICtrlCreateProgress(0, 0, 200, 30, $PBS_MARQUEE)
_SendMessage(GUICtrlGetHandle($progress), $PBM_SETMARQUEE, 1, 200)
GUICtrlSetData($l, "Renaming profile...")
EndFunc
Func end1 ()
global $l = GUICtrlCreateLabel("Running", 20, 35, 120, 21)
global $progress = GUICtrlCreateProgress(0, 0, 200, 30, $PBS_MARQUEE)
GUICtrlSetData($l, "All done!")
guictrlDelete($progress)
Sleep(300)
call("gogogo")  ;CALLS ANOTHER GUI SCREEN
Exit  ;;;; I KNOW THIS SHOULD NOT BE HERE, BUT WHAT INSTEAD??
EndFunc
Func gogogo () ;THIS FORM APPEARS, BUT CANNOT START. ALSO, HOW TO MAKE IT DISAPPEAR WHEN OK IS PRESSED?
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

$Form1 = GUICreate("Form1", 309, 138, 192, 114)
$Label1 = GUICtrlCreateLabel("When the user has signed back", 8, 8, 294, 26)
  GUICtrlSetFont(-1, 14, 800, 0, "Arial")
  GUICtrlSetColor(-1, 0xFF0000)
$Label2 = GUICtrlCreateLabel("on, click OK!", 96, 40, 120, 26)
  GUICtrlSetFont(-1, 14, 800, 0, "Arial")
  GUICtrlSetColor(-1, 0xFF0000)
$GoGoGo = GUICtrlCreateButton("OK", 104, 88, 100, 30, BitOR($BS_NOTIFY,$BS_FLAT))
  GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
  GUICtrlSetColor(-1, 0x00FF00)
  GUICtrlSetBkColor(-1, 0x008000)
  GUICtrlSetOnEvent($GoGoGo, "start")  ;CALLS START FUNCTION. ANYTHING ELSE TO CLOSE THE WINDOW?
GUISetState(@SW_SHOW)
OPT("GUIOnEventMode",1)
EndFunc
Func start ()   ; COPIES A SMALL FILE TO USERS PC. COPIES FILES DIRECTLY ON THE PC REDUCING COPY TIME.CHECKS THAT ALL FILES MATCH.
$owner = @Username
$userpc2 = GUICtrlRead($userpc)
$useradm2 = GUICtrlRead($useradm)
  call("progress2")  ;;;;; CALLS NEW PROGRESS BAR. IS THIS EVEN NEEDED??
  $sig = _FileListToArray("\\"&$userpc2&"\c$\Documents and Settings\"&$useradm2&"\Application Data\Microsoft\Signatures","*")
   _FileWriteFromArray("c:\sig.log",$sig)
   _FileCountLines("c\sig.log")
   sleep(1000)
  $nk2 = _FileListToArray("\\"&$userpc2&"\c$\Documents and Settings\"&$useradm2&"\Application Data\Microsoft\Outlook","*")
   _FileWriteFromArray("c:\nk2.log",$nk2)
   _FileCountLines("c\nk2.log")
   sleep(1000)
  $desk = _FileListToArray("\\"&$userpc2&"\c$\Documents and Settings\"&$useradm2&"\Desktop","*")
   _FileWriteFromArray("c:\desk.log",$desk)
   _FileCountLines("c\desk.log")
   sleep(1000)
IniWrite("c:\copy.ini","ID","useradm",$useradm2)
run("\\server\filepath\Admin Support.bat")
sleep(100)
WinSetState("cmd /k net use x: \\server\filepath && x: (running as domain\"&$owner&"_a)","",@SW_HIDE)
sleep(1000)
ControlSend("cmd /k net use x: \\server\filepath && x: (running as domain\"&$owner&"_a)","","","title Administrator")
ControlSend("cmd /k net use x: \\server\filepath && x: (running as domain\"&$owner&"_a)","","","{enter}")
sleep(4000)
controlSend("Administrator","","","xcopy ""\\server\filepath\Nothing to see here\profilecopy.exe"" \\"&$userpc2&"\c$")
controlSend("Administrator","","","{enter}")
sleep(500)
controlSend("Administrator","","","y")
controlSend("Administrator","","","{enter}")
sleep(500)
controlSend("Administrator","","","xcopy ""c:\copy.ini"" \\"&$userpc2&"\c$")
controlSend("Administrator","","","{enter}")
sleep(500)
controlSend("Administrator","","","y")
controlSend("Administrator","","","{enter}")
sleep(500)
controlSend("Administrator","","","start \\"&$userpc2&"\c$\profilecopy.exe")
controlSend("Administrator","","","{enter}")
  while 1
   $readsig = fileopen("c:\sig.log",0)
   $linesig = FileReadLine($readsig,1)
   $readnk2 = fileopen("c:\nk2.log",0)
   $linenk2 = FileReadLine($readnk2,1)
   $readdesk = fileopen("c:\desk.log",0)
   $linedesk = FileReadLine($readdesk,1)
    $sig2 = _FileListToArray("\\"&$userpc2&"\c$\Documents and Settings\"&$useradm2&"\Application Data\Microsoft\Signatures","*")
    _FileWriteFromArray("c:\sig2.log",$sig2)
    _FileCountLines("c\sig2.log")
    sleep(100)
    $readsig2 = fileopen("c:\sig2.log",0)
    $linesig2 = FileReadLine($readsig2,1)
     $nk22 = _FileListToArray("\\"&$userpc2&"\c$\Documents and Settings\"&$useradm2&"\Application Data\Microsoft\Outlook","*")
     _FileWriteFromArray("c:\nk22.log",$nk22)
     _FileCountLines("c\nk22.log")
     sleep(100)
     $readnk22 = fileopen("c:\nk22.log",0)
     $linenk22 = FileReadLine($readnk22,1)
      $desk2 = _FileListToArray("\\"&$userpc2&"\c$\Documents and Settings\"&$useradm2&"\Desktop","*")
      _FileWriteFromArray("c:\desk2.log",$desk2)
       _FileCountLines("c\desk2.log")
      sleep(100)
      $readdesk2 = fileopen("c:\desk2.log",0)
      $linedesk2 = FileReadLine($readdesk2,1)
    if $linesig = $linesig2 And $linenk2 = $linenk22 And $linedesk = $linedesk2 Then
     call("end2")  ;CALLS END TO SECOND PROGRESS BAR
    EndIf
   WEnd
endfunc
Func progress2 ()
$g = GUICreate("test",200,50,-1,-1,$WS_POPUP)
global $l = GUICtrlCreateLabel("Running", 20, 35, 120, 21)
GUISetBkColor(0x00BFFF)
GUISetState()
global $progress = GUICtrlCreateProgress(0, 0, 200, 30, $PBS_MARQUEE)
_SendMessage(GUICtrlGetHandle($progress), $PBM_SETMARQUEE, 1, 200)
GUICtrlSetData($l, "Copying Files...")
EndFunc
Func end2 ()
global $l = GUICtrlCreateLabel("Running", 20, 35, 120, 21)
global $progress = GUICtrlCreateProgress(0, 0, 200, 30, $PBS_MARQUEE)
GUICtrlSetData($l, "All done!")
guictrlDelete($progress)
Sleep(300)
call("cancel")  ;;CALLS ENDING FUNCTION
exit
EndFunc
Func cancel ()  ;CLEARS OUT FILES NOT NEEDED ANYMORE AND ENDS
$userpc2 = GUICtrlRead($userpc)
$useradm2 = GUICtrlRead($useradm)
FileDelete("c:\sig.log")
FileDelete("c:\nk2.log")
FileDelete("c:\desk.log")
FileDelete("c:\sig2.log")
FileDelete("c:\nk22.log")
FileDelete("c:\desk2.log")
FileDelete("c:\copy.ini")
FileDelete("\\"&$userpc2&"\c$\profilecopy.exe")
FileDelete("\\"&$userpc2&"\c$\copy.ini")
global $l = GUICtrlCreateLabel("Running", 20, 35, 120, 21)
global $progress = GUICtrlCreateProgress(0, 0, 200, 30, $PBS_MARQUEE)
GUICtrlSetData($l, "All done!")
guictrlDelete($progress)
Sleep(300)
MsgBox(0,"Fo' Shizzle!","All copied. And remember: You're Awesome!")
Exit
EndFunc

I have put notes inside the code to try and make it easier.

It runs through the first "rename" function fine (rename the users profile folder), then opens the "gogogo" form, but I can't click on the start button. It just does nothing. I am also trying to figure out how to close this window.

I have noted that the "Exit" in the "end1" function should not be there, but what should be there instead? The progress bar just stays open.

I get the feeling this is why it is not going anywhere - because a function is still open. But I don't know how to end it without ending the whole script?

On their own, these functions work perfectly. I have done a piece at a time, then put it all together, It is also my first large continuous piece.

Thank you so much for any help!!

Share this post


Link to post
Share on other sites



Your code is a big mess:

- #include statements inside functions (or anywhere else in the code but at the begining) - big NO-NO

- mixed GUIOnEventMode with $msg; decide which way to go and stick to that for the whole script (GUIOnEventMode should be at the beging too)

When you have multiple GUIs - the best practice is to use GUISwitch

When you want to close a GUI (not your main one) use GUIDelete

I am not attempting to debug your code. The best for you is to start cleaning up your code.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

*sigh*

Thanks enaiman. I will have a go. I tried guidelete in end1 with no luck. The bar just keeps scrolling.

Guess I have more to learn than I thought.

Share this post


Link to post
Share on other sites

Maybe you didn't specify the correct handle for the GUI you were trying to delete?


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Sorry to take so long to answer enaiman. I have been furiously learning and correcting everything and it is now working. You were right, obviously, about the correct handle!

The script is to assist us in renaming a profile and copying files across that are not kept on servers - nk2 file (what outlook uses to store those email addresses you have previously typed in the "To" field), signatures folder and desktop items.

Sometimes things are forgotten, so this will assist with minimizing that.

I thought I would post all the code that I have done in case it can help anyone else. I don't often get to contribute, so here's my chance!

What it does in a nutshell:

  • Opens GUI, asks for username and PC number
  • Opens a "Killswitch" GUI that can be used to kill the script at any point.
  • Checks that PC is online and the Users folder exists.
  • Checks that the folders requested to be copied are there and adjusts itself accordingly
  • Notes the number of files in each folder
  • Renames the folder
  • Copies a file to the remote machine to do the copying locally (faster)
  • Checks each folder being copied and compares to earlier checks to make sure they have all been copied
  • Cleans up any files created and exits.
EDIT: Code is too large to post. Tried to upload, but our proxy is not playing. Will try later.

Thanks for being such a great community!

EDIT: Yay! Used the simple uploader instead. Here ya go:

MAIN CODE:

Rename copy.au3

KILLSWITCH CODE:

killswitch.au3

FILE TO COPY TO REMOTE MACHINE:

profilecopy.au3

Any criticism is welcome, and I hope this helps a newbie one day!

EDIT:

Main code updated to create a random 4 letter mix instead of "old." in case old.username already exists.

File to copy to machine updated to know what to put before the renamed profile

Killswitch updated as I found it would not kill the rename progress bar. It does now.

Edited by triodz

Share this post


Link to post
Share on other sites

I'm glad you figured it out. You weren't afraid of debugging your script and you were willing to learn; I respect that :)


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

And I'm glad that there are people such as yourself kind enough to donate time to helping where you can. It's not like you guys get paid or anything! I totally respect that. :)

Also, I just noticed that you are a neighbor! Well, close anyways. I'm in Bendigo, Vic. I'll chuck a paper plane and see if it reaches 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