【已解决】开机启动使用默认位置容易找不到文件
本帖最后由 ac5474012 于 2022-8-4 09:46 编辑双击启动默认启动位置是当前目录下,如果需要调用某些当前目录下的ini就能直接写文件名就可以了,但是我发现开机启动的情况下这个位置的一些配置文件容易找不到,所以需要加上一个@ScriptDir锁定位置。
源码:
$mingcheng = StringReplace($mac, ":", "-")
$ip1 = StringSplit(@IPAddress1, '.', 1)
If $ip1 = "1" Then
Local $server = IniRead("config.ini", "ftp", "服务器内网地址", "NotFound") ;服务器地址
;~ MsgBox(0,"1",$server&@LF&$mingcheng & ".ini")
Else
Local $server = IniRead("config.ini", "ftp", "服务器地址", "NotFound") ;服务器地址
;~ MsgBox(0,"2",$server&@LF&$mingcheng & ".ini")
EndIf
Local $username = IniRead("config.ini", "ftp", "用户名", "NotFound") ;FTP用户名
Local $pass1 = IniRead("config.ini", "ftp", "密码", "NotFound") ;FTP密码
Local $pass = $pass1 & "123";在这里做了一个小防御机制,因为ini是明文的,所以对密码进行了延长三位的处理
Local $RemoteFile = IniRead("config.ini", "ftp", "远程路径", "NotFound") ;远程路径
Local $LocalFile = IniRead("config.ini", "ftp", "本地路径", "NotFound") ;本地路径
Local $Passive = IniRead("config.ini", "ftp", "主动被动模式", "NotFound");主动模式或者被动模式
Local $Port = IniRead("config.ini", "ftp", "端口", "NotFound");端口
Local $Open = _FTP_Open('MyFTP Control')
Local $Conn = _FTP_Connect($Open, $server, $username, $pass, $Passive, $Port)
_FTP_FilePut($Conn, $mingcheng & ".ini", $mingcheng & ".ini")
_FTP_Close($Open)问题:
用FTP上传一个文件。双击直接就能上传,但是加在开机启动中能启动,但是就是不能上传。
尝试:
1.延时 尝试加了一个等待 Sleep(30000) 等待30秒,但是还是失败了。
2.用另一个程序启动这个程序,还是失败了。
现象:
这个文件有其他的工作,其他的工作都能正常运行,但是只有上传是没有执行的。
请教如何解决
全部代码我贴在最下面,没用的比较多
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#PRE_icon=C:\Windows\syswow64\SHELL32.dll|-13
#PRE_Outfile=自动巡查86.exe
#PRE_Outfile_x64=自动巡查64.exe
#PRE_Compression=4
#PRE_UseUpx=n
#PRE_Compile_Both=y
#PRE_Res_Fileversion=0.0.0.17
#PRE_Res_Fileversion_AutoIncrement=p
#PRE_Res_requestedExecutionLevel=None
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#region ACN预处理程序参数(常用参数)
;#PRE_Res_Field=AutoIt Version|%AutoItVer% ;自定义资源段
;#PRE_Run_Tidy= ;脚本整理
;#PRE_Run_Obfuscator= ;代码迷惑
;#PRE_Run_AU3Check= ;语法检查
;#PRE_Run_Before= ;运行前
;#PRE_Run_After= ;运行后
;#PRE_UseX64=n ;使用64位解释器
;#PRE_Compile_Both ;进行双平台编译
#endregion ACN预处理程序参数(常用参数)
#cs ____________________________________
Au3 版本:
脚本作者:
电子邮件:
QQ/TM:
脚本版本:
脚本功能:
#ce _______________脚本开始_________________
#cs ____________________________________
Au3 版本: 3.3.7.2
脚本作者: guoji
Email:guojimail@gmail.com
QQ/TM:
脚本版本:1.0
脚本功能: 用FTP协议同步单向同步数据,不支持文件夹
简单的来说,就是检测FTP上的文件,如果设置的本地路径没有这个文件就下载这个文件,如果有就不下载。不能下载文件夹与文件夹里面的文件,只能支持一级目录。
#ce _______________脚本开始_________________
#include <FTPEx.au3>
#include <Array.au3>
#include <ACN_NET.au3>
#include <MsgBoxConstants.au3>
;~ --------------------------------------------------------------------------------------------------------------------------------
;~ TrayTip("提示","开始登记电脑的信息!",100,1)
$objWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$objItems = $objWMI.ExecQuery("SELECT * FROM Win32_SystemEnclosure")
For $ComputerSystem In $objItems
If$ComputerSystem.SMBIOSAssetTag<>"" Then
Global $AssetTag = $ComputerSystem.SMBIOSAssetTag
Else
$AssetTag = StringTrimLeft(@ComputerName,7)
EndIf
Next
$objItems = ""
;获取bios信息
$objItems = $objWMI.ExecQuery("Select * from Win32_BIOS")
For $objabc In $objItems
Global $sn = $objabc.Caption
Next
$objItems = ""
;获取主板信息
$objItems = $objWMI.ExecQuery("SELECT * FROM Win32_BaseBoard")
For $objabc In $objItems
Global $zhuban = $objabc.Product
Next
$objItems = ""
;获取显卡信息
$objItems = $objWMI.ExecQuery("Select * from Win32_VideoController")
For $objabc In $objItems
Global $xianka = $objabc.Description
Next
$objItems = ""
;获取声卡
$objItems = $objWMI.ExecQuery("Select * from Win32_SoundDevice")
For $objabc In $objItems
Global $shengka = $objabc.Description
Next
$objItems = ""
;获取网卡信息(只能有一张活动的网卡)
$objItems = $objWMI.ExecQuery("Select * from Win32_NetworkAdapter WHERE Netconnectionstatus = 2")
For $objabc In $objItems
Global $wangka = $objabc.name
Global $mac = $objabc.MACAddress
Next
$objItems = ""
;获取ip地址
$ip = @IPAddress1
;获取内存信息
$objItems = $objWMI.ExecQuery("Select * from Win32_ComputerSystem")
For $objabc In $objItems
Global $neicun = Round($objabc.totalphysicalmemory / (1024 * 1024) & " Mb")
Next
$objItems = ""
;获取系统信息
$objItems = $objWMI.ExecQuery("Select * from Win32_operatingsystem")
For $objabc In $objItems
Global$xitong = $objabc.Caption
Next
$objItems = ""
;获取cpu型号
$objItems = $objWMI.ExecQuery("Select * from Win32_processor")
For $objabc In $objItems
$cpu = $objabc.Name
Next
$objItems = ""
;获取硬盘大小
$objItems = $objWMI.ExecQuery("Select * from Win32_diskdrive")
$disk = ""
For $objabc In $objItems
If $disk = "" Then
Global $disk = Round($objabc.Size / 1073741824, 2)
EndIf
Next
$objItems = ""
;获取计算机名字
$objItems = $objWMI.ExecQuery("Select * from Win32_ComputerSystem")
For $objabc In $objItems
$ram = Round($objabc.totalphysicalmemory / 1073741824, 1)
Global$username = @UserName ;当前登录的用户名
Global $hostname = @ComputerName
Next
$objItems = ""
;~ MsgBox(0,"",$hostname&@LF&$cpu&@LF&$sn&@LF&$zhuban&@LF&$xianka&@LF&$shengka&@LF&$wangka&@LF&$neicun&@LF&$xitong&@LF&$ip&@LF&$mac&@LF&$disk)
$mingcheng= StringReplace($mac, ":", "-")
IniWrite($mingcheng&".ini", "peizhi", "监测时间", @YEAR&@MON&@MDAY)
IniWrite($mingcheng&".ini", "peizhi", "计算机名称", $hostname)
IniWrite($mingcheng&".ini", "peizhi", "cpu", $cpu)
IniWrite($mingcheng&".ini","peizhi", "bios", $sn)
IniWrite($mingcheng&".ini", "peizhi", "主板", $zhuban)
IniWrite($mingcheng&".ini", "peizhi", "显卡", $xianka)
IniWrite($mingcheng&".ini", "peizhi", "声卡", $shengka)
IniWrite($mingcheng&".ini", "peizhi", "网卡", $wangka)
IniWrite($mingcheng&".ini", "peizhi", "内存", $neicun)
IniWrite($mingcheng&".ini", "peizhi", "系统", $xitong)
IniWrite($mingcheng&".ini", "peizhi", "IP", $ip)
IniWrite($mingcheng&".ini", "peizhi", "mac", $mac)
IniWrite($mingcheng&".ini", "peizhi", "硬盘容量", $disk)
;~ --------------------------------------------------------------------------------------------------------------------------------
;获取网卡信息(只能有一张活动的网卡)
$objItems = $objWMI.ExecQuery("Select * from Win32_NetworkAdapter WHERE Netconnectionstatus = 2")
For $objabc In $objItems
Global $wangka = $objabc.name
Global $mac = $objabc.MACAddress
Next
$objItems = ""
;获取ip地址
$ip = @IPAddress1
;gui开始
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$mingcheng = StringReplace($mac, ":", "-")
$n1=IniRead($mingcheng & ".ini", "peizhi", "使用人", "NotFound")
$n2=IniRead($mingcheng & ".ini", "peizhi", "显示器型号", "NotFound")
$n3=IniRead($mingcheng & ".ini", "peizhi", "显示器编号", "NotFound")
$n4=IniRead($mingcheng & ".ini", "peizhi", "主机编号", "NotFound")
$n5=IniRead($mingcheng & ".ini", "peizhi", "硬盘健康", "NotFound")
$n6=IniRead($mingcheng & ".ini", "peizhi", "开机速度", "NotFound")
$n7=IniRead($mingcheng & ".ini", "peizhi", "设备位置", "NotFound")
$n8=IniRead($mingcheng & ".ini", "peizhi", "所属部门", "NotFound")
$mingcheng = StringReplace($mac, ":", "-")
Sleep(1000)
$mingcheng = StringReplace($mac, ":", "-")
$ip1 = StringSplit(@IPAddress1, '.', 1)
If $ip1 = "1" Then
Local $server = IniRead("config.ini", "ftp", "服务器内网地址", "NotFound") ;服务器地址
;~ MsgBox(0,"1",$server&@LF&$mingcheng & ".ini")
Else
Local $server = IniRead("config.ini", "ftp", "服务器地址", "NotFound") ;服务器地址
;~ MsgBox(0,"2",$server&@LF&$mingcheng & ".ini")
EndIf
Local $username = IniRead("config.ini", "ftp", "用户名", "NotFound") ;FTP用户名
Local $pass1 = IniRead("config.ini", "ftp", "密码", "NotFound") ;FTP密码
Local $pass = $pass1 & "123";在这里做了一个小防御机制,因为ini是明文的,所以对密码进行了延长三位的处理
Local $RemoteFile = IniRead("config.ini", "ftp", "远程路径", "NotFound") ;远程路径
Local $LocalFile = IniRead("config.ini", "ftp", "本地路径", "NotFound") ;本地路径
Local $Passive = IniRead("config.ini", "ftp", "主动被动模式", "NotFound");主动模式或者被动模式
Local $Port = IniRead("config.ini", "ftp", "端口", "NotFound");端口
Local $Open = _FTP_Open('MyFTP Control')
Local $Conn = _FTP_Connect($Open, $server, $username, $pass, $Passive, $Port)
MsgBox(0,"223", @ScriptDir&'\'&$mingcheng & ".ini")
_FTP_FilePut($Conn,@ScriptDir&'\'&$mingcheng & ".ini", $mingcheng & ".ini")
MsgBox(0,"FTP错误代码",@ERROR)
_FTP_Close($Open)
;gui结束
;MsgBox(0,"返回前4个网卡的IP和",@IPAddress1&@CR& _API_Get_NetworkAdapterMAC (@IPAddress1)&@CR&@IPAddress2&@CR& _API_Get_NetworkAdapterMAC (@IPAddress2)&@CR&@IPAddress3&@CR& _API_Get_NetworkAdapterMAC (@IPAddress3)&@CR&@IPAddress4&@CR& _API_Get_NetworkAdapterMAC (@IPAddress4))
MsgBox(0,"上传程序","执行完毕")
$mingcheng 用完整路径试试 afan 发表于 2022-8-3 16:21
$mingcheng 用完整路径试试
不管用,还是不能上传 先判断网络是否连接成功。
另外 _FTP_Connect 查看其@Error afan 发表于 2022-8-3 17:31
先判断网络是否连接成功。
另外 _FTP_Connect 查看其@Error
能联网,错误代码是-1 ac5474012 发表于 2022-8-3 18:04
能联网,错误代码是-1
那不就是连接失败。 本帖最后由 ac5474012 于 2022-8-4 09:47 编辑
afan 发表于 2022-8-3 18:08
那不就是连接失败。
嗯 解决了,加个@ScriptDir就好了 ac5474012 发表于 2022-8-4 09:44
嗯 解决了,加个@ScriptDir就好了
所以首先就让你使用完整路径测试。
如果你使用最简代码测试(如果要其它文件如ini配合,当然也要改),很容易找到问题。
页:
[1]