2015-02-09 58 views
2

我正在嘗試創建一個管理工具HTA。這比其他任何東西都更適合學習。到目前爲止,我已經在這裏找到了我需要的一切。現在我被困在一塊。我想收集計算機的序列號並將其輸出到文本框或文本區中。這是我正在嘗試使用的代碼。正如代碼將輸出「serialnumber」到文本框。任何幫助將不勝感激。如何使用HTA獲取計算機序列號

sub ComputerS 


set objExec = objShell.Exec("wmic bios get serialnumber") 

Set objStdOut = objExec.StdOut 
strLine = objStdOut.ReadLine 
queryResults.value = strLine 

end Sub 

,這裏是爲texarea和按鈕

<input type="button" value="Serial" onClick="ComputerS"> 
<textarea name="queryResults" rows="5" cols="30"></textarea> 

所以我想它的代碼。我不得不添加一行代碼

sub ComputerS 


set objExec = objShell.Exec("wmic bios get serialnumber") 

Set objStdOut = objExec.StdOut 
objExec.StdOut.skipLine 
strLine = objStdOut.ReadLine 
queryResults.value = strLine 

end Sub 

當我添加skipLine它的工作完美。 感謝大家的幫助,當我在我的工具上展開時,我一定會在不久的將來使用您的信息。

回答

2

嘗試這個HTA:

<html> 
<HTA:APPLICATION 
ICON="cmd.exe" 
APPLICATIONNAME ="Bios Serial Number" 
BORDER="dialog" 
BORDERSTYLE="complex" 
SINGLEINSTANCE="yes" 
WINDOWSTATE="maximize" 
> 
<Title>Bios Serial Number</title> 
<style> 
body{ 
background-color: Black; 
} 
</style> 
<script type="text/Vbscript"> 
sub ComputerS() 
    set objShell = CreateObject("wscript.shell") 
    set objExec = objShell.Exec("wmic bios get serialnumber") 
    Set objStdOut = objExec.StdOut 
    strLine = objStdOut.ReadAll 
    queryResults.value = strLine 
end Sub 
</script> 
<body text="white"> 
<center> 
<textarea name="queryResults" rows="5" cols="30"></textarea><br><br> 
<input type="button" value="Get Serial Number" onClick="ComputerS"> 
</body> 
</html> 

如果你想獲得有關計算機的詳細信息,只是試試這個HTA:

