Jump to content
Sign in to follow this  
strate

Problem with windows

Recommended Posts

strate

After I run the following script the icons in my quick launch will not work and some icons in the start menu. If I try to open Windows Explorer it will say its a invalid command. Any ideas, a reboot is the only remedy

AutoItSetOption ( "SendKeyDelay" ,25)

HotKeySet("{ESC}", "USER_EXIT")
HotKeySet("^1", "Step_One")
HotKeySet("^c", "Clear_Seq")
HotKeySet("^e", "Close_Excel")
HotKeySet("^l", "Find_All_Component_Cell_Data")
HotKeySet("^p", "Purge_Previous_Found_Cells")
HotKeySet("^o", "Open_Workbook")
HotKeySet("{F1}", "Menu")

Global $Column, $Row, $IMS_Sheet_Number, $selc, $var, $excel, $oExcel,$oMyError, $FilePath,$Sleep_Time
$Sleep_Time = 25
Purge_Previous_Found_Cells()

ToolTip("IMS Automation is Active, F1 for Commands, Exit: Escape",0,0) 

$oExcel = ObjGet ($FilePath) 
If ProcessExists("Excel.EXE") Then  $excel = ObjGet("","Excel.Application")

While 1
    Sleep(25)
WEnd

;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
;|||||||||||||||||||||||||||||||||||||||||      Functions        |||||||||||||||||||||||||||||||||||||||
;\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Func Find_All_Component_Cell_Data()
;To be started after "Step_One" places in first location
    Get_Cell_Value()
    $Empty_Cell_Count = 0
    $Cells_Found = 1
    While 1
        $Row = $Row + 1
        _ExcelCOM($FilePath, $IMS_Sheet_Number,$Column, $Row, 0, 4, 0, 0)
        If $var <> "" Then
            IniWrite("C:\Trial Pull Sheet Automation.INI","Found Values","Cell"&$Cells_Found,$var)
            $oExcel = ObjGet ($FilePath)
            $oExcel.activesheet.range ($Column & $Row).Select
            $oExcel.ActiveCell.Visible = 1
            IniWrite("C:\Trial Pull Sheet Automation.INI","Found Locations","Cell"&$Cells_Found,$Excel.ActiveCell.Address)
            $Empty_Cell_Count = 0
            $Cells_Found = $Cells_Found + 1
        Else
            $Empty_Cell_Count = $Empty_Cell_Count + 1
        EndIf
        If $Empty_Cell_Count = 15 Then Return
    WEnd
EndFunc

Func Purge_Previous_Found_Cells()
;~  Dim $Cell_List[100][100]
    $Cell_List = IniReadSection ("C:\Trial Pull Sheet Automation.INI","Found Locations")
    If @error Then 
    Else
        $i = ""
        For $i = 1 To $Cell_List[0][0]
            IniDelete("C:\Trial Pull Sheet Automation.INI","Found Locations",$Cell_List[$i][0])
        Next
        $i = $i - 1
        MsgBox(4096, "", "Removed "&$i&' keys from "[Found Locations]".')
    EndIf
    $Cell_List = IniReadSection ("C:\Trial Pull Sheet Automation.INI","Found Values")
    If @error Then 
    Else
        $i = ""
        For $i = 1 To $Cell_List[0][0]
            IniDelete("C:\Trial Pull Sheet Automation.INI","Found Values",$Cell_List[$i][0])
        Next
        $i = $i - 1
        MsgBox(4096, "", "Removed "&$i&' keys from "[Found Values]".')
    EndIf
EndFunc

Func Open_Workbook()
    $INI_LF = IniRead("C:\Trial Pull Sheet Automation.INI","Steps","Last Function","")
    If $INI_LF = 1 Then
        MsgBox(0,"Error","Attempted Function was just completed.")
        Return
    EndIf
    IniWrite("C:\Trial Pull Sheet Automation.INI","Steps","Last Function",1)
    ToolTip("Current function: 1, Next Function: Ctrl+2, Exit: Escape",0,0) 
    BlockInput(0)
    $ordernum = InputBox('Kit Number?', "Enter Kit Number", '')
    If @error = 1 Then Return; pressed cancel
    BlockInput(1)
    If ProcessExists("Excel.EXE") Then
        WinActivate("Microsoft Excel","")
        WinWaitActive("Microsoft Excel","")
        $excel = ObjGet("","Excel.Application")
    Else
        $excel = Objcreate ("Excel.Application") ; open an Excel Object
        $oMyError = ObjEvent ("AutoIt.Error", "MyErrFunc"); Install a custom error handler
        If @error Then
            BlockInput(0)
            MsgBox(0, "ExcelTest 1", "Error Getting an active Excel Object. Error code: " & Hex(@error, 8))
            Exit
        EndIf
    EndIf
    $FilePath = "G:\Packaging\Process Sheets\" & $ordernum & ".xls"
    $Excel.Visible = 1
    $Excel.Workbooks.Open ($FilePath, 0, 1)
    BlockInput(0)
