[已解決]無法讀取input內容
本帖最后由 jasonny 于 2016-1-4 19:47 编辑#include <GUIConstantsEx.au3>
#include <Process.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#RequireAdmin
$Form=GUICreate("PCinfo",400,300)
$label1=GUICtrlCreateLabel("",120,100,250,120)
$button1=GUICtrlCreateButton("test",200,50,70,20)
$label2=GUICtrlCreateLabel("CPU型號",50,100,70,50)
$input1=GUICtrlCreateInput("",50,50,50,30)
GUISetState()
while 1
$msg=GUIGetMsg()
$a=GUICtrlRead($Input1,0)
switch $button1
case $msg=$GUI_EVENT_CLOSE
ExitLoop
case $msg=$button1
$com= _RunDOS("wmic cpuget name >c:\cpu.txt " )
$order= FileReadLine("c:\cpu.txt",2)
GUICtrlSetData($label1,$order)
FileDelete("c:\cpu.txt")
EndSwitch
WEnd
以上程式碼輸入可執行。有個指令wmic /node:"電腦名稱" cpu get name
請問一下如何將電腦名稱用GUICtrlInput取代,讓user輸入電腦名稱,感謝~ While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
Exit
Case $button1
Run(@ComSpec & " /c wmic cpuget name >c:\cpu.txt",@SystemDir,@SW_HIDE )
$order= FileReadLine("c:\cpu.txt",2)
GUICtrlSetData($label1,$order)
FileDelete("c:\cpu.txt")
EndSwitch
WEnd 感謝H大的回答,但我試過你這樣改也只會讀到本機的資訊,我主要是想遠端讀取電腦的資訊
While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
Exit
Case $button1
Run(@ComSpec & " /c wmic /node:"$input1"cpuget name >c:\cpu.txt",@SystemDir,@SW_HIDE )
$order= FileReadLine("c:\cpu.txt",2)
GUICtrlSetData($label1,$order)
FileDelete("c:\cpu.txt")
EndSwitch
WEnd
這樣的話會出錯 回复 3# jasonny
你这么写当然会出错,你想把名称输出到INPUT吗?改下控件名不就行了?While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
Exit
Case $button1
Run(@ComSpec & " /c wmic cpuget name >c:\cpu.txt",@SystemDir,@SW_HIDE )
$order= FileReadLine("c:\cpu.txt",2)
GUICtrlSetData($input1,$order)
FileDelete("c:\cpu.txt")
EndSwitch
WEnd 楼主大概是想要这样吧,如果不考虑用户名和密码对不对的话。注意cpu get前面有个空格。GUISetState()
while 1
$msg=GUIGetMsg()
$a=GUICtrlRead($Input1,0)
switch $button1
case $msg=$GUI_EVENT_CLOSE
ExitLoop
case $msg=$button1
$computerName = GUICtrlRead($input1)
$com= Run(@ComSpec & " /c wmic /node:" & $computerName &" cpuget name >c:\cpu.txt",@SystemDir,@SW_HIDE )
$order= FileReadLine("c:\cpu.txt",2)
GUICtrlSetData($label1,$order)
FileDelete("c:\cpu.txt")
EndSwitch
WEnd 很多年前写的一个小工具里面的一部分代码,刚才复制出来测试了一下,还可以用,核心的代码好像也是以前从别人的脚本里借鉴的,楼主用这种方式来获取吧,比写到文件再读取出来的方式要可靠一些,参数可以是IP地址,也可以是计算机名称,很老的脚本了,不足之处请见谅。$lines = _hardware("homepc")
ConsoleWrite($lines)
Func _hardware($ip)
dim $mbd,$MBD,$MEM,$VGA,$HDD,$CPU
If ping($ip,100) Then
$objWMIService = objget("winmgmts:{impersonationLevel=impersonate}!\\"& $ip & "\root\cimv2")
If Not @error Then
$colBoard = $objWMIService.ExecQuery("SELECT * FROM Win32_BaseBoard")
$colCPU = $objWMIService.ExecQuery("Select * from CIM_Processor")
$colMemory = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
$colVideoinfo = $objWMIService.ExecQuery("Select * from Win32_VideoController")
$coldisk = $objWMIService.ExecQuery("Select * from Win32_DiskDrive")
For $object in $colBoard
$MBD = $object.Product
Next
For $object in $colCPU
$CPU = StringStripWS($object.Name,1)
Next
for $object in $colMemory
$MEM = string(Int(Number($object.TotalPhysicalMemory)/1048576)) & " MB"
Next
For $object in $colVideoinfo
$VGA = StringStripWS($object.Description ,1)
Next
For $object in $coldisk
$HDD = $HDD + int($object.size /1073741824)
Next
$HDD = String($HDD) & " GB"
Else
$CPU = "对方未开启WMI服务或用户名密码错误"
EndIf
Else
$CPU = "对方可能未开机"
EndIf
Return $IP & "|" & $MBD & "|" & $CPU & "|" & $MEM & "|" & $VGA & "|" & $HDD
EndFunc 回复 5# luren666
恩,我想要的就是這樣!!,感謝指點 好贴,学习了。 回复 6# luren666
感谢分享
页:
[1]