ฟอรั่ม PSsix

Would you like to react to this message? Create an account in a few clicks or log in to continue.

ฟอรั่มของบล็อก http://pssix.blogspot.com


+7
Timekeeper
asokura
Fast
Arm
POS
aut
Monaliza
11 posters

    Script ตรวจจับ FlashDrive

    Monaliza
    Monaliza
    PSsix Member Super Class III
    PSsix Member Super Class III


    PSsix Program Coder
    จำนวนข้อความ : 213
    ความนิยม : 7
    เข้าร่วมเมื่อ : 03/10/2010

    Script ตรวจจับ FlashDrive Empty Script ตรวจจับ FlashDrive

    ตั้งหัวข้อ by Monaliza 30/09/11, 07:17 pm

    แนวคิดต้องการทำโปรแกรมBlockการใช้งานFlashDrive


    แก้ไขล่าสุดโดย Monaliza เมื่อ 01/10/11, 01:52 am, ทั้งหมด 1 ครั้ง
    aut
    aut
    PSsix Powerful Scripting Class
    PSsix Powerful Scripting Class


    PSsix Game Coder
    จำนวนข้อความ : 472
    ความนิยม : 126
    เข้าร่วมเมื่อ : 24/07/2010

    Script ตรวจจับ FlashDrive Empty Re: Script ตรวจจับ FlashDrive

    ตั้งหัวข้อ by aut 30/09/11, 08:15 pm

    จัดปาย ชินจัง สคิปอื่นก้อมีนะดูนี่เลย [You must be registered and logged in to see this link.]

    $strComputer = "."
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")

    $colEvents = $objWMIService.ExecNotificationQuery _
    ("Select * From __InstanceOperationEvent Within 5 Where " _
    & "TargetInstance isa 'Win32_LogicalDisk'")

    While 1
    $objEvent = $colEvents.NextEvent
    If $objEvent.TargetInstance.DriveType = 2 Then
    Select
    Case $objEvent.Path_.Class()="__InstanceCreationEvent"
    Consolewrite("Drive " & $objEvent.TargetInstance.DeviceId & "has been added." & @CR)
    Case $objEvent.Path_.Class()="__InstanceDeletionEvent"
    Consolewrite("Drive " & $objEvent.TargetInstance.DeviceId & "has been removed."& @CR)
    EndSelect
    EndIf
    WEnd
    Monaliza
    Monaliza
    PSsix Member Super Class III
    PSsix Member Super Class III


    PSsix Program Coder
    จำนวนข้อความ : 213
    ความนิยม : 7
    เข้าร่วมเมื่อ : 03/10/2010

    Script ตรวจจับ FlashDrive Empty Re: Script ตรวจจับ FlashDrive

    ตั้งหัวข้อ by Monaliza 01/10/11, 01:59 am

    คือที่ต้องการทำคือ คอยตรวจสอบ ว่ามีใครเอา flashDrive มาเสียบหรือไม่ถ้าตรวจเจอ
    ให้Block คียร์บอดร์และเมาส์ แล้วแสดงข้อความเตือนว่าถ้าต้องการใช้งานคอมพิวเตอร์เครื่องนี้ต่อให้ถอด FlashDrive ออก ถ้าไม่เจอให้วนตรวจสอบต่อไปเรื่อย ๆ
    $var = DriveGetDrive("REMOVABLE")
    If @error Then
    exit
    Else
    For $i = 1 To $var[0]
    If $var[$i] <> "a:" And DriveStatus("READY") Then
    BlockInput(1)
    Else
    BlockInPut(0)
    EndIf
    Next
    EndIf
    WEnd
    ผมลองดูแล้ว script มันไม่ยอมทำงาน
    ต้อง
    $var = DriveGetDrive("REMOVABLE")
    If @error Then
    exit
    Else
    For $i = 1 To $var[0]
    If $var[$i] <> "a:" And DriveStatus("READY") Then
    BlockInput(1)
    ElseIf Not $var[$i] <> "a:" And DriveStatus("READY") Then
    BlockInput(0)
    Else
    sleep(100)
    EndIf
    Next
    EndIf
    WEnd
    มันถึงจะทำงาน รันscript ทิ้งไว้แล้วเสียบ flashdrivr มันจะblock คีย์บอดร์และเมาส์
    แต่เวลาถอดออกมันเหมือนคำสั่งBlockInput(0)
    มันไม่ทำงาน
    ต้องกดปุ่ม Ctrl+Shift+Alt ให้ขึ้นหน้าตัวเลือก windows แล้วกดcancle กลับมาหน้าปกติถึงจะใช้ได้เหมือนเดิม
    POS
    POS
    PSsix
    PSsix


    Script ตรวจจับ FlashDrive Empty Script ตรวจจับ FlashDrive Empty Script ตรวจจับ FlashDrive Empty
    จำนวนข้อความ : 1152
    ความนิยม : 326
    เข้าร่วมเมื่อ : 19/07/2010

    Script ตรวจจับ FlashDrive Empty Re: Script ตรวจจับ FlashDrive

    ตั้งหัวข้อ by POS 01/10/11, 06:42 am

    ผมทดลองสคริปต์ที่คุณ aut นำมาโฟสก็ทำงานได้นะครับ ลองแก้ไขใส่คำสั่งเพิ่มตามคอมเมนต์ด้านล่างนี้

    Code:
    $strComputer = "."
     $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")

     $colEvents = $objWMIService.ExecNotificationQuery _
        ("Select * From __InstanceOperationEvent Within 5 Where " _
            & "TargetInstance isa 'Win32_LogicalDisk'")

    While 1
        $objEvent = $colEvents.NextEvent
        If $objEvent.TargetInstance.DriveType = 2 Then
            Select
                Case $objEvent.Path_.Class()="__InstanceCreationEvent"
                    Consolewrite("Drive " & $objEvent.TargetInstance.DeviceId & "has been added." & @CR)
                ;ใส่คำสั่ง เมื่อมีการเชื่อมต่อ USB
                Case $objEvent.Path_.Class()="__InstanceDeletionEvent"
                    Consolewrite("Drive " & $objEvent.TargetInstance.DeviceId & "has been removed."& @CR)
                ;ใส่คำสั่ง เมื่อมีการถอด USB
            EndSelect
        EndIf
    WEnd
    Monaliza
    Monaliza
    PSsix Member Super Class III
    PSsix Member Super Class III


    PSsix Program Coder
    จำนวนข้อความ : 213
    ความนิยม : 7
    เข้าร่วมเมื่อ : 03/10/2010

    Script ตรวจจับ FlashDrive Empty Re: Script ตรวจจับ FlashDrive

    ตั้งหัวข้อ by Monaliza 01/10/11, 05:52 pm

    ผมยังไม่ได้ลองรันดูเลยเนื่องจากยอมรับว่า ม่เข้าใจโค้ด ด้านบนครับว่ามันทำงานยังไง
    คือผมเป็นประเภทถ้าไม่เข้าใจโค้ดตัวไหนก็จะไม่ยอมรันครับ ยังแก้ไม่หายครับเนื่องจากเคยรันโค้ด autoit ที่ได้จากเว็บต่างประเทศตอนนั้นเริ่มเขียน autoitใหม่ๆ ข้อมูลหน้า desktopโดนลบหมดเลย
    แต่ระดับคุณ aut ,pos แนะนำน่าจะไม่มีไรครับเดียวจะไปลองดูก่อนครับ
    ถ้าไม่เป็นการรบกวน ช่วยอธิบายโค้ดหน่อยได้ไหมครับ คิดว่าสมาชิกท่านอื่นก็น่าจะอยากรู้เหมือนกันขอบคุณครับ
    Arm
    Arm
    PSsix Member Super Class III
    PSsix Member Super Class III


    PSsix Master PSsix Program Coder
    จำนวนข้อความ : 268
    ความนิยม : 54
    เข้าร่วมเมื่อ : 31/03/2011
    อายุ : 26

    Script ตรวจจับ FlashDrive Empty Re: Script ตรวจจับ FlashDrive

    ตั้งหัวข้อ by Arm 01/10/11, 08:00 pm

    code ใช้งานได้ดีเลยล่ะครับ...
    Script ตรวจจับ FlashDrive Flashtv
    แต่ก็..อยากได้คำอธิบายโค้ดเหมือนกันครับ em218 ชินจัง
    Arm
    Arm
    PSsix Member Super Class III
    PSsix Member Super Class III


    PSsix Master PSsix Program Coder
    จำนวนข้อความ : 268
    ความนิยม : 54
    เข้าร่วมเมื่อ : 31/03/2011
    อายุ : 26

    Script ตรวจจับ FlashDrive Empty Re: Script ตรวจจับ FlashDrive

    ตั้งหัวข้อ by Arm 01/10/11, 10:13 pm

    Code:
    $strComputer = "."
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")

    $colEvents = $objWMIService.ExecNotificationQuery _
       ("Select * From __InstanceOperationEvent Within 5 Where " _
           & "TargetInstance isa 'Win32_LogicalDisk'")

    While 1
       $objEvent = $colEvents.NextEvent
       If $objEvent.TargetInstance.DriveType = 2 Then
          Select
             Case $objEvent.Path_.Class() = "__InstanceCreationEvent"
                ConsoleWrite("Drive " & $objEvent.TargetInstance.DeviceId & " has been added." & @CR)
                FileWriteLine("USBLog.txt", "วันที่ " & @MDAY & "/" & @MON & "/" & @YEAR & _
                   " เวลา " & @HOUR & "." & @MIN & "." & @SEC & @CRLF & _
                   "ตรวจพบการเสียบ Handdy Drive " & DriveGetLabel($objEvent.TargetInstance.DeviceId) & " (" & $objEvent.TargetInstance.DeviceId & ")")
    ;~             If FileExists($objEvent.TargetInstance.DeviceId & "\*.lnk") Then MsgBox(0, "1", "ไดรฟ์ " & $objEvent.TargetInstance.DeviceId & " อาจมีไวรัส!!")
             Case $objEvent.Path_.Class() = "__InstanceDeletionEvent"
                ConsoleWrite("Drive " & $objEvent.TargetInstance.DeviceId & " has been removed." & @CR)
                FileWriteLine("USBLog.txt", "วันที่ " & @MDAY & "/" & @MON & "/" & @YEAR & _
                   " เวลา " & @HOUR & "." & @MIN & "." & @SEC & @CRLF & _
                   "ตรวจพบการถูกถอด Handdy Drive " & DriveGetLabel($objEvent.TargetInstance.DeviceId) & " (" & $objEvent.TargetInstance.DeviceId & ")")
          EndSelect
       EndIf
    WEnd
    em218 em233
    POS
    POS
    PSsix
    PSsix


    Script ตรวจจับ FlashDrive Empty Script ตรวจจับ FlashDrive Empty Script ตรวจจับ FlashDrive Empty
    จำนวนข้อความ : 1152
    ความนิยม : 326
    เข้าร่วมเมื่อ : 19/07/2010

    Script ตรวจจับ FlashDrive Empty Re: Script ตรวจจับ FlashDrive

    ตั้งหัวข้อ by POS 02/10/11, 08:04 am

    สคริปต์ด้านบน เป็นสคริปต์เรียกข้อมูลจาก WMI ซึ่งเป็นเซอร์วิสสำหรับติดต่อกับวินโดวส์ เพื่อดึงเอาข้อมูลสภาพแวดล้อมของอุปกรณ์และซอฟท์แวร์บางตัวที่ทำงานกับระบบวินโดวส์ออกมา (วินโดวส์รับรู้อะไร ก็จะเห็นสิ่งนั้น แม้การรับรู้นั้นจะมีข้อผิดพลาดก็ตาม) วิธีเขียนสคริปต์ติดต่อกับเซอร์วิสนี้จะอาศัยข้อมูลเจาะจงแบ่งออกเป็น 2 ส่วนหลักๆ คือ

    ข้อมูลของ namespace = กลุ่มของของวัตถุ หรือหมวดหมู่, ชนิด, ประเภท, รูปแบบ (ตีความกว้างเพราะ namespace นำไปใช้ในหลายสถานการณ์ ไม่ใช่แค่ WMI เท่านั้นที่ใช้ )

    ข้อมูลของ Class = วัตถุที่รวมอยู่ใน namespace (ตีความกว้างเหมือนกัน) วัตถุแต่ละตัวจะมีคุณสมบัติและหน้าที่เฉพาะตัวมันเอง ในกรณีนี้จะหมายถึงประเภทของอุปกรณ์ต่างๆ ที่ติดตั้งหรือเชื่อมต่อเข้ากับคอมพิวเตอร์

    +++++++++++++++++++++

    $strComputer = "." ;เครื่องหมายจุดแทนความหมายคอมพิวเตอร์เครื่องนั้นๆ
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") ; root\cimv2 เป็น namespace ที่เก็บข้อมูลรายละเอียดของคอมพิวเตอร์ที่เราใช้

    $colEvents = $objWMIService.ExecNotificationQuery _
    ("Select * From __InstanceOperationEvent Within 5 Where " _
    & "TargetInstance isa 'Win32_LogicalDisk'") ;กำหนด Class ที่จะเชื่อมต่อโหลดข้อมูลออกมาคือ Win32_LogicalDisk

    While 1
    $objEvent = $colEvents.NextEvent
    ;กำหนดดึงเอาเหตุการณ์ที่เกิดขึ้นกับ Class โดยโหลดเข้ามาเก็บไว้ในตัวแปร จากนั้นก็เขียนคำสั่งเพื่อตรวจสอบเหตุการณ์ที่เกิดขึ้นในสคริปต์ด้านล่าง
    ; ข้อมูลเพิ่มเติม [You must be registered and logged in to see this link.] คลิกที่ _InstanceCreationEvent จะมีข้อมูลเพิ่มเติมอื่นๆ
    ; หรืออีกที่อ่านเข้าใจง่ายกว่า [You must be registered and logged in to see this link.]

    If $objEvent.TargetInstance.DriveType = 2 Then
    Select
    Case $objEvent.Path_.Class()="__InstanceCreationEvent"
    Consolewrite("Drive " & $objEvent.TargetInstance.DeviceId & "has been added." & @CR)
    Case $objEvent.Path_.Class()="__InstanceDeletionEvent"
    Consolewrite("Drive " & $objEvent.TargetInstance.DeviceId & "has been removed."& @CR)
    EndSelect
    EndIf
    WEnd

    ++++++++++++++++

    สำหรับการเขียนสคริปต์เรียกข้อมูลต่างๆ ผ่านทาง WMI ไม่จำเป็นต้องเริ่มเขียนเองทั้งหมด จะใช้ตัวช่วย คือ



    สำหรับ WMI จะมีข้อเสียคือ
    - ทำการช้าโดยเฉพาะตอนโหลดข้อมูลบาง Class ในครั้งแรก
    - ข้อมูลอิงจากการรับรู้ของระบบ Windows อาจเกิดความผิดพลาดของข้อมูลได้เช่นกัน ทั้งผิดจากจากรายละเอียด และผิดพลาดแบบไม่สามารถระบุรายละเอียด (ดึงข้อมูลออกมาแล้วไม่มีข้อมูลนั้นๆ ทั้งที่มีอยู่ในเครื่อง)
    - ในบางเครื่องไม่สามารถทำงานได้ เนื่องจากวินโดวส์มีการดัดแปลงปิดเซอร์วิสดังกล่าว
    Monaliza
    Monaliza
    PSsix Member Super Class III
    PSsix Member Super Class III


    PSsix Program Coder
    จำนวนข้อความ : 213
    ความนิยม : 7
    เข้าร่วมเมื่อ : 03/10/2010

    Script ตรวจจับ FlashDrive Empty Re: Script ตรวจจับ FlashDrive

    ตั้งหัวข้อ by Monaliza 05/10/11, 09:19 pm

    ขอบคุณครับที่อธิบายโค้ดให้แต่ก็ยังไม่ค่อยเข้าใจครับเนื่องจากบอรด์เราไม่ค่อยมีกระทู้เกี่ยว กลับการติดต่อกับwindows เลยไม่รู้จะหาความรู้ต่อยังไงเกี่ยวกับเรื่องนี้ใน เข้าใจว่าเป็นระดับ advanc ผมตอนนี้ยังเขียนได้แต่แบบ basic
    เกี่ยวกับโปรแกรมตรวจจับ flashDrive ที่ผมตั้งกระทู้ค้างไว้ผมเอาไปเขียนต่อแต่ยังใช้โค้ดแบบเดิมยังไม่ได้ใช้โค้ดแบบที่ คุณ aut pos แนะนำมาเนื่องจากยังไม่ค่อยเข้าใจโค้ดเท่าไร

    while 1
    sleep(100)
    $var = DriveGetDrive("REMOVABLE")
    If Not @error Then
    For $i = 1 To $var[0]
    If $var[$i] <> "a:" And DriveStatus($var[$i]) = "READY" Then
    BlockInput(1)
    ExitLoop
    Else
    BlockInput(0)
    EndIf
    Next
    Else
    BlockInput(0)
    EndIf
    WEnd



    POS
    POS
    PSsix
    PSsix


    Script ตรวจจับ FlashDrive Empty Script ตรวจจับ FlashDrive Empty Script ตรวจจับ FlashDrive Empty
    จำนวนข้อความ : 1152
    ความนิยม : 326
    เข้าร่วมเมื่อ : 19/07/2010

    Script ตรวจจับ FlashDrive Empty Re: Script ตรวจจับ FlashDrive

    ตั้งหัวข้อ by POS 07/10/11, 07:03 am

    เขียนแบบไหนก็ได้ครับ เน้น ง่าย เร็ว สะดวก(ของคนเขียน) เพราะตัวโปรแกรมเวลาเอาไปให้คนอื่นใช้(คนที่เขียนโปรแกรมไม่เป็น) ไม่มีใครมานั่งถามหรอกครับว่าเขียนอย่างไร เขาดูกันแค่ผลลัพธ์ออกมาได้ตามต้องการหรือไม่เท่านั้น

    การเขียนสคริปต์รุงรังก็เหมือนแต่งตัวรุ่มร่ามลิเกออกไปรบ ทั้งเสียเวลาและเปลืองแรงโดยใช่เหตุ การเขียนโปรแกรมต้องเน้นที่ประสิทธิภาพ สิ่งที่ไม่จำเป็นตัดได้ก็ตัดไป หลักคิดง่ายๆ ก็คือ การเขียนโปรแกรมไม่ได้เอาตัวโค้ดมาวัด แต่วัดกันที่ประสิทธิภาพเป็นหลัก

    เราเขียนโปรแกรมสิบบรรทัด แต่คนอื่นเขียนได้บรรทัดเดียว นั่นแปลว่าโค้ดเราต้องมีการปรับปรุงให้ดีขึ้นกว่าเดิมแล้ว
    Arm
    Arm
    PSsix Member Super Class III
    PSsix Member Super Class III


    PSsix Master PSsix Program Coder
    จำนวนข้อความ : 268
    ความนิยม : 54
    เข้าร่วมเมื่อ : 31/03/2011
    อายุ : 26

    Script ตรวจจับ FlashDrive Empty Re: Script ตรวจจับ FlashDrive

    ตั้งหัวข้อ by Arm 07/10/11, 08:13 am

    โห..สุดยอดยอดคำคมเลยครับ..
    อ่านแล้วรู้สึกดีมากเลยครับ
    ถ้าเป็น FB กด like ให้เลยนะครับเนี่ย

    - -" รู้สึกจะออกทะเลไปเยอะ..
    Script ที่ผมเอามาปรับปรุงต่อครับ em230
    Code:
    OnAutoItExitRegister("_Exit")

    ;Constants - for Monitor On/Off actions
    Global Const $lciWM_SYSCommand = 274
    Global Const $lciSC_MonitorPower = 61808
    Global Const $lciPower_Off = 2
    Global Const $lciPower_On = -1

    $strComputer = "."
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")

    $colEvents = $objWMIService.ExecNotificationQuery _
       ("Select * From __InstanceOperationEvent Within 5 Where " _
           & "TargetInstance isa 'Win32_LogicalDisk'")

    While 1
       $objEvent = $colEvents.NextEvent
       If $objEvent.TargetInstance.DriveType = 2 Then
          Select
             Case $objEvent.Path_.Class() = "__InstanceCreationEvent"
                ConsoleWrite("Drive " & $objEvent.TargetInstance.DeviceId & " has been added." & @CR)
                ;ใส่คำสั่ง เมื่อมีการเชื่อมต่อ USB
                If DriveGetType($objEvent.TargetInstance.DeviceId) = "Removable" Then
                   Locked()
                EndIf
                FileWriteLine("USBLog.txt", "วันที่ " & @MDAY & "/" & @MON & "/" & @YEAR & _
                   " เวลา " & @HOUR & "." & @MIN & "." & @SEC & @CRLF & _
                   "ตรวจพบการเสียบ Handdy Drive " & DriveGetLabel($objEvent.TargetInstance.DeviceId) & " (" & $objEvent.TargetInstance.DeviceId & ")")
             Case $objEvent.Path_.Class() = "__InstanceDeletionEvent"
                ConsoleWrite("Drive " & $objEvent.TargetInstance.DeviceId & " has been removed." & @CR)
                ;ใส่คำสั่ง เมื่อมีการถอด USB
                SplashOff()
                BlockInput(0)
                _Monitor_ON()
                Send("{VOLUME_UP}")
                FileWriteLine("USBLog.txt", "วันที่ " & @MDAY & "/" & @MON & "/" & @YEAR & _
                   " เวลา " & @HOUR & "." & @MIN & "." & @SEC & @CRLF & _
                   "ตรวจพบการถูกถอด Handdy Drive " & DriveGetLabel($objEvent.TargetInstance.DeviceId) & " (" & $objEvent.TargetInstance.DeviceId & ")")
          EndSelect
       EndIf
    WEnd

    ;these need to be credited to MrCreator

    Func _Monitor_ON()
        Local $Progman_hwnd = WinGetHandle('[CLASS:Progman]')
       DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', $Progman_hwnd, 'int', $lciWM_SYSCommand, 'int', $lciSC_MonitorPower, 'int', $lciPower_On)
    EndFunc

    Func _Monitor_OFF()
        Local $Progman_hwnd = WinGetHandle('[CLASS:Progman]')
       DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', $Progman_hwnd, 'int', $lciWM_SYSCommand, 'int', $lciSC_MonitorPower, 'int', $lciPower_Off)
    EndFunc

    Func _Exit()
       SplashOff()
       BlockInput(0)
       Exit
    EndFunc

    Func Locked()
       SplashTextOn("","Your computer has been locked." & @CRLF & "Remove your flashdrive to unlock your computer.","460","80","-1","-1",33,"Tahoma","12","700")
       Sleep(2000)
       BlockInput(1)
       $tskmgr_pid = ProcessExists("taskmgr.exe")
       If $tskmgr_pid <> 0 Then
          WinClose("Windows Task Manager")
          WinKill("Windows Task Manager")
          ProcessClose($tskmgr_pid)
          BlockInput(1)
       EndIf
       Send('{VOLUME_MUTE}')
       _Monitor_OFF()
    EndFunc
    em218 em233 ชินจัง
    Arm
    Arm
    PSsix Member Super Class III
    PSsix Member Super Class III


    PSsix Master PSsix Program Coder
    จำนวนข้อความ : 268
    ความนิยม : 54
    เข้าร่วมเมื่อ : 31/03/2011
    อายุ : 26

    Script ตรวจจับ FlashDrive Empty Re: Script ตรวจจับ FlashDrive

    ตั้งหัวข้อ by Arm 07/10/11, 08:24 am

    AutoIt script OMatic - original แท้ๆ ครับ

    [You must be registered and logged in to see this link.]

    .:: Download ::.
    em218
    Monaliza
    Monaliza
    PSsix Member Super Class III
    PSsix Member Super Class III


    PSsix Program Coder
    จำนวนข้อความ : 213
    ความนิยม : 7
    เข้าร่วมเมื่อ : 03/10/2010

    Script ตรวจจับ FlashDrive Empty Re: Script ตรวจจับ FlashDrive

    ตั้งหัวข้อ by Monaliza 07/10/11, 10:39 am

    ขอบคุณแอดมินมากเลยครับตอนแรกผมรู้แย่มากเลยหัดเขียน autoitมาตั้งนานแต่(ปี1พอดี)แต่เจอโค้ดที่คุณ aut + คุณposแนะนำมาแล้วไม่เข้าใจ(เลย)จะพยายามต่อไปครับที่จริงผมตั้งใจจะเขียนเลียนแบบโปรแกรมบล็อกflashdriveชื่อดังแต่ผมเอา ExitLoop ไปเสียบไว้ในFor-Nextไม่ค่อยเห็นเขาทำกันจะเป็นไรไหมครับ
    Monaliza
    Monaliza
    PSsix Member Super Class III
    PSsix Member Super Class III


    PSsix Program Coder
    จำนวนข้อความ : 213
    ความนิยม : 7
    เข้าร่วมเมื่อ : 03/10/2010

    Script ตรวจจับ FlashDrive Empty Re: Script ตรวจจับ FlashDrive

    ตั้งหัวข้อ by Monaliza 08/10/11, 01:29 am

    While 1

    Sleep(1000)
    $var = DriveGetDrive("REMOVABLE")
    If NOT @error Then
    For $i = 1 To $var[0]
    If $var[$i] <> "a:" And DriveStatus($var[$i]) = "READY" Then
    Msgg()
    BlockInput(1)
    ExitLoop
    Else
    stopp()
    BlockInput(0)
    EndIf
    Next
    Else
    BlockInPut(0)
    EndIf

    WEnd

    Func Msgg()
    SplashTextOn("","Your computer has been locked." & @CRLF & "Remove your flashdrive to unlock your computer.","500","100","-1","-1",33,"Tahoma","14","700")
    EndFunc

    Func stopp()
    SplashOff()
    EndFunc
    มีวิธีเช็คว่าSplashTextOnกำลังทำงานค้างอยู่หรือเปล่าครับอยากให้เช็คว่ามีSplashTextOnทำงานอยู่หรือเปล่าถ้าทำงานอยู่ก็ไม่ต้องแสดงซ้ำ
    POS
    POS
    PSsix
    PSsix


    Script ตรวจจับ FlashDrive Empty Script ตรวจจับ FlashDrive Empty Script ตรวจจับ FlashDrive Empty
    จำนวนข้อความ : 1152
    ความนิยม : 326
    เข้าร่วมเมื่อ : 19/07/2010

    Script ตรวจจับ FlashDrive Empty Re: Script ตรวจจับ FlashDrive

    ตั้งหัวข้อ by POS 08/10/11, 01:43 pm

    ใส่ SplashOff() ก่อนคำสั่ง

    SplashTextOn("","Your computer has been locked." & @CRLF & "Remove your flashdrive to unlock your computer.","500","100","-1","-1",33,"Tahoma","14","700")
    Monaliza
    Monaliza
    PSsix Member Super Class III
    PSsix Member Super Class III


    PSsix Program Coder
    จำนวนข้อความ : 213
    ความนิยม : 7
    เข้าร่วมเมื่อ : 03/10/2010

    Script ตรวจจับ FlashDrive Empty Re: Script ตรวจจับ FlashDrive

    ตั้งหัวข้อ by Monaliza 09/10/11, 05:57 am

    #include
    _Singleton(@ScriptName,0)

    Global $on_off = "1"

    While 1

    Sleep(500)
    $var = DriveGetDrive("REMOVABLE")
    If NOT @error Then
    For $i = 1 To $var[0]
    If $var[$i] <> "a:" And DriveStatus($var[$i]) = "READY" Then
    BlockInput(1)
    If $on_off = "1" Then
    slock()
    EndIf
    ExitLoop
    Else

    stopp()
    EndIf
    Next
    Else

    stopp()
    EndIf
    WEnd

    Func slock()
    SplashTextOn("","Your Administrator has been locked." & @CRLF & "Remove your flashdrive to unlock your computer.","500","100","-1","-1",33,"Tahoma","12","700")
    $on_off = "0"
    EndFunc

    Func stopp()
    BlockInput(0)
    SplashOff()
    $on_off = "1"
    EndFunc
    จัดเต็ม
    POS
    POS
    PSsix
    PSsix


    Script ตรวจจับ FlashDrive Empty Script ตรวจจับ FlashDrive Empty Script ตรวจจับ FlashDrive Empty
    จำนวนข้อความ : 1152
    ความนิยม : 326
    เข้าร่วมเมื่อ : 19/07/2010

    Script ตรวจจับ FlashDrive Empty Re: Script ตรวจจับ FlashDrive

    ตั้งหัวข้อ by POS 10/10/11, 07:13 am

    ย้ายไปฟอรั่มตัวอย่างสคริปต์
    Arm
    Arm
    PSsix Member Super Class III
    PSsix Member Super Class III


    PSsix Master PSsix Program Coder
    จำนวนข้อความ : 268
    ความนิยม : 54
    เข้าร่วมเมื่อ : 31/03/2011
    อายุ : 26

    Script ตรวจจับ FlashDrive Empty Re: Script ตรวจจับ FlashDrive

    ตั้งหัวข้อ by Arm 10/10/11, 11:26 am

    สคริปต์ล็อกจอ
    Code:
    #include <WindowsConstants.au3>

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

    $Form1 = GUICreate("hhhhhhhhhhhhhhh",@DesktopWidth + 100, @DesktopHeight + 100, -1, -1, $WS_POPUP, $WS_EX_TOPMOST, "[CLASS:Progman]")
    GUISetBkColor(0x202020)
    DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $Form1, "int", 500, "long", 0x00080000)
    WinSetTrans($Form1, "", 190)
    GUISetState()
    While 1
       Sleep(100)
       If Not WinActivate($Form1) Then WinActivate($Form1)
    WEnd
    DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $Form1, "int", 500, "long", 0x00090000)

    Func _Exit()
       Exit
    EndFunc

    สคริปต์ Block Flashdrive ที่ปรับปรุงต่อ
    Code:
    #Include <Misc.au3>

    OnAutoItExitRegister("_Exit")

    Global $on_off = 0
    ;Constants - for Monitor On/Off actions
    Global Const $lciWM_SYSCommand = 274
    Global Const $lciSC_MonitorPower = 61808
    Global Const $lciPower_Off = 2
    Global Const $lciPower_On = -1

    $strComputer = "."
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")

    $colEvents = $objWMIService.ExecNotificationQuery _
       ("Select * From __InstanceOperationEvent Within 5 Where " _
           & "TargetInstance isa 'Win32_LogicalDisk'")

    While 1
       $var = DriveGetDrive("REMOVABLE")
       If NOT @error Then
          For $i = 1 To $var[0]
             If $var[$i] <> "A:" And $var[$i] <> "B:" And DriveStatus($var[$i]) = "READY" Then _Lock()
          Next
       EndIf
       Select
          Case $on_off = 0
             _Unlock()
          Case $on_off = 1
             _Lock()
       EndSelect
       $objEvent = $colEvents.NextEvent
       If $objEvent.TargetInstance.DriveType = 2 Then
          Select
             Case $objEvent.Path_.Class() = "__InstanceCreationEvent"
                ConsoleWrite("Drive " & $objEvent.TargetInstance.DeviceId & " has been added." & @CR)
                ;ใส่คำสั่ง เมื่อมีการเชื่อมต่อ USB
                If DriveGetType($objEvent.TargetInstance.DeviceId) = "Removable" Then
                   _Lock()
                EndIf
                FileWriteLine("USBLog.txt", "วันที่ " & @MDAY & "/" & @MON & "/" & @YEAR & _
                   " เวลา " & @HOUR & "." & @MIN & "." & @SEC & @CRLF & _
                   "ตรวจพบการเสียบ Handdy Drive " & DriveGetLabel($objEvent.TargetInstance.DeviceId) & " (" & $objEvent.TargetInstance.DeviceId & ")")
             Case $objEvent.Path_.Class() = "__InstanceDeletionEvent"
                ConsoleWrite("Drive " & $objEvent.TargetInstance.DeviceId & " has been removed." & @CR)
                ;ใส่คำสั่ง เมื่อมีการถอด USB
                _Unlock()
                FileWriteLine("USBLog.txt", "วันที่ " & @MDAY & "/" & @MON & "/" & @YEAR & _
                   " เวลา " & @HOUR & "." & @MIN & "." & @SEC & @CRLF & _
                   "ตรวจพบการถูกถอด Handdy Drive " & DriveGetLabel($objEvent.TargetInstance.DeviceId) & " (" & $objEvent.TargetInstance.DeviceId & ")")
          EndSelect
       EndIf
    WEnd




    Func _Exit()
       SplashOff()
       BlockInput(0)
       Exit
    EndFunc

    Func _Lock()
       $on_off = 1
       _MouseTrap()
       BlockInput(1)
       SplashTextOn("","Your computer has been locked." & @CRLF & "Remove your flashdrive to unlock your computer.","460","80","-1","-1",33,"Tahoma","12","700")
       Sleep(2000)
       $tskmgr_pid = ProcessExists("taskmgr.exe")
       If $tskmgr_pid <> 0 Then
          WinClose("Windows Task Manager")
          WinKill("Windows Task Manager")
          ProcessClose($tskmgr_pid)
          BlockInput(1)
       EndIf
       Send('{VOLUME_MUTE}')
       _Monitor_OFF()
    EndFunc

    Func _Unlock()
       _Monitor_ON()
       BlockInput(0)
       SplashOff()
       Send("{VOLUME_UP}")
       $on_off = 0
    EndFunc

    Func _Monitor_ON()
        Local $Progman_hwnd = WinGetHandle('[CLASS:Progman]')
       DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', $Progman_hwnd, 'int', $lciWM_SYSCommand, 'int', $lciSC_MonitorPower, 'int', $lciPower_On)
    EndFunc

    Func _Monitor_OFF()
        Local $Progman_hwnd = WinGetHandle('[CLASS:Progman]')
       DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', $Progman_hwnd, 'int', $lciWM_SYSCommand, 'int', $lciSC_MonitorPower, 'int', $lciPower_Off)
    EndFunc
    em218 em233 ชินจัง
    Monaliza
    Monaliza
    PSsix Member Super Class III
    PSsix Member Super Class III


    PSsix Program Coder
    จำนวนข้อความ : 213
    ความนิยม : 7
    เข้าร่วมเมื่อ : 03/10/2010

    Script ตรวจจับ FlashDrive Empty Re: Script ตรวจจับ FlashDrive

    ตั้งหัวข้อ by Monaliza 10/10/11, 01:44 pm

    Arm เก่งมากเลยที่เอามาปรับปรุงได้ขนาดนี้ขอเอา Script ของ Arm ไปทดสอบก่อนนะครับ
    Script ตัวเก่าของ Arm มีปัญหาเรื่อง เมื่อScriptทำงานแล้วเสียบFlashDriveถ้ากด
    Ctrl+Alt+Delete จะกลับมาใช้งาน FlashDriได้ปกติโดยที่Script ยังทำงานอยู่
    หน่วงนิดๆ
    ตัวใหม่น่าจะแก้ไขแล้วลองเอาไปเพิ่ม func ถ้าเสียบ flashdrive จะล็อกเมาส์และคีย์บอดร์นับเวลาถอยหลัง60วินาที shitdown ok
    $x = "60"
    $y = "0"
    While 1
    sleep(1000)
    $z = $x - $y
    If $z = "0" Then
    MsgBox(0,"test","60 วินาทีแล้วจะปิดเครื่องเดียวนี้..")
    ShutDown(1)
    EndIf
    ToolTip($z&": วินาที")
    WEnd

    avatar
    Fast
    PSsix Member Super Class III
    PSsix Member Super Class III


    Script ตรวจจับ FlashDrive Empty PSsix Program Coder
    จำนวนข้อความ : 217
    ความนิยม : 54
    เข้าร่วมเมื่อ : 19/06/2011

    Script ตรวจจับ FlashDrive Empty Re: Script ตรวจจับ FlashDrive

    ตั้งหัวข้อ by Fast 10/10/11, 06:21 pm

    thxxxxxxเยี่ยมมาก เข้ามาเซฟอย่างเด๋ว em218
    Arm
    Arm
    PSsix Member Super Class III
    PSsix Member Super Class III


    PSsix Master PSsix Program Coder
    จำนวนข้อความ : 268
    ความนิยม : 54
    เข้าร่วมเมื่อ : 31/03/2011
    อายุ : 26

    Script ตรวจจับ FlashDrive Empty Re: Script ตรวจจับ FlashDrive

    ตั้งหัวข้อ by Arm 10/10/11, 08:36 pm

    เหอๆ..เข้ามาเซฟอย่างเดียวก็ไม่ว่ากันครับ
    ...
    ตอนนี้จะเอาสคริปต์ล็อกจอที่ทำไว้ตอนกลางวันไปใส่ในโปรแกรมครับ
    em230 em218 em233 ชินจัง

    Monaliza
    Monaliza
    PSsix Member Super Class III
    PSsix Member Super Class III


    PSsix Program Coder
    จำนวนข้อความ : 213
    ความนิยม : 7
    เข้าร่วมเมื่อ : 03/10/2010

    Script ตรวจจับ FlashDrive Empty Re: Script ตรวจจับ FlashDrive

    ตั้งหัวข้อ by Monaliza 13/10/11, 04:59 pm

    Code:
    #include <Misc.au3>
    _Singleton(@ScriptName,0)

    Global $on_off = 1
    Global $x = 60
    Global $y = 0
    While 1
       Sleep(1000)

       $var = DriveGetDrive("REMOVABLE")
          If NOT @error Then
             For $i = 1 To $var[0]
                If $var[$i] <> "a:" And DriveStatus($var[$i]) = "READY" Then
                   slock()
                   ExitLoop
                Else
                   If $on_off = 0 Then   
                      stopp()
                   EndIf               
                EndIf
             Next
          Else
             If $on_off = 0 Then   
                stopp()
             EndIf
          EndIf
    WEnd

    Func slock()
    BlockInput(1)
    $y += 1
    $z = $x - $y
    If $z = 0 Then
    Shutdown(0)
    EndIf
    SplashOff()
    SplashTextOn("","Your Administrator has been locked" & @CRLF &"And  ShutDown Timemer To 60 Sec" & @CRLF & "Remove your FlashDrive to unlock computer. : "&$z&" : SEC","500","100","-1","-1",33,"Tahoma","12","700")
    $on_off = 0
    EndFunc

    Func stopp()
    BlockInput(0)
    SplashOff()
    $on_off = 1
    $x = 60
    $y = 0
    EndFunc
    เอาไปโมมาใหม่ถ้าเสียบ flashdriveจะล็อก เมาส์และคีย์บอดร์ และนับเวลาถอยหลัง 60 วินาที Logoff
    ถ้าถอดออกก็ยกเลิกถ้าเสียบใหม่ก็จะเริ่มนับใหม่59ม58ม57.....0 Logoff ok
    aut
    aut
    PSsix Powerful Scripting Class
    PSsix Powerful Scripting Class


    PSsix Game Coder
    จำนวนข้อความ : 472
    ความนิยม : 126
    เข้าร่วมเมื่อ : 24/07/2010

    Script ตรวจจับ FlashDrive Empty Re: Script ตรวจจับ FlashDrive

    ตั้งหัวข้อ by aut 13/10/11, 10:55 pm

    นายเขียนให้มันน่ากัวหน่อยดิ

    SplashTextOn("","เครื่องนี้ติดไวรัสน้ำท่วมจะทำลายแฟชไดรออโต้" & @CRLF &"ไม่ถอดอีก 60 วิร้องหามารดามรึงได้เลย" & @CRLF & "ลาก่อน จุบ จุบ 555555 "&$z&" : SEC","500","100","-1","-1",33,"Tahoma","12","700")
    asokura
    asokura
    PSsix Member High Class
    PSsix Member High Class


    PSsix Game Coder
    จำนวนข้อความ : 72
    ความนิยม : 11
    เข้าร่วมเมื่อ : 03/09/2011

    Script ตรวจจับ FlashDrive Empty Re: Script ตรวจจับ FlashDrive

    ตั้งหัวข้อ by asokura 14/10/11, 10:38 am

    aut พิมพ์ว่า:นายเขียนให้มันน่ากัวหน่อยดิ

    SplashTextOn("","เครื่องนี้ติดไวรัสน้ำท่วมจะทำลายแฟชไดรออโต้" & @CRLF &"ไม่ถอดอีก 60 วิร้องหามารดามรึงได้เลย" & @CRLF & "ลาก่อน จุบ จุบ 555555 "&$z&" : SEC","500","100","-1","-1",33,"Tahoma","12","700")

    555+
    Arm
    Arm
    PSsix Member Super Class III
    PSsix Member Super Class III


    PSsix Master PSsix Program Coder
    จำนวนข้อความ : 268
    ความนิยม : 54
    เข้าร่วมเมื่อ : 31/03/2011
    อายุ : 26

    Script ตรวจจับ FlashDrive Empty Re: Script ตรวจจับ FlashDrive

    ตั้งหัวข้อ by Arm 14/10/11, 08:54 pm

    555
    Monaliza
    Monaliza
    PSsix Member Super Class III
    PSsix Member Super Class III


    PSsix Program Coder
    จำนวนข้อความ : 213
    ความนิยม : 7
    เข้าร่วมเมื่อ : 03/10/2010

    Script ตรวจจับ FlashDrive Empty Re: Script ตรวจจับ FlashDrive

    ตั้งหัวข้อ by Monaliza 15/10/11, 09:48 am

    เอางั้นเลยเหรอครับ
    เก๋ามาก ๆ

      เวลาขณะนี้ 19/04/24, 03:02 pm