EndFunc


Func Step_One()
    Open_Workbook()
    Worksheet_Names()
    BlockInput(1)
    $Excel.Sheets ($IMS_Sheet_Number).Select; how to change worksheet tabs
    $Row = 1
    _ExcelCOM($FilePath, $IMS_Sheet_Number, "A", $Row, 0, 4, 0, 0)
    While 1
        $Row = $Row + 1
        _ExcelCOM($FilePath, $IMS_Sheet_Number, "A", $Row, 0, 4, 0, 0)
        If StringIsAlpha($var) And $var = "Quantity" Then
            ExitLoop
        EndIf
    WEnd
    _ExcelCOM($FilePath, $IMS_Sheet_Number, "C", $Row, 0, 0, 0, 0)
    BlockInput(0)
    $orderqty = InputBox('Quantity', "Enter Quantity")
    If @error = 1 Then Return
    BlockInput(1)
    With $oExcel
        .activesheet.range ("C" & $Row).NumberFormat = "General"
        .activesheet.range ("C" & $Row).value = $orderqty
        Send("{Right 2}")
        Send("{Down 5}")
        Get_Cell_Location()
        $Start_Column = $Column
        $Start_Row = $Row
        BlockInput(0)
;~      MsgBox(0,"Cell to paste",$Start_Column&$Start_Row)
        BlockInput(1)
        Send("{UP}")
        Find_All_Component_Cell_Data()
        .activesheet.range ($Start_Column & $Start_Row).Select
        .ActiveCell.Visible = 1
        Get_Cell_Value()
        If StringLeft($var,2) = "*p" Then
            $var = StringTrimLeft(StringTrimRight($var,1),2)
        EndIf
        Send("{LEFT 2}")
        Send("{DOWN 1}")
    EndWith
    WinActivate("VMS EB2", "")
    WinWaitActive("VMS EB2", "")
    Sleep(100)
    Send($var)
    Send("{F1 2}")
    BlockInput(0)
EndFunc  ;==>Step_One

Func Get_Cell_Location()
    $x = $Excel.ActiveCell.Address
    $loc = StringSplit($x, "$")
    $Column = $loc[2]
    $Row = $loc[3]
EndFunc

Func Get_Cell_Value()
    $x = $Excel.ActiveCell.Address
    $loc = StringSplit($x, "$")
    $Column = $loc[2]
    $Row = $loc[3]
    $var = $Excel.activesheet.range ($Column & $Row).value; grab value of current cell
EndFunc

Func _ExcelCOM($sFilePath, $Sheet, $Column, $Row, $Save, $ExcelValue, $Visible, $Exit)
    $var = ""
    $oExcel = ObjGet ($FilePath); Get an Excel Object from an existing filename
    If IsObj ($oExcel) Then
;~       with $oExcel
            $oExcel.Windows (1).Visible = 1; Set the first worksheet in the workbook visible
            $oExcel.Worksheets ($IMS_Sheet_Number).Activate
            $oExcel.ActiveSheet.Visible = 1
            $selc = $oExcel.activesheet.range ($Column & $Row).NumberFormat
            $oExcel.activesheet.range ($Column & $Row).NumberFormat = "General"
            $var = $oExcel.activesheet.range ($Column & $Row).value
            $oExcel.activesheet.range ($Column & $Row).NumberFormat = $selc
;~       EndWith
    Else
        MsgBox(0, "Excel File Test", "Error: Could not open " & $sFilePath & " as an Excel Object.")
    EndIf
    Return $var
EndFunc  ;==>_ExcelCOM

Func USER_EXIT()
    ToolTip("") 
    BlockInput(1)
    IniWrite("C:\Trial Pull Sheet Automation.INI","Steps","Last Function",0)
    If ProcessExists("EXCEL.EXE") Then
        Do
            ProcessClose("EXCEL.EXE")
        Until ProcessExists("EXCEL.EXE") = 0
    EndIf
    BlockInput(0)
    Exit
EndFunc  ;==>USER_EXIT

Func Worksheet_Names()
    $oExcel = ObjGet ($FilePath)
    if @error then 
        Msgbox (0,"ExcelTest 2","Error Getting an active Excel Object. Error code: " & hex(@error,8))
        exit
    endif
    If IsObj ($oExcel) Then
        $Number_of_Worksheets = $oExcel.Worksheets.count
        For $i = 1 To $Number_of_Worksheets
            If StringInStr($oExcel.Worksheets ($i).Name, "Pick") Then
                $IMS_Sheet_Number = $i
            EndIf
        Next
    EndIf
EndFunc  ;==>Worksheet_Names

Func MyErrFunc()
    Sleep(100)
EndFunc  ;==>MyErrFunc

