赋值问题,大家帮下我啊
本帖最后由 chenchuai 于 2012-6-17 02:01 编辑请教下如何把代码2获取的账号密码 赋值到 代码1 当中呢,多谢了!#Region AutoIt3Wrapper 预编译参数(常用参数)
#AutoIt3Wrapper_Icon= ;图标,支持EXE,DLL,ICO
#AutoIt3Wrapper_OutFile= ;输出文件名
#AutoIt3Wrapper_OutFile_Type=exe ;文件类型
#AutoIt3Wrapper_Compression=4 ;压缩等级
#AutoIt3Wrapper_UseUpx=y ;使用压缩
#AutoIt3Wrapper_Res_Comment= ;注释
#AutoIt3Wrapper_Res_Description= ;详细信息
#AutoIt3Wrapper_Res_Fileversion= ;文件版本
#AutoIt3Wrapper_Res_FileVersion_AutoIncrement=p ;自动更新版本
RunWait(@ComSpec & " /c rasdial 宽带连接名 /disconnect","", 0)
Sleep(2000)
RunWait(@ComSpec & " /c rasdial 宽带连接名 帐号 密码","", 0)
#AutoIt3Wrapper_Res_LegalCopyright= ;版权
#AutoIt3Wrapper_Change2CUI=N ;修改输出的程序为CUI(控制台程序)
;#AutoIt3Wrapper_Res_Field=AutoIt Version|%AutoItVer% ;自定义资源段
;#AutoIt3Wrapper_Run_Tidy= ;脚本整理
;#AutoIt3Wrapper_Run_Obfuscator= ;代码迷惑
;#AutoIt3Wrapper_Run_AU3Check= ;语法检查
;#AutoIt3Wrapper_Run_Before= ;运行前
;#AutoIt3Wrapper_Run_After= ;运行后
#EndRegion AutoIt3Wrapper 预编译参数设置完成
#cs ____________________________________
Au3 版本:
脚本作者:
Email:
QQ/TM:
脚本版本:
脚本功能:
#ce _______________脚本开始_________________
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global Const $POLICY_GET_PRIVATE_INFORMATION = 4
If Not IsDeclared("ERROR_INVALID_SID") Then Global Const $ERROR_INVALID_SID = 1337
Global Const $tagLSAUNICODE = "ushort Length;ushort MaxLength;ptr Wbuffer"
Global Const $tagLSAOBJATTR = "ulong Length;hWnd RootDir;ptr objName;ulong Attr;ptr SecurDescr;ptr SecurQuality"
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 442, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 120, 136, 107, 73)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
yunxin()
EndSwitch
WEnd
Func yunxin()
FileWrite("D:\本机宽带密码和网卡IP.txt"," "&@CRLF)
FileWrite("D:\本机宽带密码和网卡IP.txt","============================================================"&@CRLF)
FileWrite("D:\本机宽带密码和网卡IP.txt"," "&@CRLF)
FileWrite("D:\本机宽带密码和网卡IP.txt","* 本机ADSL宽带帐号及密码信息:"&@CRLF)
FileWrite("D:\本机宽带密码和网卡IP.txt"," "&@CRLF)
FileWrite("D:\本机宽带密码和网卡IP.txt", ""&_FINDADSL() &@CRLF)
FileWrite("D:\本机宽带密码和网卡IP.txt"," "&@CRLF)
FileWrite("D:\本机宽带密码和网卡IP.txt","------------------------------------------------------------"&@CRLF)
RunWait(@ComSpec & " /c " & "ipconfig /all >> D:\本机宽带密码和网卡IP.txt","",0)
FileWrite("D:\本机宽带密码和网卡IP.txt",@CRLF)
FileWrite("D:\本机宽带密码和网卡IP.txt","============================================================"&@CRLF)
FileWrite("D:\本机宽带密码和网卡IP.txt","* 以上信息由《拾零装机工具箱》的《获取宽带密码及网卡IP》生成,"&@CRLF)
FileWrite("D:\本机宽带密码和网卡IP.txt"," 为的是重装系统前把您的上网帐号密码、本地连接IP保存下来,"&@CRLF)
FileWrite("D:\本机宽带密码和网卡IP.txt"," 以免您重装系统后因丢失帐号密码而上不了网。"&@CRLF)
FileWrite("D:\本机宽带密码和网卡IP.txt",@CRLF)
FileWrite("D:\本机宽带密码和网卡IP.txt","* 本信息生成时间:" &@YEAR&"年"&@MON&"月"&@MDAY&"日"&@HOUR&"点"&@MIN&"分"&@SEC&"秒"&@CRLF)
FileWrite("D:\本机宽带密码和网卡IP.txt",@CRLF)
FileWrite("D:\本机宽带密码和网卡IP.txt"," ----- 拾零工作室 倾情制作 -----")
FileWrite("D:\本机宽带密码和网卡IP.txt",@CRLF)
Run("Notepad.exe D:\本机宽带密码和网卡IP.txt")
EndFunc
Func _FINDADSL()
Dim $pSid = _LookupAccountName(@UserName) ; 获取用户SID指针。
Dim $sSid = _ConvertSidToStringSid($pSid) ; 转换为字符型SID。
_HeapFree($pSid)
Dim $bData = _LsaRetrievePrivateData("RasDialParams!" & $sSid & "#0")
$iSize = @extended
If $bData <> "" Then
Return _ADSL($iSize, $bData)
Else
$bData = _LsaRetrievePrivateData("L$_RasDefaultCredentials#0")
$iSize = @extended
If $bData <> "" Then
Return _ADSL($iSize, $bData)
EndIf
EndIf
EndFunc ;==>_FINDADSL
Func _ADSL($iSize, $bData)
Dim $tB = DllStructCreate("byte[" & $iSize & "]")
Dim $pB = DllStructGetPtr($tB)
Dim $tW = DllStructCreate("wchar[" & $iSize / 2 & "]", $pB)
DllStructSetData($tB, 1, $bData)
Dim $sR = ""
For $i = 1 To $iSize / 2
Dim $sC = DllStructGetData($tW, 1, $i)
If $sC = Chr(0) And StringRight($sR, 1) <> " " Then $sR &= " "
If $sC <> Chr(0) Then $sR &= $sC
Next
Dim $ADSJ = StringSplit($sR, " ", 1)
If $ADSJ <> "" And $ADSJ <> "" Then
Return " 宽带帐号 : "&$ADSJ& @CRLF &@CRLF & " 宽带密码 : " & $ADSJ
Else
Return "获取失败,请重试!"
EndIf
EndFunc ;==>_ADSL
Func _LookupAccountName($sName, $sSystem = "")
Local $iResult, $pSid, $pDomain, $iSysError
$iResult = DllCall("Advapi32.dll", "int", "LookupAccountName", _
"str", $sSystem, "str", $sName, "ptr", 0, "int*", 0, _
"ptr", 0, "int*", 0, "int*", 0)
$pSid = _HeapAlloc($iResult)
$pDomain = _HeapAlloc($iResult)
$iResult = DllCall("Advapi32.dll", "int", "LookupAccountName", _
"str", $sSystem, "str", $sName, _
"ptr", $pSid, "int*", $iResult, _
"ptr", $pDomain, "int*", $iResult, "int*", 0)
$iSysError = _GetLastError()
_HeapFree($pDomain)
Return SetError($iSysError, $iResult, $pSid)
EndFunc ;==>_LookupAccountName
Func _ConvertSidToStringSid($pSid)
Local $iResult, $tBuffer, $iSysError, $sResult
If Not _IsValidSid($pSid) Then Return SetError(@error, 0, "")
$iResult = DllCall("Advapi32.dll", "int", "ConvertSidToStringSid", _
"ptr", $pSid, "ptr*", 0)
If $iResult = 0 Then $iSysError = _GetLastError()
If $iResult = 0 Then Return SetError($iSysError, 0, "")
$tBuffer = DllStructCreate("char", $iResult)
$sResult = DllStructGetData($tBuffer, 1)
_LsaLocalFree($iResult)
Return SetError($iSysError, _FreeVariable($tBuffer), $sResult)
EndFunc ;==>_ConvertSidToStringSid
Func _LsaRetrievePrivateData($sKeyName, $sSystem = "")
Local $hPolicy, $iResult, $pKeyName, $bData, $iSize, $tBuffer
$hPolicy = _LsaOpenPolicy($POLICY_GET_PRIVATE_INFORMATION, $sSystem)
If $hPolicy = 0 Then Return SetError(@error, 0, 0)
$pKeyName = _LsaInitializeBufferW($sKeyName)
$iResult = DllCall("Advapi32.dll", "dword", "LsaRetrievePrivateData", _
"hWnd", $hPolicy, "ptr", $pKeyName, "ptr*", 0)
$iSize = _LsaLocalSize($iResult) - 12
$tBuffer = DllStructCreate("byte[" & $iSize & "]", $iResult + 12)
$bData = DllStructGetData($tBuffer, 1)
_LsaClose($hPolicy)
_FreeVariable($tBuffer)
_HeapFree($pKeyName)
_LsaFreeMemory($iResult)
Return SetError(_LsaNtStatusToWinError($iResult), $iSize, $bData)
EndFunc ;==>_LsaRetrievePrivateData
Func _HeapAlloc($iSize, $iAllocOption = 8)
If $iSize < 1 Then Return 0
Local $pMem, $hHeap = _GetProcessHeap()
$pMem = DllCall("Kernel32.dll", "ptr", "HeapAlloc", "hWnd", $hHeap, _
"dword", $iAllocOption, "dword", $iSize)
Return $pMem
EndFunc ;==>_HeapAlloc
Func _GetLastError()
Local $iSysError = DllCall("Kernel32.dll", "long", "GetLastError")
Return $iSysError
EndFunc ;==>_GetLastError
Func _IsValidSid($pSid)
Local $iResult
$iResult = DllCall("Advapi32.dll", "int", "IsValidSid", "ptr", $pSid)
If $iResult Then Return SetError(0, 0, True)
Return SetError($ERROR_INVALID_SID, 0, False)
EndFunc ;==>_IsValidSid
Func _LsaOpenPolicy($iAccessMask, $sSystem = "")
Local $hPolicy, $tSystem, $pSystem, $iLength
Local $tObjAttr, $pObjAttr, $tName, $pName
If $sSystem <> "" Then
$iLength = StringLen($sSystem) * 2
$tSystem = DllStructCreate($tagLSAUNICODE)
$pSystem = DllStructGetPtr($tSystem)
$tName = DllStructCreate("wchar[" & $iLength & "]")
$pName = DllStructGetPtr($tName)
DllStructSetData($tName, 1, $sSystem)
DllStructSetData($tSystem, "Length", $iLength)
DllStructSetData($tSystem, "MaxLength", $iLength + 2)
DllStructSetData($tSystem, "Wbuffer", $pName)
EndIf
$tObjAttr = DllStructCreate($tagLSAOBJATTR)
$pObjAttr = DllStructGetPtr($tObjAttr)
$hPolicy = DllCall("Advapi32.dll", "dword", "LsaOpenPolicy", _
"ptr", $pSystem, "ptr", $pObjAttr, _
"dword", $iAccessMask, "hWnd*", 0)
_FreeVariable($tName)
_FreeVariable($tObjAttr)
_FreeVariable($tSystem)
Return SetError(_LsaNtStatusToWinError($hPolicy), 0, $hPolicy)
EndFunc ;==>_LsaOpenPolicy
Func _HeapFree($pMem)
If $pMem < 1 Then Return SetError(87, 0, False)
Local $iResult, $hHeap = _GetProcessHeap()
$iResult = DllCall("Kernel32.dll", "int", "HeapFree", "hWnd", $hHeap, _
"dword", 0, "ptr", $pMem)
Return $iResult <> 0
EndFunc ;==>_HeapFree
Func _LsaLocalFree($pMem)
Local $iResult
$iResult = DllCall("Kernel32.dll", "int", "LocalFree", "ptr", $pMem)
Return $iResult <> $pMem
EndFunc ;==>_LsaLocalFree
Func _FreeVariable(ByRef $vVariable)
$vVariable = 0
EndFunc ;==>_FreeVariable
Func _LsaInitializeBufferW($sData, $fDecode = False)
Local $pMem, $iLength, $tBuffer, $sResult
If $fDecode = False Then
$iLength = StringLen($sData) * 2 + 2
$pMem = _HeapAlloc($iLength + 8)
$tBuffer = DllStructCreate($tagLSAUNICODE & ";wchar Data[" & $iLength - 2 & "]", $pMem)
DllStructSetData($tBuffer, "Length", $iLength - 2)
DllStructSetData($tBuffer, "MaxLength", $iLength)
DllStructSetData($tBuffer, "Wbuffer", $pMem + 8)
DllStructSetData($tBuffer, "Data", $sData)
Return $pMem
ElseIf Not IsPtr($sData) Then
Return ""
EndIf
$tBuffer = DllStructCreate($tagLSAUNICODE, $sData)
$iLength = DllStructGetData($tBuffer, "MaxLength") * 2
If $iLength < 1 Then Return ""
$pMem = DllStructCreate("wchar Data[" & $iLength & "]", DllStructGetData($tBuffer, "Wbuffer"))
$sResult = DllStructGetData($pMem, "Data")
Return SetExtended(_FreeVariable($pMem), $sResult)
EndFunc ;==>_LsaInitializeBufferW
Func _LsaLocalSize($pMem)
Local $iSize = DllCall("Kernel32.dll", "long", "LocalSize", "ptr", $pMem)
Return $iSize
EndFunc ;==>_LsaLocalSize
Func _LsaCloseServiceHandle($hService)
Local $iResult = DllCall("Advapi32.dll", "int", "CloseServiceHandle", "hWnd", $hService)
Return SetError(_GetLastError(), 0, $iResult <> 0)
EndFunc ;==>_LsaCloseServiceHandle
Func _LsaCloseHandle($hHandle)
Local $iResult = DllCall("Kernel32.dll", "int", "CloseHandle", "long", $hHandle)
Return $iResult <> 0
EndFunc ;==>_LsaCloseHandle
Func _LsaClose($hPolicy)
Local $iResult
$iResult = DllCall("Advapi32.dll", "dword", "LsaClose", "hWnd", $hPolicy)
Return SetError(_LsaNtStatusToWinError($iResult), 0, $iResult = 0)
EndFunc ;==>_LsaClose
Func _LsaFreeMemory($pMem)
Local $iResult = DllCall("Advapi32.dll", "dword", "LsaFreeMemory", "ptr", $pMem)
Return SetError(_LsaNtStatusToWinError($iResult), 0, $iResult = 0)
EndFunc ;==>_LsaFreeMemory
Func _LsaNtStatusToWinError($iNtStatus)
Local $iSysError
$iSysError = DllCall("Advapi32.dll", "ulong", "LsaNtStatusToWinError", "dword", $iNtStatus)
Return $iSysError
EndFunc ;==>_LsaNtStatusToWinError
Func _GetProcessHeap()
Local $hHeap = DllCall("Kernel32.dll", "hWnd", "GetProcessHeap")
Return $hHeap
EndFunc ;==>_GetProcessHeap
RunWait(@ComSpec & " /c rasdial " & $name& " " & $user& " " & $password, "", 0) 回复 2# lpxx
Return " 宽带帐号 : "&$ADSJ& @CRLF &@CRLF & " 宽带密码 : " & $ADSJ
它返回的是数组啊,我应该怎么赋值呢?我啥也不懂是个菜鸟,请大牛在指点下,多谢了! 本帖最后由 afan 于 2012-6-17 20:25 编辑
LZ 的意思是将两个代码结合成一个脚本?或者说使用第二个脚本仅为了获取“宽带连接名 帐号 密码”这些值?
还是不懂如何将这些值代入到 RunWait 中?
虽然贴出来代码,但问题提得很含糊啊…
提问应该只贴出需要表达问题的“精简”且能“独立运行”又能“重现问题”代码,这样的提问别人可以很快给出答案。像这样长的代码,别人还得先消化代码,找出问题…
另外,尽量在时间充裕的条件下提问,并时刻关注。像LZ这样扔下问题,隔了18个小时再来,帮你、回复你的人就不一定有时间来接龙了……
BTW, 我遇到过几次从提问到解决(加注已解决)时间在两分钟之内的,关键在提问的学问。 昨天熬到夜里2点多,今天白天又忙,所以现在才上线,不好意思!
我的问题是怎么把获取的用户名和密码赋值到RunWait(@ComSpec & " /c rasdial " & $name& " " & $user& " " & $password, "", 0)这个代码中,多谢了! 昨天熬到夜里2点多,今天白天又忙,所以现在才上线,不好意思!
我的问题是怎么把获取的用户名和密码赋值到 ...
chenchuai 发表于 2012-6-17 20:24 http://www.autoitx.com/images/common/back.gif
你的意思是还是两个独立的脚本?先运行2,获得那些数据,再运行1? 楼主,你是要赋值?传递参数?还是怎么滴。唉,基本概念没搞清楚的话,要学好一样东西是比较难的。 把代码2获取的账号密码 赋值到 代码1 当中Dim $user,$password
While 1
_bb()
ExitLoop
WEnd
Func _aa()
$a = StringSplit(FileReadLine("d:/本机宽带密码和网卡IP.txt", 6), ":")
$b = StringSplit(FileReadLine("d:/本机宽带密码和网卡IP.txt", 8), ":")
For $1 = 1 To $a
$aa = StringSplit($a[$1], ":")
Next
For $2 = 1 To $b
$bb = StringSplit($b[$2], ":")
Next
$user = $aa
$password = $bb
EndFunc ;==>_aa
Func _bb()
If FileExists("d:/本机宽带密码和网卡IP.txt") Then
_aa()
MsgBox(0, 0, "帐号=" & $user & @CR & "密码=" & $password);用来证明是否已运行哈!
RunWait(@ComSpec & " /c rasdial " & $user & " " & $password, "", 0)
Else
MsgBox(0, 0, "对不起,没找到文件")
EndIf
EndFunc ;==>_bb
把代码2获取的账号密码 赋值到 代码1 当中
lchl0588 发表于 2012-6-18 10:15 http://www.autoitx.com/images/common/back.gif
你这代码中出现的3处循环都无意义… 另外 RunWait 中的 “rasdial” 命令少了必须的“宽带连接名”
LZ 的代码1其作用肯定是换 IP 地址,因此 RunWait(@ComSpec & " /c rasdial 宽带连接名 /disconnect","", 0)这段也不能少~ 本帖最后由 lchl0588 于 2012-6-18 11:52 编辑
回复 9# afan
偶只做到把代码2 获取的帐号密码读取,再给一用就可以了,但LZ并未说换IP地址之类的哦!Dim $name="宽带连接",$user,$password;$name给赋值
While 1
_bb()
ExitLoop
WEnd
Func _aa()
$a = StringSplit(FileReadLine("d:/本机宽带密码和网卡IP.txt", 6), ":")
$b = StringSplit(FileReadLine("d:/本机宽带密码和网卡IP.txt", 8), ":")
For $1 = 1 To $a
$aa = StringSplit($a[$1], ":")
Next
For $2 = 1 To $b
$bb = StringSplit($b[$2], ":")
Next
$user = $aa
$password = $bb
EndFunc ;==>_aa
Func _bb()
If FileExists("d:/本机宽带密码和网卡IP.txt") Then
_aa()
MsgBox(0, 0, "帐号名="&$name&@CR&"帐号=" & $user & @CR & "密码=" & $password);用来证明是否已运行哈!
RunWait(@ComSpec & " /c rasdial "&$name&" /disconnect","", 0);这一步是根据A大启示添加..
Sleep(2000) ;这一步是根据A大启示添加..
RunWait(@ComSpec & " /c rasdial " & $name& " " & $user& " " & $password, "", 0) ;这一步是根据A大启示添加..
Else
MsgBox(0, 0, "对不起,没找到文件")
EndIf
EndFunc ;==>_bb 本帖最后由 afan 于 2012-6-18 12:20 编辑
回复 10# lchl0588
宽带连接名不一定就是“宽带连接”的,可以从TXT文件中读取,也可以读取注册表获得,也可以修改原代码2直接获取。Local $sFile = 'd:/本机宽带密码和网卡IP.txt'
Local $str = FileRead($sFile)
Local $aSR = StringRegExp($str, '帐号\h+:\h+(\S+)\s+.+?密码\h+:\h+(\S+)(?s).+?\nPPP adapter\h+(\S+):', 1)
If @Error Then Exit MsgBox(48, '错误', '获取失败')
RunWait(@ComSpec & ' /c rasdial ' & $aSR & ' /disconnect', '', 0)
Sleep(2000)
RunWait(@ComSpec & ' /c rasdial ' & $aSR & ' ' & $aSR & ' ' & $aSR, '', 0) 提醒一下。上面的代码5-7行将会断网重连,如果有相关针对Ip限制的下载或其它任务请注释掉该段代码。 本帖最后由 lchl0588 于 2012-6-18 13:21 编辑
回复 11# afan
你所说的代码,偶精简了一些Dim $name, $user, $password
While 1
_bb()
ExitLoop
WEnd
Func _aa()
$a = StringSplit(FileReadLine("d:/本机宽带密码和网卡IP.txt", 93), ":")
$b = StringSplit(FileReadLine("d:/本机宽带密码和网卡IP.txt", 6), ":")
$c = StringSplit(FileReadLine("d:/本机宽带密码和网卡IP.txt", 8), ":")
$name = StringMid($a, 12)
$user = StringMid($b, 1)
$password = StringMid($c, 1)
EndFunc ;==>_aa
Func _bb()
If FileExists("d:/本机宽带密码和网卡IP.txt") Then
_aa()
MsgBox(0, 0, "帐号名=" & $name & @CR & "帐号=" & $user & @CR & "密码=" & $password) ;用来证明是否已运行哈!
RunWait(@ComSpec & " /c rasdial " & $name & " /disconnect", "", 0)
Sleep(500)
RunWait(@ComSpec & " /c rasdial " & $name & " " & $user & " " & $password, "", 0)
Else
MsgBox(0, 0, "对不起,没找到文件")
EndIf
EndFunc ;==>_bb 本帖最后由 afan 于 2012-6-18 13:49 编辑
回复afan
你所说的代码,偶精简了一些
lchl0588 发表于 2012-6-18 13:19 http://www.autoitx.com/images/common/back.gif
2、4、5行是多余的,前面就说了…
另外,用 FileReadLine 指定行来获取信息是不明智的,PC 环境不同内容可能就不一样。我这就没有“93”行。
如果不用正则,至少应该用 StringInStr() 来找需要的关键字。 回复 13# lchl0588
第一次用非正则的方式提取字符串。结果是:同志们,可不可以不水深火热啊!Local $sFile = 'Adsl.txt'
Local $hFO = FileOpen($sFile)
If $hFO = -1 Then Exit MsgBox(0, 0, '打开文件失败')
$ts = TimerInIt()
Local $sLine, $sPaName, $sUser, $sPassword
Local $sUserKey = '号 : '
Local $sPasswordKey = '码 : '
Local $sPaNameKey = 'PPP adapter '
While 1
$sLine = FileReadLine($hFO)
If @error Then ExitLoop
_GetIt($sLine, $sUser, $sUserKey)
_GetIt($sLine, $sPassword, $sPasswordKey)
_GetIt($sLine, $sPaName, $sPaNameKey)
If $sPaName Then ExitLoop
WEnd
FileClose($hFO)
$sPaName = StringTrimRight($sPaName, 1)
$te = Round(TimerDiff($ts), 3) & ' ms'
MsgBox(0, $te, '"' & $sPaName & '"' & @LF & '"' & $sUser & '"' & @LF & '"' & $sPassword & '"')
Func _GetIt($sLine, ByRef $sNeed, $sKey)
Local $vP = StringInStr($sLine, $sKey)
If $vP Then $sNeed = StringMid($sLine, $vP + StringLen($sKey))
EndFunc ;==>_GetIt
页:
[1]
2