Sign in to follow this  
Followers 0
autosc

Drive-Lock script modified

10 posts in this topic

This script works only if i comment out the following functions

#include <Misc.au3>

#include <string.au3>

#include <Array.au3>

But i need this functions to modify the script . Whay is happening ?

#include <Misc.au3>
#include <string.au3>

#include <Array.au3>



Opt("WinTitleMatchMode", 4)


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

$hwnd = WinGetHandle("classname=Progman")
$user32 = DllOpen("user32.dll")
Global Const $lciWM_SYSCommand = 274
Global Const $lciSC_MonitorPower = 61808
Global Const $lciPower_Off = 2
Global Const $lciPower_On = -1

$last = WinGetHandle("active")
Global Const $WS_POPUP = 0x80000000
Global Const $WS_EX_TOOLWINDOW = 0x00000080
$gui = GUICreate("", 1, 1, -2, -2, $WS_POPUP, $WS_EX_TOOLWINDOW)
GUISetBkColor(0, $gui)
WinSetOnTop($gui, "", 1)
GUISetState()
WinActivate($last)

$drive = StringLeft(@ScriptFullPath, 2) & "\"
$code = _DriveInfo($drive)
While 1
   While FileExists(@ScriptFullPath)
      Sleep(50)
   WEnd
   ProcessClose("taskmgr.exe")
   $pid = Run("taskmgr.exe", @SystemDir, @SW_HIDE)
   WinMove($gui, "", -2, -2, @DesktopWidth + 4, @DesktopHeight + 4)
   While not ( _DriveInfo($drive) = $code )
      While not FileExists(@ScriptFullPath)
         WinActivate($gui)
         DllCall($user32, "int", "SendMessage", "hwnd", $hwnd, "int", $lciWM_SYSCommand, "int", $lciSC_MonitorPower, "int", $lciPower_Off)
         BlockInput(1)
         Sleep(20)
      WEnd
   WEnd
   WinMove($gui, "", -2, -2, 1, 1)
   ProcessClose($pid)
   DllCall($user32, "int", "SendMessage", "hwnd", $hwnd, "int", $lciWM_SYSCommand, "int", $lciSC_MonitorPower, "int", $lciPower_On)
   BlockInput(0)
WEnd

Func _DriveInfo( $drv )
   Return DriveGetFileSystem($drv)&DriveGetLabel($drv)&DriveGetSerial($drv)&DriveGetType($drv)&DriveSpaceTotal($drv)&DriveStatus($drv)&FileGetSize(@ScriptFullPath)
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

do you have the terminate function defined?

try this-

#include <Misc.au3>
#include <string.au3>

#include <Array.au3>



Opt("WinTitleMatchMode", 4)


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

$hwnd = WinGetHandle("classname=Progman")
$user32 = DllOpen("user32.dll")
Global Const $lciWM_SYSCommand = 274
Global Const $lciSC_MonitorPower = 61808
Global Const $lciPower_Off = 2
Global Const $lciPower_On = -1

$last = WinGetHandle("active")
Global Const $WS_POPUP = 0x80000000
Global Const $WS_EX_TOOLWINDOW = 0x00000080
$gui = GUICreate("", 1, 1, -2, -2, $WS_POPUP, $WS_EX_TOOLWINDOW)
GUISetBkColor(0, $gui)
WinSetOnTop($gui, "", 1)
GUISetState()
WinActivate($last)

$drive = StringLeft(@ScriptFullPath, 2) & "\"
$code = _DriveInfo($drive)
While 1
   While FileExists(@ScriptFullPath)
      Sleep(50)
   WEnd
   ProcessClose("taskmgr.exe")
   $pid = Run("taskmgr.exe", @SystemDir, @SW_HIDE)
   WinMove($gui, "", -2, -2, @DesktopWidth + 4, @DesktopHeight + 4)
   While not ( _DriveInfo($drive) = $code )
      While not FileExists(@ScriptFullPath)
         WinActivate($gui)
         DllCall($user32, "int", "SendMessage", "hwnd", $hwnd, "int", $lciWM_SYSCommand, "int", $lciSC_MonitorPower, "int", $lciPower_Off)
         BlockInput(1)
         Sleep(20)
      WEnd
   WEnd
   WinMove($gui, "", -2, -2, 1, 1)
   ProcessClose($pid)
   DllCall($user32, "int", "SendMessage", "hwnd", $hwnd, "int", $lciWM_SYSCommand, "int", $lciSC_MonitorPower, "int", $lciPower_On)
   BlockInput(0)
WEnd

Func _DriveInfo( $drv )
   Return DriveGetFileSystem($drv)&DriveGetLabel($drv)&DriveGetSerial($drv)&DriveGetType($drv)&DriveSpaceTotal($drv)&DriveStatus($drv)&FileGetSize(@ScriptFullPath)
EndFunc
func Terminate()
    Exit
EndFunc
Edited by evilertoaster

Share this post


Link to post
Share on other sites

do you have the terminate function defined?

try this-

#include <Misc.au3>
#include <string.au3>

#include <Array.au3>
Opt("WinTitleMatchMode", 4)
HotKeySet("{ESC}", "Terminate")

$hwnd = WinGetHandle("classname=Progman")
$user32 = DllOpen("user32.dll")
Global Const $lciWM_SYSCommand = 274
Global Const $lciSC_MonitorPower = 61808
Global Const $lciPower_Off = 2
Global Const $lciPower_On = -1

$last = WinGetHandle("active")
Global Const $WS_POPUP = 0x80000000
Global Const $WS_EX_TOOLWINDOW = 0x00000080
$gui = GUICreate("", 1, 1, -2, -2, $WS_POPUP, $WS_EX_TOOLWINDOW)
GUISetBkColor(0, $gui)
WinSetOnTop($gui, "", 1)
GUISetState()
WinActivate($last)