Func Clear_Seq()
    IniWrite("C:\Trial Pull Sheet Automation.INI","Steps","Last Function",0)
EndFunc

Func Close_Excel()
    BlockInput(1)
    IniWrite("C:\Trial Pull Sheet Automation.INI","Steps","Last Function",0)
    If ProcessExists("EXCEL.EXE") Then
        Do
            ProcessClose("EXCEL.EXE")
        Until ProcessExists("EXCEL.EXE") = 0
    EndIf
    BlockInput(0)
EndFunc

Func Menu()
    If WinExists("Help","") Then
        SplashOff()
    Else
        SplashTextOn("Help","ESC - Exit program in full."&@CR&"Ctrl+1 - Start Step One"&@CR&"Ctrl+C - Clear Sequence File"&@CR&"Ctrl+E - Close Excel Only"&@CR&"Ctrl+O - Open new workbook"&@CR&"F1 - Exit Help",250,125)
    EndIf
EndFunc

It doesn't do it every time though.


INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites
jefhal

Any ideas, a reboot is the only remedy

Is it wise to use hotkeys that overlap Window's hotkeys? (CTRL-C, F1, CTRL-P)

Also, you might want to compare processes that are running before you launch your code and after, as well as when you think you are done. Perhaps you are leaving a process open?

I think that the taskbar is a part of Explorer.exe. If you bumped into it, that would explain the error. I just read an article today (forgot the source) that explains how to restart explorer without a reboot. That might determine if Explorer is indeed broken...

Edited by jefhal

...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format

Share this post


Link to post
Share on other sites
strate

Excel 2003

Windows 2000 SP 4

AutoIt Beta 3.1.1.56

I'm not sure about the overlapping of the hotkeys.


INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites
t0ddie

just typing explorer in the run box will run explorer. heh


Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites
GaryFrost

if your going to use beta, need to keep up with it also, currently at .59


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites
rakeshranjan1985

I am also facing a problem similar to this. After the script completes, if i press L, the system gets locked; if i press r, the Run window opens; if i press e, the windows-explorer opens. These things probably happen because WINDOWS+L, WINDOWS+r, WINDOWS+e,... are the short-cut keys. I have used a script which right-clicks an icon in the taskbar and then opens the window corresponding to that. and then clicks a button on it. Finally i am locking the system using WINDOWS+l.

#include "SysTray_UDF.au3"

; -- Example 5 --
; Left-click Outlook's icon on system tray
    
; Press hide inactive icon's button part is from Valik's refresh system tray script!
    $oldMatchMode = Opt("WinTitleMatchMode", 4)
    $oldChildMode = Opt("WinSearchChildren", 1)
    
    $class = "classname=Shell_TrayWnd"
    $hControl = ControlGetHandle($class, "", "Button2")
    
; get tray position and move there. Helps if Auto Hide tray option is used.
    $posTray = WinGetPos(_FindTrayToolbarWindow())
    MouseMove($posTray[0], $posTray[1])
    
; If XP and the Hide Inactive Icons mode is active
    If $hControl <> "" And ControlCommand($class, "", $hControl, "IsVisible","") Then
        ControlClick($class, "", $hControl)
        Sleep(250); Small delay to allow the icons to be drawn
    EndIf
    
    $index = _SysTrayIconIndex("myfile.exe"); Change this to some other application if needed;
    If $index <> -1 Then
        $pos = _SysTrayIconPos($index)
        
        If $pos = -1 Then Exit
        MouseMove($pos[0], $pos[1])
        Sleep(1000)
        MouseClick("right")  ;this right-clicks on the desired icon in the system-tray
    EndIf
    ConsoleWrite(@CRLF & "Pos[0]: " & $pos[0] & @TAB & "Pos[1]: " & $pos[1] & @CRLF)
; Restore Opt settings
    Opt("WinTitleMatchMode", $oldMatchMode)
    Opt("WinSearchChildren", $oldChildMode)

Send("o");'o' is for 'open' menu-item. this opens a window titled say "window-title"

$WinActivate = WinActivate( "window-title" )
$WinWaitActive = WinWaitActive( "window-title" )
MouseMove( 800, 720 )
MouseClick( "left" );i left-click on a button on the "window-title". 
;After this a window titled "Windows Internet Explorer" should appear on which i press a button(controlID=1)

WinActivate( "Windows Internet Explorer" )
WinWaitActive( "Windows Internet Explorer" )
ControlClick( "Windows Internet Explorer", "", 1 )

;Now i want to lock the system using WINDOWS+l
Send( "#l" )

Exit

Jefhal, can you please explain how to restart explorer without a reboot or am i leaving a process open in this code? As you can see, i am not using any hotkeys which overlap window's hotkeys. Any help from a knowledgable person would be appreciated.

Edited by rakeshranjan1985

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  

×