<html> 
<HTA:APPLICATION 
ICON="cmd.exe" 
APPLICATIONNAME ="Get Info PC" 
BORDER="dialog" 
BORDERSTYLE="complex" 
SINGLEINSTANCE="yes" 
WINDOWSTATE="maximize" 
> 
<Title>Get Info PC</title> 
<style> 
body{ 
background-color: Black; 
} 
</style> 
<script type="text/Vbscript"> 
sub ComputerS() 
    Set oShell = CreateObject("wscript.Shell") 
    Set env = oShell.environment("Process") 
    strComputer = env.Item("Computername") 
    Const HKEY_LOCAL_MACHINE = &H80000002 
    Const UnInstPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" 
    Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ 
    ".\root\default:StdRegProv") 

    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 
    Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48) 
    Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime") 

    report = report & "******************************************" & vbCrLf 
    report = report & " - Information de l'ordinateur " & strComputer & " - " & vbCrLf 
    report = report & "******************************************" & vbCrLf & vbCrLf 


    report = report & vbCrLf & "******************************************" & vbCrLf 
    report = report & "Informations sur Windows" & vbCrLf & "******************************************" & vbCrLf 

    For Each objItem in colItems 
     report = report & "- Nom du poste: " & strComputer & vbCrLf 
     report = report & "- Description de l'ordinateur: " & objItem.Description & vbCrLf 
     report = report & "- Utilisateur possédant la licence Windows: " & objItem.RegisteredUser & vbCrLf 
     report = report & "- Organisation possédant la licence Windows: " & objItem.Organization & vbCrLf 
     report = report & "******************************************" & vbCrLf 
     report = report & "- Nom du système d'exploitation: " & objItem.Caption & vbCrLf 
     If (objItem.OSProductSuite <> "")Then 
      report = report & "- Système d'exploitation de la suite " & objItem.OSProductSuite & vbCrLf 
     End If 
     report = report & "- Version: " & objItem.Version & vbCrLf 
     dtmConvertedDate.Value = objItem.InstallDate 
     dtmInstallDate = dtmConvertedDate.GetVarDate 
     report = report & "- Date de son installation: " & dtmInstallDate & vbCrLf 
     report = report & "- Numéro de série de " & objItem.Caption & ": " & objItem.SerialNumber & vbCrLf 
     report = report & vbCrLf 
     report = report & "******************************************" & vbCrLf 
     report = report & "Détails techniques sur Windows"& vbCrlf 
     report = report & "******************************************" & vbCrLf 
     report = report & "- Numéro du dernier Service Pack majeur installé: " 
     report = report & objItem.ServicePackMajorVersion & vbCrLf 

     If (objItem.MaxNumberOfProcesses="-1") Then 
      report = report & "- Maximum de processus pouvant être ouvert: Aucune limite fixée" & vbCrLf 
     Else 
      report = report & "- Maximum de processus pouvant être ouvert: " & objItem.MaxNumberOfProcesses & vbCrLf 
     End If 
    Next 

    Set colBIOS = objWMIService.ExecQuery _ 
    ("Select * from Win32_BIOS") 
    report = report & "******************************************" & vbCrLf 
    report = report & "BIOS - Utilitaire de détection des disques et" & vbCrLf 
    report = report & " de gestion des composantes internes" & vbCrLf & "******************************************" & vbCrLf 

    For Each objBIOS in colBIOS 
     report = report & "- Nom: " & objBIOS.Name & vbCrLf 
     report = report & "- Code d'identification: " & objBIOS.IdentificationCode & vbCrLf 
     report = report & "- Manufacturier: " & objBIOS.Manufacturer & vbCrLf 
     report = report & "- BIOS primaire: " & objBIOS.PrimaryBIOS & vbCrLf 
     dtmConvertedDate.Value = objBIOS.ReleaseDate 
     dtmInstallDate = dtmConvertedDate.GetVarDate 
     report = report & "- Date de création: " & dtmInstallDate & vbCrLf 
     report = report & "- Numéro de série: " & objBIOS.SerialNumber & vbCrLf 
     report = report & "- Version: " & objBIOS.Version & vbCrLf 
     report = report & "- Version (SMBIOS): " & objBIOS.SMBIOSBIOSVersion & vbCrLf 
     report = report & vbCrLf 
    Next 

    Set colSettings = objWMIService.ExecQuery _ 
    ("Select * from Win32_ComputerSystem") 
    report = report & "******************************************" & vbCrLf 
    report = report & "Mémoire vive (RAM) et processeur" & vbCrLf & "******************************************" & vbCrLf 
    For Each objComputer in colSettings 
     report = report & "- Vous avez actuellement " & objComputer.TotalPhysicalMemory /1024\1024+1 & " Mo de mémoire vive(RAM) au total." & vbcrlf 
    Next 

    Set colSettings = objWMIService.ExecQuery _ 
    ("Select * from Win32_Processor") 
    For Each objProcessor in colSettings 

     report = report & "- Type de processeur: " 
     If objProcessor.Architecture = 0 Then 
      report = report & "x86" & vbCrLf 
     ElseIf objProcessor.Architecture = 1 Then 
      report = report & "MIPS" & vbCrLf 
     ElseIf objProcessor.Architecture = 2 Then 
      report = report & "Alpha" & vbCrLf 
     ElseIf objProcessor.Architecture = 3 Then 
      report = report & "PowerPC" & vbCrLf 
     ElseIf objProcessor.Architecture = 6 Then 
      report = report & "ia64" & vbCrLf 
     Else 
      report = report & "inconnu" & vbCrLf 
     End If 

     report = report & "- Nom du processeur: " & objProcessor.Name & vbCrLf 
     report = report & "- Description du processeur: " & objProcessor.Description & vbCrLf 
     report = report & "- Vitesse actuelle du processeur: " & objProcessor.CurrentClockSpeed & " Mhz" & vbCrLf 
     report = report & "- Vitesse maximale du processeur: " & objProcessor.MaxClockSpeed & " Mhz" & vbCrLf 

     report = report & vbCrLf 
    Next 

    report = report & "******************************************" & vbCrLf 
    report = report & "Disque(s) dur(s) et autres lecteurs actuellement " & vbCrLf 
    report = report & "en usage" & vbCrLf & "******************************************" & vbCrLf 

    Dim oFSO 
    Set oFSO = CreateObject("Scripting.FileSystemObject") 

    Dim oDesLecteurs 
    Set oDesLecteurs = oFSO.Drives 

    Dim oUnLecteur 
    Dim strLectType 

    For Each oUnLecteur in oDesLecteurs 
     If oUnLecteur.IsReady Then 
      Select Case oUnLecteur.DriveType 
      Case 0: strLectType = "Inconnu" 
      Case 1: strLectType = "Amovible (Disquette, clé USB, etc.)" 
      Case 2: strLectType = "Fixe (Disque dur, etc.)" 
      Case 3: strLectType = "Réseau" 
      Case 4: strLectType = "CD-Rom" 
      End Select 

      report = report & "- Lettre du lecteur: " & oUnLecteur.DriveLetter & vbCrLf 
      report = report & "- Numéro de série: " & oUnLecteur.SerialNumber & vbCrLf 
      If (oUnLecteur.FileSystem <> "") Then 
       report = report & "- Système de fichier utilisé: " & oUnLecteur.FileSystem & vbCrLf 
      End If 

      Set objWMIService = GetObject("winmgmts:") 
      Set objLogicalDisk = objWMIService.Get("Win32_LogicalDisk.DeviceID='" & oUnLecteur.DriveLetter & ":'") 
      report = report & "- Il y a " & objLogicalDisk.FreeSpace /1024\1024+1 & " Mo d'espace restant sur ce lecteur/disque" & vbCrLf 
      report = report & "- Il y a " & objLogicalDisk.Size /1024\1024+1 & " Mo d'espace au total sur ce lecteur/disque" & vbCrLf 

     End If 
     report = report & vbCrLf 
    Next 

    queryResults.value = report 
end Sub 
</script> 
<body text="white"> 
<center> 
<textarea name="queryResults" rows="35" cols="120"></textarea><br><br> 
<input type="button" value="Get Info PC" onClick="ComputerS"> 
</body> 
</html> 
0

所以我最終找到我一直在尋找的答案在我自己的。我尋找的代碼非常簡單。

objExec.StdOut.SkipLine 

這是我唯一需要添加才能得到我想要的結果的東西。

相關問題