找回密码
 加入
搜索
查看: 5564|回复: 11

[AU3基础] 【已解决】如何判断本程序是否在硬盘上运行

  [复制链接]
发表于 2015-5-30 11:25:55 | 显示全部楼层 |阅读模式
本帖最后由 dnvplj 于 2015-6-18 16:08 编辑

请问各位朋友:如何判断本程序是否在硬盘上运行,如果在硬盘上运行,在执行完任务后删除自己,否则退出。编译后的文件名为:Software.exe
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 297, 160, 192, 124)
$Group1 = GUICtrlCreateGroup("", 8, 8, 281, 97)
$Label1 = GUICtrlCreateLabel("如果在硬盘上运行", 64, 32, 172, 28)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("任务完成删除自己", 64, 64, 172, 28)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("执  行", 112, 112, 73, 33)
$Button2 = GUICtrlCreateButton("退  出", 192, 112, 73, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                        
                Case $Button1
                        Set1()
                        
                Case $Button2
                        Exit

        EndSwitch
WEnd

Func Set1()
        RunWait('c:\Soft\Setup.exe')
        
EndFunc   ;==>Set1
发表于 2015-5-31 21:42:46 | 显示全部楼层
回复 1# dnvplj

第五行:
Global $colDisk_2

Func Set1()
        info()
        If $colDisk_2 = 1 Then
                MsgBox(0, "判断结果", "在无硬盘上运行")
                RunWait('c:\Soft\Setup.exe')
        Else
                MsgBox(1, "判断结果", "在< " & $colDisk_2 & " >硬盘上运行"& @CRLF & @CRLF &"按确定执行后删除自身文件!")
                RunWait('c:\Soft\Setup.exe')
                SHANGCHUWJ();删除自身文件代码
        EndIf
EndFunc   ;==>Set1
Func info()
        $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
        $colDisk = $objWMIService.ExecQuery("Select * from Win32_DiskDrive")
        For $object In $colDisk
                $colDisk_2 = StringStripWS($object.Caption, 1)
        Next
EndFunc   ;==>info
Func SHANGCHUWJ();删除自身
        ;删除自身文件代码
EndFunc   ;==>SHANGCHUWJ
 楼主| 发表于 2015-5-31 23:05:27 | 显示全部楼层
回复 2# chzj589
感谢2楼朋友的回复,但在硬盘和U盘上运行都没有反映(编译后也没有反映)。
发表于 2015-6-1 07:59:06 | 显示全部楼层
回复 3# dnvplj
不会没反映吧

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2015-6-1 09:10:59 | 显示全部楼层
本帖最后由 dnvplj 于 2015-6-1 09:14 编辑

回复 4# chzj589
我的系统是:WIN7X86,AU3是:AUTOIT_3.3.6.1-2版本,我在2个机器上试都没有反映。您是在那个版本系统环境下运行的。
发表于 2015-6-1 10:45:14 | 显示全部楼层
回复 5# dnvplj

刚在WIN7苹果双系统测试通过。
我的版本:Autoit V3  3.13.18
发表于 2015-6-5 11:22:09 | 显示全部楼层
 楼主| 发表于 2015-6-18 08:16:18 | 显示全部楼层
回复 8# zhao_ming
我在WIN7x32和64位系统上都没有反映,是什么原因?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2015-6-18 11:37:39 | 显示全部楼层
刚在WIN7苹果双系统测试通过。
发表于 2015-6-18 14:47:58 | 显示全部楼层
回复 9# dnvplj
看了你上的图,不知怎么说你......
;----------------------------------------------------------

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
;第五行:
Global $colDisk_2
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 297, 160, 192, 124)
$Group1 = GUICtrlCreateGroup("", 8, 8, 281, 97)
$Label1 = GUICtrlCreateLabel("如果在硬盘上运行", 64, 32, 172, 28)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("任务完成删除自己", 64, 64, 172, 28)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("执  行", 112, 112, 73, 33)
$Button2 = GUICtrlCreateButton("退  出", 192, 112, 73, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                        
                Case $Button1
                        Set1()
                        
                Case $Button2
                        Exit

        EndSwitch
WEnd
Func Set1()
        info()
        If $colDisk_2 = 1 Then
                MsgBox(0, "判断结果", "在无硬盘上运行")
                RunWait('c:\Soft\Setup.exe')
        Else
                MsgBox(1, "判断结果", "在< " & $colDisk_2 & " >硬盘上运行"& @CRLF & @CRLF &"按确定执行后删除自身文件!")
                RunWait('c:\Soft\Setup.exe')
                SHANGCHUWJ();删除自身文件代码
        EndIf
EndFunc   ;==>Set1
Func info()
        $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
        $colDisk = $objWMIService.ExecQuery("Select * from Win32_DiskDrive")
        For $object In $colDisk
                $colDisk_2 = StringStripWS($object.Caption, 1)
        Next
EndFunc   ;==>info
Func SHANGCHUWJ();删除自身
        ;删除自身文件代码
EndFunc   ;==>SHANGCHUWJ
;------------------------------------------------------------
这样应该不会没反映吧?
 楼主| 发表于 2015-6-18 16:06:03 | 显示全部楼层
回复 11# chzj589
是我的错误,事办的很好,结决了我的问题,话不是很好听,哈,谢谢你。
发表于 2015-12-31 08:23:57 | 显示全部楼层
学习学习一下
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-20 06:16 , Processed in 0.081060 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表