Need helping add the function of one script into another

Author Message
CoquitoKing

  • Total Posts : 25
  • Scores: 0
  • Reward points : 0
  • Joined: 4/20/2005
  • Location: USA
  • Status: offline
Need helping add the function of one script into another Monday, December 12, 2011 8:50 AM (permalink)
0
Hi all,
I have two working scripts.  I want to be able to enter the machine name in an inputbox of the second script like I do in the first script. 
SCRIPT 1:
---------------------------------------------------------------------------------------------
Const HARD_DISK = 3
Const CONVERSION_FACTOR = 1048576
Input = InputBox("Please enter machine name:","Machine Name")
strComputer = Input
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_LogicalDisk WHERE DriveType = " _
        & HARD_DISK & "")
For Each objDisk in colDisks
    FreeMegaBytes = objDisk.FreeSpace / CONVERSION_FACTOR
Wscript.Echo "Drive " & objDisk.DeviceID & " on " & strComputer & " has " & Int(FreeMegaBytes) & " megabytes of free disk space." 
Next
------------------------------------------------------------------------------------------------------------
SCRIPT 2:
----------------------------------------------------------------------------------------------------------------------
Option Explicit
const strComputer = "."
const strReport = "c:\diskspace.txt"

Dim objWMIService, objItem, colItems
Dim strDriveType, strDiskSize, txt
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk WHERE DriveType=3")
txt = "Drive" & vbtab & "Size" & vbtab & "Used" & vbtab & "Free" & vbtab & "Free(%)" & vbcrlf
For Each objItem in colItems
 
 DIM pctFreeSpace,strFreeSpace,strusedSpace
 
 pctFreeSpace = INT((objItem.FreeSpace / objItem.Size) * 1000)/10
 strDiskSize = Int(objItem.Size /1073741824) & "Gb"
 strFreeSpace = Int(objItem.FreeSpace /1073741824) & "Gb"
 strUsedSpace = Int((objItem.Size-objItem.FreeSpace)/1073741824) & "Gb"
 txt = txt & objItem.Name & vbtab & strDiskSize & vbtab & strUsedSpace & vbTab & strFreeSpace & vbtab & pctFreeSpace & vbcrlf
Next
writeTextFile txt, strReport
wscript.echo "Report written to " & strReport & vbcrlf & vbcrlf & txt
' Procedure to write output to a text file
private sub writeTextFile(byval txt,byval strTextFilePath)
 Dim objFSO,objTextFile
 
 set objFSO = createobject("Scripting.FileSystemObject")
 set objTextFile = objFSO.CreateTextFile(strTextFilePath)
 objTextFile.Write(txt)
 objTextFile.Close
 SET objTextFile = nothing
end sub
------------------------------------------------------------------------------------------------
 
Any help with this will be greatly appreciated,
C
 
#1
    CoquitoKing

    • Total Posts : 25
    • Scores: 0
    • Reward points : 0
    • Joined: 4/20/2005
    • Location: USA
    • Status: offline
    Re:Need helping add the function of one script into another Monday, December 12, 2011 9:10 AM (permalink)
    0
    I got it to work. 
     
    What do you guys think?
     
    Input = InputBox("Please enter machine name:","Machine Name")
    strComputer = Input
    const strReport = "c:\diskspace.txt"

    Dim objWMIService, objItem, colItems
    Dim strDriveType, strDiskSize, txt
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk WHERE DriveType=3")
    txt = "Drive" & vbtab & "Size" & vbtab & "Used" & vbtab & "Free" & vbtab & "Free(%)" & vbcrlf
    For Each objItem in colItems
     
     DIM pctFreeSpace,strFreeSpace,strusedSpace
     
     pctFreeSpace = INT((objItem.FreeSpace / objItem.Size) * 1000)/10
     strDiskSize = Int(objItem.Size /1073741824) & "Gb"
     strFreeSpace = Int(objItem.FreeSpace /1073741824) & "Gb"
     strUsedSpace = Int((objItem.Size-objItem.FreeSpace)/1073741824) & "Gb"
     txt = txt & objItem.Name & vbtab & strDiskSize & vbtab & strUsedSpace & vbTab & strFreeSpace & vbtab & pctFreeSpace & vbcrlf
    Next
    writeTextFile txt, strReport
    wscript.echo "Report written to " & strReport & vbcrlf & vbcrlf & txt
    ' Procedure to write output to a text file
    private sub writeTextFile(byval txt,byval strTextFilePath)
     Dim objFSO,objTextFile
     
     set objFSO = createobject("Scripting.FileSystemObject")
     set objTextFile = objFSO.CreateTextFile(strTextFilePath)
     objTextFile.Write(txt)
     objTextFile.Close
     SET objTextFile = nothing
    end sub
     
    #2
      59cobalt

      • Total Posts : 977
      • Scores: 91
      • Reward points : 0
      • Joined: 7/17/2011
      • Status: offline
      Re:Need helping add the function of one script into another Monday, December 12, 2011 9:53 AM (permalink)
      0
      Since you're writing independent lines, I'd probably drop the WriteTextFile() procedure and simply open the file before the loop, .WriteLine each record, and close the file after the loop is finished. Other than that the script looks okay to me.
       
      #3
        CoquitoKing

        • Total Posts : 25
        • Scores: 0
        • Reward points : 0
        • Joined: 4/20/2005
        • Location: USA
        • Status: offline
        Re:Need helping add the function of one script into another Monday, December 12, 2011 10:07 AM (permalink)
        0
        59cobalt


        Since you're writing independent lines, I'd probably drop the WriteTextFile() procedure and simply open the file before the loop, .WriteLine each record, and close the file after the loop is finished. Other than that the script looks okay to me.

        Hi 59,
         
        Thanks for the reply.  I ultimately want the machine name I enter in the inputbox to also be the name of the output file.  I just dont know how yet. 
         
        #4
          59cobalt

          • Total Posts : 977
          • Scores: 91
          • Reward points : 0
          • Joined: 7/17/2011
          • Status: offline
          Re:Need helping add the function of one script into another Monday, December 12, 2011 10:02 PM (permalink)
          0
          Don't make strReport a constant.
          strReport = "C:\" & Input & ".txt"
          That is unrelated to my suggestion, though.
           
          #5

            Online Bookmarks Sharing: Share/Bookmark

            Jump to:

            Current active users

            There are 0 members and 1 guests.

            Icon Legend and Permission

            • New Messages
            • No New Messages
            • Hot Topic w/ New Messages
            • Hot Topic w/o New Messages
            • Locked w/ New Messages
            • Locked w/o New Messages
            • Read Message
            • Post New Thread
            • Reply to message
            • Post New Poll
            • Submit Vote
            • Post reward post
            • Delete my own posts
            • Delete my own threads
            • Rate post

            2000-2012 ASPPlayground.NET Forum Version 3.9