$drive = StringLeft(@ScriptFullPath, 2) & "\"
$code = _DriveInfo($drive)
While 1
   While FileExists(@ScriptFullPath)
      Sleep(50)
   WEnd
   ProcessClose("taskmgr.exe")
   $pid = Run("taskmgr.exe", @SystemDir, @SW_HIDE)
   WinMove($gui, "", -2, -2, @DesktopWidth + 4, @DesktopHeight + 4)
   While not ( _DriveInfo($drive) = $code )
      While not FileExists(@ScriptFullPath)
         WinActivate($gui)
         DllCall($user32, "int", "SendMessage", "hwnd", $hwnd, "int", $lciWM_SYSCommand, "int", $lciSC_MonitorPower, "int", $lciPower_Off)
         BlockInput(1)
         Sleep(20)
      WEnd
   WEnd
   WinMove($gui, "", -2, -2, 1, 1)
   ProcessClose($pid)
   DllCall($user32, "int", "SendMessage", "hwnd", $hwnd, "int", $lciWM_SYSCommand, "int", $lciSC_MonitorPower, "int", $lciPower_On)
   BlockInput(0)
WEnd

Func _DriveInfo( $drv )
   Return DriveGetFileSystem($drv)&DriveGetLabel($drv)&DriveGetSerial($drv)&DriveGetType($drv)&DriveSpaceTotal($drv)&DriveStatus($drv)&FileGetSize(@ScriptFullPath)
EndFunc
func Terminate()
    Exit
EndFunc

the script is referring to line 21 .. (Can not redeclare a constant.:

my defined svript works separately with the functions

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

line 21 is GUISetState() and does not declare any variable. Are you sure it is in this script file that the error is happening. I can run the problem without the error (although i don't know what it does). Is there some other part to it you didn't post?

Edited by evilertoaster

Share this post


Link to post
Share on other sites

line 21 is GUISetState() and does not declare any variable. Are you sure it is in this script file that the error is happening. I can run the problem without the error (although i don't know what it does). Is there some other part to it you didn't post?

if i comment out the functions on top works the script .

otherwise getting an error . That is the strange what i dont grasp ?

Share this post


Link to post
Share on other sites

if i comment out the functions on top works the script .

otherwise getting an error . That is the strange what i dont grasp ?

You already said that... how bout if you post a screen shot of the error when it happens...

Share this post


Link to post
Share on other sites

You already said that... how bout if you post a screen shot of the error when it happens...

here is output from Scite --- latest version

>"C:\Program\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "F:\drive-lock2.au3" /autoit3dir "C:\Program\AutoIt3" /UserParams 
+>23:27:24 Starting AutoIt3Wrapper v.1.9.1
>Running AU3Check (1.54.7.0)  from:C:\Program\AutoIt3
F:\drive-lock2.au3(21,36) : ERROR: $WS_POPUP previously declared as a 'Const'
Global Const $WS_POPUP = 0x80000000
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
F:\drive-lock2.au3(22,44) : ERROR: $WS_EX_TOOLWINDOW previously declared as a 'Const'
Global Const $WS_EX_TOOLWINDOW = 0x00000080
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
F:\drive-lock2.au3 - 2 error(s), 0 warning(s)
!>23:27:25 AU3Check ended.rc:2
>Running:(3.2.4.9):C:\Program\AutoIt3\autoit3.exe "F:\drive-lock2.au3"  
F:\drive-lock2.au3 (21) : ==> Can not redeclare a constant.: 
Global Const $WS_POPUP = 0x80000000 
Global Const ^ ERROR
->23:27:32 AutoIT3.exe ended.rc:1
+>23:27:33 AutoIt3Wrapper Finished
>Exit code: 1   Time: 9.596

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

the script is referring to line 21 .. (Can not redeclare a constant.:

my defined svript works separately with the functions

Just rename the offending constant in your script. Somewhere in one of those include files a matching name is used. I'd bet on Array.au3, because it includes GuiConstants.au3, which in turn loads a dozen others.

You could test for the condition with IsDeclared(), but that brings its own ugliness in Assign() and Eval(). The best thing is to simply pick a different name.

:rolleyes:

Edit: You posted while I was. Specifically rename $WS_POPUP and $WS_EX_TOOLwindow. Those are style constants used in AutoIt, and definitely included in GuiConstants.au3 (which is in Array.au3 for support of _ArrayDisplay()).

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Just rename the offending constant in your script. Somewhere in one of those include files a matching name is used. I'd bet on Array.au3, because it includes GuiConstants.au3, which in turn loads a dozen others.

You could test for the condition with IsDeclared(), but that brings its own ugliness in Assign() and Eval(). The best thing is to simply pick a different name.

:rolleyes:

Edit: You posted while I was. Specifically rename $WS_POPUP and $WS_EX_TOOLwindow. Those are style constants used in AutoIt, and definitely included in GuiConstants.au3 (which is in Array.au3 for support of _ArrayDisplay()).

Psalty ! Good lesson ! thanks . Fixed.

Share this post


Link to post
Share on other sites

Psalty ! Good lesson ! thanks . Fixed.

As usual, I did kind of overlook the simplest solution. :rolleyes:

Delete your declarations completely and #include <GuiConstants.au3> for yourself if you want to use those constants. Then you wouldn't even have to change the references to $WS_POPUP, etc. in your script.

There is no harm in including something a second time. The #include-once statement at the top of the UDFs prevents the same code from being repeated even if something else includes the same thing.

I should have said that from the start, but I'm getting old...

:rambo:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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